每当我尝试用ffmpeg获取有关我的视频文件的一些信息时,它就会把很多无用的信息与好东西混在一起。
我正在使用ffmpeg -i name_of_the_video.mpg
。
有可能以友好的方式获得它吗?我的意思是JSON会很棒(甚至丑陋的XML也很好)。
到目前为止,我让我的应用程序使用正则表达式解析数据,但在某些特定的视频文件中出现了许多令人讨厌的角落。我修复了我遇到的所有问题,但可能还有更多。
我想要类似的东西:
{
"Stream 0": {
"type": "Video",
"codec": "h264",
"resolution": "720x480"
},
"Stream 1": {
"type": "Audio",
"bitrate": "128 kbps",
"channels": 2
}
}
答案 0 :(得分:269)
有点晚了,但可能仍与某人有关..
ffprobe
确实是一个很好的方式。不过请注意,您需要告诉ffprobe
您希望它显示哪些信息(使用-show_format
,-show_packets
和-show_streams
选项),或者它只会告诉您空白输出(就像你在其中一条评论中提到的那样)。
例如,ffprobe -v quiet -print_format json -show_format -show_streams somefile.asf
会产生如下内容:
{
"streams": [{
"index": 0,
"codec_name": "wmv3",
"codec_long_name": "Windows Media Video 9",
"codec_type": "video",
"codec_time_base": "1/1000",
"codec_tag_string": "WMV3",
"codec_tag": "0x33564d57",
"width": 320,
"height": 240,
"has_b_frames": 0,
"pix_fmt": "yuv420p",
"level": -99,
"r_frame_rate": "30000/1001",
"avg_frame_rate": "0/0",
"time_base": "1/1000",
"start_time": "0.000",
"duration": "300.066",
"tags": {
"language": "eng"
}
}],
"format": {
"filename": "somefile.asf",
"nb_streams": 1,
"format_name": "asf",
"format_long_name": "ASF format",
"start_time": "0.000",
"duration": "300.066",
"tags": {
"WMFSDKVersion": "10.00.00.3646",
"WMFSDKNeeded": "0.0.0.0000",
"IsVBR": "0"
}
}
}
答案 1 :(得分:13)
您可以尝试ffprobe
。获取JSON输出的正确命令应如下所示:
ffprobe ... -print_format json
答案 2 :(得分:8)
现在可以使用# andy @ Andy-surface in /mnt/c/Users/Karma/ws/sandbox [11:47:46] C:2
$ python c:/Users/Karma/ws/sandbox/flask.py
python: can't open file 'c:/Users/Karma/ws/sandbox/flask.py': [Errno 2] No such file or directory
打印由-progress -
格式化的友好信息。
key=value
答案 3 :(得分:2)
ffprobe
的另一种用法,可以很好地解析:
ffprobe -v error -select_streams v:0 -show_entries stream=width,height,r_frame_rate,bit_rate,codec_name,duration -of csv=p=0:s=x video.mp4
导致:
h264x600x480x25/1x385.680000x542326
-select_streams v:0
仅选择视频流。如果删除该参数,则每个流只有一行。