简体   繁体   中英

Writing video in mp4 format with opencv python

i can save the video in .avi format.but i am unable to write the video in mp4 format. im using opencv3

 fourcc = cv2.VideoWriter_fourcc(*'XVID')  
 out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

above portion of code saves the video in .avi format.

for making mp4 videos you can

VideoWriter_fourcc(*'MP4V')

you can see all fourcc codecs in https://www.fourcc.org/codecs.php

fourcc = cv2.VideoWriter_fourcc(*'mp4v')

and I don't get any errors.

if using fourcc = cv2.VideoWriter_fourcc(*'MPV4'), I get

OpenCV: FFMPEG: fallback to use tag 0x7634706d/'mp4v'

Follow this link :

you should replace:

 fourcc = cv2.VideoWriter_fourcc(*'XVID') 

by:

 fourcc = cv2.VideoWriter_fourcc(*'FMP4')

I tried and succeeded.

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