使用ffprobe提取视频元数据 ffprobe -v quiet -print_format json -show_format -show_streams filename.mp4

从ffprobe工具提取的元数据中得到:

filesize: 28102957 B = (27444.29  * 1024) KB = (26.8 * 1024 * 1024) MB
duration: 544.2 秒
bitrate: 413126 bits/s

视频流:

r_frame_rate = 24000/1001 ≈ 23.97 fps
nb_frames = 13040 帧
duration = 543.876667
bit_rate = 280350 bits/s

音频流:

duration = 544.200000 bit_rate = 128000 bits/s

因为:1 B = 8 bits,所以有: $$ bitrate = \frac {filesize * 8 bits} {duration} \approx 413126.89 bits/s $$

另有帧率: $$ framerate = \frac {nbofframes}{duration} = \frac{13040}{543.87667} \approx 23.97 fps $$

使用ffmpeg copy媒体流重新封装,保持原属性,得到更精确的信息 fmpeg -i filename.mp4 -c:a copy -c:v copy -y temp.mp4

命令输出的信息有:

视频流:

duration: 00:09:04.20 = 544.2 秒
bitrate = 413 kb/s 
SAR: 32:27
DAR: 16:9
video_bitrate = 280 kb/s 
framerate = 23.98 fps  与ffprobe 获取的一致

音频流: audio_bitrate = 128 kb/s

封装文件:

frame = 13040 帧

duration = 544.2 秒
bitrate = 413.1 kbits/s

fileSize = 27444 kB
videoSize = 18613 kB
audioSize = 8503 kB
muxing overhead = 1.210994%

结论

  1. 文件尺寸 muxing overhead 是封装格式占用的开销 即:

$$ overhead = \frac{(fileSize - videoSize - audioSize)} {fileSize} = \frac{27444-18613-8503}{27444} \approx 1.19% $$

  1. 音视频比特率 若 ffprobe 没获取到videoBitrate和audioBitrate 可根据转封装时得到的:videoSize 和audioSize 进行计算 需要注意的时:码率既称之为比特率,所以在计算时,要把常用的字节Byte * 8 换算为bits. 而我们通常在讨论文件大小、网络带宽时,都时以字节为单位的: 如文件大小: (1MB = 1024 KB = 1024 * 1024 Byte = 8 * 1024*1024 bits) 网络带宽: ( 2MB/s = 2048 KB/s)

另外,还需要注意的是,以字节为单位时,习惯上每1024进位,即(1KB = 1024Byte) 而在讲比特率/码率时,习惯上以1000进位,即(1mb = 1000kb = 10^6bits)

视频比特率和音频比特率的计算公式如下 $$ videoBitRate = \frac{videoSize * 1024 * 8}{duration} = \frac{ 18613 * 1024 * 8 bits}{544.2s} \approx 280186.87 bits/s $$

$$ audioBitRate = \frac{audioSize * 1024 * 8}{duration} = \frac{8503 * 1024 * 8 bits}{544.2s} \approx 127998.1 bits/s $$

$$ totalBitRate = \frac{fileSize * 1024 * 8}{duration} = \frac{27444 * 1024 * 8}{544.2} \approx 413122.46 bits/s $$

  • ffprobe 获取的总比特率:bitrate: 413126 bits/s,在转封装输出时,按1k = 1000来转为了413.1 kb/s
  • ffprobe 获取的视频比特率:280350 bits/s,在转封装输出时,转为了280 kb/s
  • ffprobe 获取的音频比特率:128000 bits/s,转封装输出为:128 kb/s

  1. ffprobe返回结果
{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "High",
            "codec_type": "video",
            "codec_time_base": "1001/48000",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 480,
            "height": 320,
            "coded_width": 480,
            "coded_height": 320,
            "has_b_frames": 2,
            "sample_aspect_ratio": "32:27",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 21,
            "chroma_location": "left",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "r_frame_rate": "24000/1001",
            "avg_frame_rate": "24000/1001",
            "time_base": "1/24000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 13053040,
            "duration": "543.876667",
            "bit_rate": "280350",
            "bits_per_raw_sample": "8",
            "nb_frames": "13040",
            "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
            },
            "tags": {
                "language": "und",
                "handler_name": "VideoHandler"
            }
        },
        {
            "index": 1,
            "codec_name": "mp3",
            "codec_long_name": "MP3 (MPEG audio layer 3)",
            "codec_type": "audio",
            "codec_time_base": "1/48000",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "s16p",
            "sample_rate": "48000",
            "channels": 2,
            "channel_layout": "stereo",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 26121600,
            "duration": "544.200000",
            "bit_rate": "128000",
            "nb_frames": "22675",
            "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
            },
            "tags": {
                "language": "und",
                "handler_name": "SoundHandler"
            }
        }
    ],
    "format": {
        "filename": "875b31ee4b17cfd85e0f04c931cf0999.mp4",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "544.200000",
        "size": "28102957",
        "bit_rate": "413126",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "encoder": "Lavf56.40.101"
        }
    }
}
  1. ffmpeg copy封装控制台输出
ffmpeg version 3.1.4 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  libpostproc    54.  0.100 / 54.  0.100
  // 以上是ffmpeg 版本信息
 

输入流信息

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '875b31ee4b17cfd85e0f04c931cf0999.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.40.101
  Duration: 00:09:04.20, start: 0.000000, bitrate: 413 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x320 [SAR 32:27 DAR 16:9], 280 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, s16p, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
      
[mp4 @ 0000000002545100] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
    Last message repeated 1 times

输出流信息

Output #0, mp4, to 'test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.41.100
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 480x320 [SAR 32:27 DAR 16:9], q=2-31, 280 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 24k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: mp3 (i[0][0][0] / 0x0069), 48000 Hz, stereo, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=13040 fps=0.0 q=-1.0 Lsize=   27444kB time=00:09:04.20 bitrate= 413.1kbits/s speed=1.9e+003x
video:18613kB audio:8503kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.210994%