参考python + opencv 将图片保存为视频–2016年更新,
code example 为:
def imgs2video(imgs_dir, save_name):
fps = 24
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
video_writer = cv2.VideoWriter(save_name, fourcc, fps, (1920, 1080))
# no glob, need number-index increasing
imgs = glob.glob(os.path.join(imgs_dir, '*.png'))
for i in range(len(imgs)):
imgname = os.path.join(imgs_dir, 'core-{:02d}.png'.format(i))
frame = cv2.imread(imgname)
video_writer.write(frame)
video_writer.release()
参考python opencv VideoWriter: OpenCV: Frame size does not match video size,
"mMovieWriter.status: 3. Error: Cannot Save"
是由于已经有了同名文件,无法覆盖,删掉再转换就可以了。
OpenCV: Frame size does not match video size.
WARNING: -finishWriting should not be called on the main thread.