Python:检测视频容器中使用的编解码器
我有几个视频容器文件,其中包含各种编解码器中的音频和视频。现在我想从 Python 脚本检查容器,以了解音频+视频使用哪个编解码器。这是在 Linux 机器上,所以如果需要的话我有所有可用的工具。
我想也许 gstreamer 可以在这里帮助我,但我无法找到可以在这里帮助我的 API。
有什么想法吗?我也愿意接受任何建议,只要它是免费软件就不需要是 gstreamer :-) FS
I have a couple of video container files which contain audio and video in various codecs. Now I'd like to inspect the container from a Python script to know which codec is used for audio+video. This is on a linux box so I have all the tools available if necessary.
I thought that maybe gstreamer could help me here but I was unable to find an API which could help me here.
Any ideas? I'm also open for any suggestion, doesn't need to be gstreamer as long as it is free software :-)
fs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需使用 subprocess.check_output 调用它,您就会获得媒体文件的漂亮 JSON 描述。如果您需要它从标准输入获取数据,请将 YOUR_FILE 替换为 pipeline:0。
ffprobe 与 ffmpeg 一起提供。
Just invoke this with subprocess.check_output and you'll get a beautiful JSON description of your media file. If you need it to grab the data from stdin, replace YOUR_FILE with pipe:0.
ffprobe comes with ffmpeg.
尝试下载 ffmpeg 源代码并查看其命令行程序的源代码。我过去曾破解过类似的实用程序。我不会发布我的解决方案,因为 ffmpeg 喜欢更改其 API,因此我的旧代码不太可能与当前版本一起编译。您需要做足够的工作来创建编解码器上下文,您可以检查它以获得您需要的内容。
其他一些替代方案:
MediaInfo:http://mediainfo.sourceforge.net/en
GSpot(仅限 Windows ): http://www.headbands.com/gspot/
编辑:
http://code.google.com/p/pyffmpeg/ 可能有你想要的(我没有我自己用过它)。
Try downloading the ffmpeg source and look at the source for their command line programs. I've hacked up similar utilities in the past. I'm not posting my solution because ffmpeg likes to change their API, so my old code is unlikely to compile with the current version. You'll want to do enough work to create codec context, which you can inspect to get what you need.
Some other alternatives:
MediaInfo: http://mediainfo.sourceforge.net/en
GSpot (Windows only): http://www.headbands.com/gspot/
EDIT:
http://code.google.com/p/pyffmpeg/ might have what you want (I haven't used it myself).
您可以在Gstreamer中使用decodebin2。查看 TAE 获取代码示例。
You can use decodebin2 in Gstreamer. Take a look at TAE for code examples.