json 以友好的方式获取ffmpeg信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7708373/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:01:00  来源:igfitidea点击:

Get ffmpeg information in friendly way

jsonparsingffmpeg

提问by JBernardo

Every time I try to get some information about my video files with ffmpeg, it pukes a lot of useless information mixed with good things.

每次我尝试使用 ffmpeg 获取有关我的视频文件的一些信息时,它都会吐出很多无用的信息和好的东西。

I'm using ffmpeg -i name_of_the_video.mpg.

我正在使用ffmpeg -i name_of_the_video.mpg.

There are any possibilities to get that in a friendly way? I mean JSON would be great (and even ugly XML is fine).

有没有可能以友好的方式获得它?我的意思是 JSON 会很棒(甚至丑陋的 XML 也可以)。

By now, I made my application parse the data with regex but there are lots of nasty corners that appear on some specific video files. I fixed all that I encountered, but there may be more.

到现在为止,我让我的应用程序使用正则表达式解析数据,但是在某些特定的视频文件上出现了很多令人讨厌的角落。我修复了我遇到的所有问题,但可能还有更多。

I wanted something like:

我想要这样的东西:

{
  "Stream 0": {
     "type": "Video",
     "codec": "h264",
     "resolution": "720x480"
  },
  "Stream 1": {
     "type": "Audio",
     "bitrate": "128 kbps",
     "channels": 2
  }
}

回答by Irexistus

A bit late, but perhaps still relevant to someone..

有点晚了,但也许仍然与某人有关..

ffprobeis indeed an excellent way to go. Note, though, that you need to tell ffprobewhat information you want it to display (with the -show_format, -show_packetsand -show_streamsoptions) or it'll just give you blank output (like you mention in one of your comments).

ffprobe确实是一个很好的方法。但是请注意,您需要告诉ffprobe您希望它显示哪些信息(使用-show_format,-show_packets-show_streams选项),否则它只会给您空白输出(就像您在评论中提到的那样)。

For example, ffprobe -v quiet -print_format json -show_format -show_streams somefile.asfwould yield something like the following:

例如,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"
    }
  }
}

回答by NT3RP

You could try ffprobe. The correct command to get JSON output should look like the following:

你可以试试ffprobe。获取 JSON 输出的正确命令应如下所示:

ffprobe ... -print_format json

回答by Oleksandr Kyrpa

Now is possible to use -progress -to print friendly info formatted by key=value.

现在可以用于-progress -打印由key=value.

ffmpeg  -i video.mp4 .......-s 1920x1080 -progress - -y out.mp4

speed=5.75x
frame=697
fps=167.7
stream_0_0_q=39.0
bitrate=2337.0kbits/s
total_size=6979778
out_time_ms=23893333
out_time=00:00:23.893333
dup_frames=0
drop_frames=0

回答by yglodt

Another usage of ffprobewhich is nicely parseable:

它的另一种用法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

results in:

结果是:

h264x600x480x25/1x385.680000x542326

h264x600x480x25/1x385.680000x542326

-select_streams v:0selects only the video stream. If you remove that parameter you get one line for each stream.

-select_streams v:0仅选择视频流。如果删除该参数,则每个流都会得到一行。