简体   繁体   中英

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. How to get mp4 file instead of avi file

# 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') .


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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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