What is codec for mp4 video in python opencv

fourcc = cv2.cv.CV_FOURCC(*'XVID') 

The above line is used for AVI video. In the same way, which codec do we use for mp4 video in Ubuntu?

+10
source share
3 answers

H.264 codec.

One of them should work for you:

 fourcc = cv2.cv.CV_FOURCC(*'H264') #or #fourcc = cv2.cv.CV_FOURCC(*'X264') 

However, I should warn you that you will probably need to install the ffmpeg and x264 ffmpeg , so since you are in Ubuntu, try the following command in the terminal :

 sudo apt-get install ffmpeg x264 libx264-dev 

Also check out this link from the OpenCV tutorials for more information on the types of FourCC codes available for your platform.

The link above says that X264 is the FourCC code you should use, but switch between them until it works.

+9
source

You can also use mp4v

 fourcc = cv2.cv.CV_FOURCC(*'mp4v') 

where the video memory should look like this:

 out = cv2.VideoWriter('output.mp4',fourcc, 15, size) 

But for mp4 more codecs are available. You can see their list by setting fourcc = -1 , it will show a list like this:

 OpenCV: FFMPEG: format mp4 / MP4 (MPEG-4 Part 14) fourcc tag 0x7634706d/'mp4v' codec_id 000C fourcc tag 0x31637661/'avc1' codec_id 001B fourcc tag 0x33637661/'avc3' codec_id 001B fourcc tag 0x31766568/'hev1' codec_id 00AD fourcc tag 0x31637668/'hvc1' codec_id 00AD fourcc tag 0x7634706d/'mp4v' codec_id 0002 fourcc tag 0x7634706d/'mp4v' codec_id 0001 fourcc tag 0x7634706d/'mp4v' codec_id 0007 fourcc tag 0x7634706d/'mp4v' codec_id 003D .... 

They all support mp4, but h264 supported by web browsers if you want to post videos on the Internet.

+2
source

This is an old question. But if someone is facing a problem recently, using a codec that cannot receive the saved video. They can use 0X00000021 as the codec value for OpenCV 3 and later.

+1
source

Source: https://habr.com/ru/post/986746/


All Articles