FFmpeg命令行工具学习(一):查看媒体文件头信息工具ffprobe

目录

FFmpeg命令行工具学习(一):查看媒体文件头信息工具ffprobe
FFmpeg命令行工具学习(二):播放媒体文件的工具ffplay
FFmpeg命令行工具学习(三):媒体文件转换工具ffmpeg

 

 

 

 

一、简述

ffprobe是ffmpeg命令行工具中相对简单的,此命令是用来查看媒体文件格式的工具。

二、命令格式

在命令行中输入如下格式的命令:

ffprobe [文件名] 

三、使用ffprobe查看mp3格式的文件

本文使用的是歌曲《社会摇》,执行的命令为:

ffprobe shy.mp3 

输出内容为:

Input #0, mp3, from 'shy.mp3':
  Metadata:
    genre           : Blues
    encoder         : Lavf56.4.101
    comment         : 163 key(Don't modify):L64FU3W4YxX3ZFTmbZ+8/UO6KmVXLfTij3uZN/wCXE4a00XHtvOwccwFlS+8ednRD4MnrdUH+aUYZFVY8bObsrabtBM2Ps/UAWPJtsmW/3RXnn6eJcNUHrPALM0003fIpQnn6MOWbdXqog6WFDLpaZJhoPMnFy9u41HxCalUwMEc+mkHNn+nSLlioJfpv4wPBwUhxfLNmOScmXPzOary2k37A/brRx7QUlMD9rkaZ
    album           : 社会摇
    title           : 社会摇
    artist          : 萧全
    track           : 1
  Duration: 00:04:09.34, start: 0.025056, bitrate: 323 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 320 kb/s
    Stream #0:1: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 500x500 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc
    Metadata:
      comment         : Media (e.g. label side of CD)

首先我们看以下这行信息:

Duration: 00:04:09.34, start: 0.025056, bitrate: 323 kb/s

这行信息表示,该视频文件的时长是4分9秒340毫秒,开始播放时间是0.025056,整个文件的比特率是256Kbit/s,然后我们看下一行信息:

Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 320 kb/s

这行信息表示,第一个流是音频流,编码格式是MP3格式,采样率是44.1KHz,声道是立体声,采样表示格式是SInt16(short)的planner(平铺格式),这路流的比特率320Kbit/s。

四、使用ffprobe查看mp4格式的文件

本文使用的是视频《泡沫》,执行的命令为:

ffprobe pm.mp4 

输出内容为:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pm.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2016-12-17T16:02:05.000000Z
    album           : Yinyuetai
    artist          : yinyuetai.com
    comment         : Yinyuetai-1TR1151
    date            : 12/18/16 00:02:05
  Duration: 00:04:33.51, start: 0.000000, bitrate: 1104 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 960x540, 1008 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2016-12-17T16:02:05.000000Z
      handler_name    : 264@GPAC0.5.1-DEV-rev5472
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 92 kb/s (default)
    Metadata:
      creation_time   : 2016-12-17T15:50:54.000000Z
      handler_name    : Sound Media Handler

首先我们看以下这行信息:

Duration: 00:04:33.51, start: 0.000000, bitrate: 1104 kb/s

这行信息表示,该视频文件的时长是4分33秒510毫秒,开始播放时间是0,整个文件的比特率是1104Kbit/s,然后我们看下一行信息:

Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 960x540, 1008 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)

这行信息表示,第一个流是视频流,编码格式是H264格式(封装格式为AVC1),每一帧的数据表示为yuv420p,分辨率为960x540,这路流的比特率为1108Kbit/s,帧率为每秒钟25帧。

接下来我们看下一行:

Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 92 kb/s (default)

这行信息表示第二个流是音频流,编码方式为ACC(封装格式为MP4A),并且采用的Profile是LC规格,采样率是44.1KHz,声道是立体声,这路流的比特率92Kbit/s。

到此为止,我们就掌握了使用ffprobe提取媒体的头文件信息的方式,并了解了提取出来的信息的含义

五、ffprobe高级使用方式

1. 输出格式信息

appledeMacBook-Pro:Desktop renhui$ ffprobe -show_format  pm.mp4 
ffprobe version 3.4.2 Copyright (c) 2007-2018 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --disable-jack --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pm.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2016-12-17T16:02:05.000000Z
    album           : Yinyuetai
    artist          : yinyuetai.com
    comment         : Yinyuetai-1TR1151
    date            : 12/18/16 00:02:05
  Duration: 00:04:33.51, start: 0.000000, bitrate: 1104 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 960x540, 1008 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2016-12-17T16:02:05.000000Z
      handler_name    : 264@GPAC0.5.1-DEV-rev5472
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 92 kb/s (default)
    Metadata:
      creation_time   : 2016-12-17T15:50:54.000000Z
      handler_name    : Sound Media Handler
[FORMAT]
filename=pm.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=273.506667
size=37776599
bit_rate=1104955
probe_score=100
TAG:major_brand=isom
TAG:minor_version=1
TAG:compatible_brands=isomavc1
TAG:creation_time=2016-12-17T16:02:05.000000Z
TAG:album=Yinyuetai
TAG:artist=yinyuetai.com
TAG:comment=Yinyuetai-1TR1151
TAG:date=12/18/16 00:02:05
[/FORMAT]
View Code

2. 输出每个流的具体信息(以JSON格式)

appledeMacBook-Pro:Desktop renhui$ ffprobe -print_format json  -show_streams pm.mp4 
ffprobe version 3.4.2 Copyright (c) 2007-2018 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --disable-jack --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
{
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pm.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2016-12-17T16:02:05.000000Z
    album           : Yinyuetai
    artist          : yinyuetai.com
    comment         : Yinyuetai-1TR1151
    date            : 12/18/16 00:02:05
  Duration: 00:04:33.51, start: 0.000000, bitrate: 1104 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 960x540, 1008 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2016-12-17T16:02:05.000000Z
      handler_name    : 264@GPAC0.5.1-DEV-rev5472
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 92 kb/s (default)
    Metadata:
      creation_time   : 2016-12-17T15:50:54.000000Z
      handler_name    : Sound Media Handler
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "Main",
            "codec_type": "video",
            "codec_time_base": "1/50",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 960,
            "height": 540,
            "coded_width": 960,
            "coded_height": 540,
            "has_b_frames": 2,
            "sample_aspect_ratio": "0:1",
            "display_aspect_ratio": "0:1",
            "pix_fmt": "yuv420p",
            "level": 31,
            "chroma_location": "left",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "r_frame_rate": "25/1",
            "avg_frame_rate": "25/1",
            "time_base": "1/25000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 6835000,
            "duration": "273.400000",
            "bit_rate": "1008649",
            "bits_per_raw_sample": "8",
            "nb_frames": "6835",
            "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
            },
            "tags": {
                "creation_time": "2016-12-17T16:02:05.000000Z",
                "language": "und",
                "handler_name": "[email protected]"
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "LC",
            "codec_type": "audio",
            "codec_time_base": "1/44100",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "44100",
            "channels": 2,
            "channel_layout": "stereo",
            "bits_per_sample": 0,
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/44100",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 12061696,
            "duration": "273.507846",
            "bit_rate": "92649",
            "max_bit_rate": "136240",
            "nb_frames": "11779",
            "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
            },
            "tags": {
                "creation_time": "2016-12-17T15:50:54.000000Z",
                "language": "und",
                "handler_name": "Sound Media Handler"
            }
        }
    ]
}
View Code

3. 显示帧信息

ffprobe -show_frames pm.mp4

4. 查看包信息

ffprobe -show_packets pm.mp4

你可能感兴趣的:(FFmpeg命令行工具学习(一):查看媒体文件头信息工具ffprobe)