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

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

Jitendarpal Singn
1#
Jitendarpal Singn Published in 2018-01-12 06:25:05Z
 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() 
Silencer
2#
 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?
 You need to login account before you can post.
Processed in 0.310763 second(s) , Gzip On .