python 无法使用 videoWriter 模块中的 opencv 保存视频
Unable to save the video using opencv in videoWriter module in python
下面是代码片段。
fourcc = cv2.VideoWriter_fourcc(*)
out = cv2.VideoWriter('/Users\Dell\Documents\GitHub\capstoneproject\ProjectS\sample\example_03.mp4',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
上面的视频无法保存。
我想你忘了提供编解码器的类型。正确的代码应该是。
fourcc = cv2.VideoWriter_fourcc(*'type of codec')
编解码器类型可以是 mp4、XVID 等
下面是代码片段。
fourcc = cv2.VideoWriter_fourcc(*)
out = cv2.VideoWriter('/Users\Dell\Documents\GitHub\capstoneproject\ProjectS\sample\example_03.mp4',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
上面的视频无法保存。
我想你忘了提供编解码器的类型。正确的代码应该是。
fourcc = cv2.VideoWriter_fourcc(*'type of codec')
编解码器类型可以是 mp4、XVID 等