本文介绍了以友好的方式获取ffmpeg信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 name_of_the_video.mpg

有什么可能以友好的方式得到这个?我的意思是JSON将是伟大的(甚至丑陋的XML是好的)。

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

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

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.

我想要的东西如下:

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


推荐答案

p>有点迟了,但也许与某人有关。

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

ffprobe 确实是一个很好的方式。请注意,您需要告诉 ffprobe 您希望显示哪些信息(使用 -show_format -show_packets -show_streams 选项),或者只是给你空白的输出(像你在你的一个评论中提到的) )

ffprobe is indeed an excellent way to go. Note, though, that you need to tell ffprobe what information you want it to display (with the -show_format, -show_packets and -show_streams options) or it'll just give you blank output (like you mention in one of your comments).

例如, ffprobe -v quiet -print_format json -show_format -show_streams somefile.asf 会产生一些东西如下:

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

{
  "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"
    }
  }
}

这篇关于以友好的方式获取ffmpeg信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 18:05