0

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()
Kinght 金
  • 17,681
  • 4
  • 60
  • 74

1 Answers1

0

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?

Community
  • 1
  • 1
Kinght 金
  • 17,681
  • 4
  • 60
  • 74