无法写入视频文件。视频文件未创建

时间:2018-12-30 15:41:07

标签: python python-3.x opencv

我只是试图从文件中读取帧,然后使用python中的opencv 3.4.5将其重写为新文件。但是它无法创建视频文件。

import cv2
vidcap = cv2.VideoCapture('movie.mov')
success,image = vidcap.read()
height, width, channels = image.shape
print(channels)
video=cv2.VideoWriter('video.avi',-1,1,(width,height))
count = 0
images = []
while success:
    images.append(image)
    success,image = vidcap.read()
    print('Read a new frame: ', success)
    count += 1
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
print(count,len(images))
for i in images:
    video.write(i)
cv2.destroyAllWindows()
video.release()

1 个答案:

答案 0 :(得分:0)

问题在于您声明writer的方式。

fps = int(cap.get(cv2.CAP_PROP_FPS))
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
fourcc = int(cv2.VideoWriter_fourcc('X','V','I','D')) # XVID codecs

writer = cv2.VideoWriter("new.avi", fourcc, fps, size)