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.

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

到现在为止,我让我的应用程序用regex解析数据,但在一些特定的视频文件中出现了许多令人讨厌的角落.我修复了所有遇到的问题,但可能还有更多问题.

I wanted something like:

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

推荐答案

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

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将产生类似以下内容的结果:

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

Json相关问答推荐

使用JQ将对象数组转换为平面数组

将PNG图像保存为Python中的JSON文件

JOLT转换以根据条件删除json对象

在 json 对象中存储多个键:值对

VSCode 为 python 文件添加标尺,但不为 C 文件添加标尺.为什么?

将 JSON 字符串解析为 Kotlin Android 中的对象列表(MOSHI?)

Shell脚本空格转义

golang递归json来构造?

修改 boost::json::object 中的值

JOLT 转换 - 删除 JSON 数组中的空 node

使用 jq Select 键:值并输出为数组

将哈希表转换为 json 后,Powershell 缺少数组

在 Perl Mojolicious 中呈现 JSON 时防止转义字符

如何在 Django 的模板语言中获取 json 键和值?

验证和格式化 JSON 文件

JSON.NET JsonConvert 与 .NET JavaScriptSerializer

在 Django 1.9 中,使用 JSONField(本机 postgres jsonb)的约定是什么?

错误未判断调用put(K, V)作为原始类型java.util.HashMap的成员

使用 Node.js 对 JSON 中的字符串大小有限制吗?

如何将有向无环图 (DAG) 存储为 JSON?