python OpenCV中mp4视频的编解码器是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30103077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is the codec for mp4 videos in python OpenCV
提问by Suhail Ahmed Khan
fourcc = cv2.cv.CV_FOURCC(*'XVID')
The above line is used for avi video. In the same fashion, which codec do we use for mp4 videos in Ubuntu?
上面的行用于 avi 视频。以同样的方式,我们在 Ubuntu 中为 mp4 视频使用哪种编解码器?
回答by rayryeng
The codec is H.264.
编解码器是 H.264。
One of these should work for you:
其中之一应该适合您:
fourcc = cv2.cv.CV_FOURCC(*'H264')
#or
#fourcc = cv2.cv.CV_FOURCC(*'X264')
However, I should warn you that you'll probably need to have ffmpeg
and the x264
libraries installed so since you are in Ubuntu, try doing this command in the terminal:
但是,我应该警告您,您可能需要安装ffmpeg
这些x264
库,因为您使用的是 Ubuntu,请尝试在终端中执行以下命令:
sudo apt-get install ffmpeg x264 libx264-dev
Also, check out this linkfrom OpenCV tutorials for more details as to the kinds of FourCC codes available for your platform.
此外,请查看OpenCV 教程中的此链接,了解有关可用于您的平台的 FourCC 代码类型的更多详细信息。
In the above link, it says X264
is the FourCC code you should use, but switch between them until you get it to work.
在上面的链接中,它说的X264
是您应该使用的 FourCC 代码,但在它们之间切换,直到您让它工作为止。
回答by Ibrahim Yousuf
This is an old question. But, if anyone is facing an issue lately using the codec who can't get a saved video. They can use 0X00000021
as the codec value for OpenCV 3 and later.
这是一个老问题。但是,如果有人最近在使用无法获取已保存视频的编解码器时遇到问题。它们可以0X00000021
用作 OpenCV 3 及更高版本的编解码器值。
回答by Gonzalo Garcia
You can also use mp4v
你也可以使用 mp4v
fourcc = cv2.cv.CV_FOURCC(*'mp4v')
where the videowriter should look like this:
视频作者应该是这样的:
out = cv2.VideoWriter('output.mp4',fourcc, 15, size)
But there are more codecs available for mp4. You can see the list of them by setting fourcc = -1
, it will show a list like this:
但是还有更多可用于 mp4 的编解码器。您可以通过设置查看它们的列表fourcc = -1
,它将显示如下列表:
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
....
All of them supports mp4 but h264
is supported by Web browsers if you want to serve the video into the web.
它们都支持 mp4,但h264
如果您想将视频提供到网络中,则 Web 浏览器支持。
回答by PeterB
fourcc = cv2.VideoWriter_fourcc('m','p','4','v')
Always seems to work.
似乎总是有效。