如何使用 FFprobe 从视频文件中获取音频比特率?

如何使用 FFprobe 从视频文件中获取音频比特率?

我有一个视频,我想获取视频的时长和音频比特率。

使用这个脚本(将视频路径作为第一个参数),我可以获取持续时间并将其分配给一个变量。

videoSeconds=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$1")

但是我不确定如何将音频比特率分配给变量(我查看了手册页但没有找到)。

当我ffprobe不使用任何选项运行时,我可以看到音频比特率作为更广泛信息的一部分。

Side data:
  displaymatrix: rotation of -90.00 degrees
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 96 kb/s (default)
Metadata:

有什么想法吗?

答案1

尝试使用此命令,关键是使用-select_streams a:0 -show_entries stream=bit_rate

audioBitrate=$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "$1")

答案2

您可以直接从 ffprobe 中使用以下方法获取它:

ffprobe -v 0 -select_streams a:0 -show_entries stream=bit_rate -of compact=p=0:nk=1 "$1"

答案3

接受的答案对我来说不起作用。

在带有 opus 编解码器音频流的视频上,流=比特率对我没用。 流=采样率工作了。

在我正在探测的文件上运行:

ffprobe -v 0 -select_streams a:0 -show_entries stream=bit_rate -of compact=p=0:nk=1 1.webm

返回:

{
"streams": [
    {
        "index": 0,
        "codec_name": "vp9",
        "codec_long_name": "Google VP9",
        "profile": "Profile 0",
        "codec_type": "video",
        "codec_tag_string": "[0][0][0][0]",
        "codec_tag": "0x0000",
        "width": 480,
        "height": 360,
        "coded_width": 480,
        "coded_height": 360,
        "closed_captions": 0,
        "film_grain": 0,
        "has_b_frames": 0,
        "sample_aspect_ratio": "1:1",
        "display_aspect_ratio": "4:3",
        "pix_fmt": "yuv420p",
        "level": -99,
        "color_range": "tv",
        "refs": 1,
        "r_frame_rate": "25/1",
        "avg_frame_rate": "25/1",
        "time_base": "1/1000",
        "start_pts": 0,
        "start_time": "0.000000",
        "disposition": {
            "default": 1,
            "dub": 0,
            "original": 0,
            "comment": 0,
            "lyrics": 0,
            "karaoke": 0,
            "forced": 0,
            "hearing_impaired": 0,
            "visual_impaired": 0,
            "clean_effects": 0,
            "attached_pic": 0,
            "timed_thumbnails": 0,
            "captions": 0,
            "descriptions": 0,
            "metadata": 0,
            "dependent": 0,
            "still_image": 0
        },
        "tags": {
            "language": "eng",
            "DURATION": "00:42:12.480000000"
        }
    },
    {
        "index": 1,
        "codec_name": "opus",
        "codec_long_name": "Opus (Opus Interactive Audio Codec)",
        "codec_type": "audio",
        "codec_tag_string": "[0][0][0][0]",
        "codec_tag": "0x0000",
        "sample_fmt": "fltp",
        "sample_rate": "48000",
        "channels": 2,
        "channel_layout": "stereo",
        "bits_per_sample": 0,
        "initial_padding": 312,
        "r_frame_rate": "0/0",
        "avg_frame_rate": "0/0",
        "time_base": "1/1000",
        "start_pts": 0,
        "start_time": "0.000000",
        "extradata_size": 19,
        "disposition": {
            "default": 1,
            "dub": 0,
            "original": 0,
            "comment": 0,
            "lyrics": 0,
            "karaoke": 0,
            "forced": 0,
            "hearing_impaired": 0,
            "visual_impaired": 0,
            "clean_effects": 0,
            "attached_pic": 0,
            "timed_thumbnails": 0,
            "captions": 0,
            "descriptions": 0,
            "metadata": 0,
            "dependent": 0,
            "still_image": 0
        },
        "tags": {
            "language": "eng",
            "DURATION": "00:42:12.528000000"
        }
    }
],
"format": {
    "filename": "1.webm",
    "nb_streams": 2,
    "nb_programs": 0,
    "format_name": "matroska,webm",
    "format_long_name": "Matroska / WebM",
    "start_time": "0.000000",
    "duration": "2532.528000",
    "size": "127666051",
    "bit_rate": "403284",
    "probe_score": 100,
    "tags": {
        "ENCODER": "Lavf60.10.100"
    }
}

}

音频没有预设“bit_rate”,而是预设“sample_rate”。

相关内容