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

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#
Silencer Reply to 2018-01-12 07:37:23Z

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.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310763 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO