简体   繁体   English

如何使用Python OpenCV从多个帧生成mp4(而非avi)文件?

[英]How to generate a mp4(not a avi) file from a number of frames using Python OpenCV?

I am unable to generate a mp4 file from a number of frames, although I can generate avi file. 尽管可以生成avi文件,但无法从多个帧生成mp4文件。 How to get mp4 file instead of avi file 如何获取mp4文件而不是avi文件

# Define the codec and create VideoWriter object.The output is stored in 'outpy.avi' file.
import cv2
out = cv2.VideoWriter('outpy.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 10, (frame_width,frame_height))
out.write(frame) 
out.release()

Try to use cv2.VideoWriter_fourcc(*'mpeg') or cv2.VideoWriter_fourcc(*'mp4v') . 尝试使用cv2.VideoWriter_fourcc(*'mpeg')cv2.VideoWriter_fourcc(*'mp4v')


Here is an example: 这是一个例子:

sz = (640, 480)
fps = 20
#fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
#fourcc = cv2.VideoWriter_fourcc('m', 'p', 'e', 'g')
fourcc = cv2.VideoWriter_fourcc(*'mpeg')

## open and set props
vout = cv2.VideoWriter()
vout.open('output.mp4',fourcc,fps,sz,True)

Full description at this answer: How can I write a series of images into a video using opencv? 关于此答案的完整描述: 如何使用opencv将一系列图像写入视频?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM