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

一、简述

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

二、命令格式

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

ffprobe [文件名] 

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

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

ffprobe shy.mp3 

输出内容为:

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

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

Duration: ::09.34, start: 0.025056, bitrate:  kb/s

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

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

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

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

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

ffprobe pm.mp4 

输出内容为:

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

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

Duration: ::33.51, start: 0.000000, bitrate:  kb/s

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

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

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

接下来我们看下一行:

Stream #:(und): Audio: aac (LC) (mp4a / 0x6134706D),  Hz, stereo, fltp,  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. Copyright (c) - the FFmpeg developers
built with Apple LLVM version 9.0. (clang-900.0.39.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4. --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 . 78.100 / . 78.100
libavcodec 57.107. / 57.107.
libavformat . 83.100 / . 83.100
libavdevice . 10.100 / . 10.100
libavfilter 6.107. / 6.107.
libavresample . . / . .
libswscale . 8.100 / . 8.100
libswresample . 9.100 / . 9.100
libpostproc . 7.100 / . 7.100
Input #, mov,mp4,m4a,3gp,3g2,mj2, from 'pm.mp4':
Metadata:
major_brand : isom
minor_version :
compatible_brands: isomavc1
creation_time : --17T16::.000000Z
album : Yinyuetai
artist : yinyuetai.com
comment : Yinyuetai-1TR1151
date : // ::
Duration: ::33.51, start: 0.000000, bitrate: kb/s
Stream #:(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 960x540, kb/s, fps, tbr, 25k tbn, tbc (default)
Metadata:
creation_time : --17T16::.000000Z
handler_name : @GPAC0.5.1-DEV-rev5472
Stream #:(und): Audio: aac (LC) (mp4a / 0x6134706D), Hz, stereo, fltp, kb/s (default)
Metadata:
creation_time : --17T15::.000000Z
handler_name : Sound Media Handler
[FORMAT]
filename=pm.mp4
nb_streams=
nb_programs=
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.000000
duration=273.506667
size=
bit_rate=
probe_score=
TAG:major_brand=isom
TAG:minor_version=
TAG:compatible_brands=isomavc1
TAG:creation_time=--17T16::.000000Z
TAG:album=Yinyuetai
TAG:artist=yinyuetai.com
TAG:comment=Yinyuetai-1TR1151
TAG:date=// ::
[/FORMAT]

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

appledeMacBook-Pro:Desktop renhui$ ffprobe -print_format json  -show_streams pm.mp4
ffprobe version 3.4. Copyright (c) - the FFmpeg developers
built with Apple LLVM version 9.0. (clang-900.0.39.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4. --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 . 78.100 / . 78.100
libavcodec 57.107. / 57.107.
libavformat . 83.100 / . 83.100
libavdevice . 10.100 / . 10.100
libavfilter 6.107. / 6.107.
libavresample . . / . .
libswscale . 8.100 / . 8.100
libswresample . 9.100 / . 9.100
libpostproc . 7.100 / . 7.100
{
Input #, mov,mp4,m4a,3gp,3g2,mj2, from 'pm.mp4':
Metadata:
major_brand : isom
minor_version :
compatible_brands: isomavc1
creation_time : --17T16::.000000Z
album : Yinyuetai
artist : yinyuetai.com
comment : Yinyuetai-1TR1151
date : // ::
Duration: ::33.51, start: 0.000000, bitrate: kb/s
Stream #:(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 960x540, kb/s, fps, tbr, 25k tbn, tbc (default)
Metadata:
creation_time : --17T16::.000000Z
handler_name : @GPAC0.5.1-DEV-rev5472
Stream #:(und): Audio: aac (LC) (mp4a / 0x6134706D), Hz, stereo, fltp, kb/s (default)
Metadata:
creation_time : --17T15::.000000Z
handler_name : Sound Media Handler
"streams": [
{
"index": ,
"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": ,
"height": ,
"coded_width": ,
"coded_height": ,
"has_b_frames": ,
"sample_aspect_ratio": "0:1",
"display_aspect_ratio": "0:1",
"pix_fmt": "yuv420p",
"level": ,
"chroma_location": "left",
"refs": ,
"is_avc": "true",
"nal_length_size": "",
"r_frame_rate": "25/1",
"avg_frame_rate": "25/1",
"time_base": "1/25000",
"start_pts": ,
"start_time": "0.000000",
"duration_ts": ,
"duration": "273.400000",
"bit_rate": "",
"bits_per_raw_sample": "",
"nb_frames": "",
"disposition": {
"default": ,
"dub": ,
"original": ,
"comment": ,
"lyrics": ,
"karaoke": ,
"forced": ,
"hearing_impaired": ,
"visual_impaired": ,
"clean_effects": ,
"attached_pic": ,
"timed_thumbnails":
},
"tags": {
"creation_time": "2016-12-17T16:02:05.000000Z",
"language": "und",
"handler_name": "264@GPAC0.5.1-DEV-rev5472"
}
},
{
"index": ,
"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": "",
"channels": ,
"channel_layout": "stereo",
"bits_per_sample": ,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/44100",
"start_pts": ,
"start_time": "0.000000",
"duration_ts": ,
"duration": "273.507846",
"bit_rate": "",
"max_bit_rate": "",
"nb_frames": "",
"disposition": {
"default": ,
"dub": ,
"original": ,
"comment": ,
"lyrics": ,
"karaoke": ,
"forced": ,
"hearing_impaired": ,
"visual_impaired": ,
"clean_effects": ,
"attached_pic": ,
"timed_thumbnails":
},
"tags": {
"creation_time": "2016-12-17T15:50:54.000000Z",
"language": "und",
"handler_name": "Sound Media Handler"
}
}
]
}

3. 显示帧信息

ffprobe -show_frames pm.mp4

4. 查看包信息

ffprobe -show_packets pm.mp4

上一篇:FFmpeg命令行工具学习(三):媒体文件转换工具ffmpeg


下一篇:使用FFMpeg命令行录屏推rtmp流