ffprobe輸入與輸出信息詳解

ffprobeffmpeg提供的三大工具之一,用來查看音視頻文件的各種信息,比如:封裝格式、音頻/視頻流信息、數據包信息等。

ffprobe的源碼是ffprobe.c,開發過程中如果想獲取ffprobe查看的信息,可以通過分析源碼,獲得對應字段。 本文主要介紹formatstreamPacketFrame信息,包含每個字段的說明以及對應的ffmpeg字段。

輸出每個流的具體信息(以JSON格式)

ffprobe -v quiet -print_format json -show_format -show_streams http://XXXXX.mp4
{
    "streams": [
        {
            "index": 0,    流索引號
            "codec_name": "h264",   編碼器名
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",    編碼器名全稱
            "codec_type": "video",    編碼器類型
            "codec_time_base": "1/30",    編碼器每幀時長
            "codec_tag_string": "avc1",    編碼器標籤名
            "codec_tag": "0x31637661",    編碼器標籤
            "width": 1152,   寬度
            "height": 864,   高度
            "has_b_frames": 0,   記錄幀緩存大小
            "sample_aspect_ratio": "1:1",   採樣率
            "display_aspect_ratio": "4:3",
            "pix_fmt": "yuv420p",   像素個數
            "level": 40,   級別
            "is_avc": "1",
            "nal_length_size": "4",
            "r_frame_rate": "15/1",   真實基礎幀率
            "avg_frame_rate": "15/1",   平均幀率
            "time_base": "1/15000",   每幀時長
            "start_time": "0.000000",   首幀時間
            "duration": "6413.333333",   文件總時間
            "nb_frames": "96200",   幀數
            "tags": {    標籤
                "creation_time": "2013-01-07 12:58:08",     創建時間
                "language": "eng",   語言
                "handler_name": "Video Media Handler"    處理器名字
            }
        },
        {
            "index": 1,   流索引號
            "codec_name": "aac",   編碼器名
            "codec_long_name": "Advanced Audio 編碼器全名Coding",   編碼器名全稱
            "codec_type": "audio",   編碼器類型
            "codec_time_base": "1/44100",   編碼器每幀時長
            "codec_tag_string": "mp4a",   編碼器標籤名
            "codec_tag": "0x6134706d",   編碼器標籤
            "sample_fmt": "s16",   採樣格式
            "sample_rate": "44100",   採樣率
            "channels": 2,   音頻數
            "bits_per_sample": 0,   採樣碼率
            "r_frame_rate": "0/0",   真實基礎幀率
            "avg_frame_rate": "0/0",   平均幀率
            "time_base": "1/44100",   每幀時長
            "start_time": "0.000000",   首幀時間
            "duration": "6413.374694",   文件總時間
            "nb_frames": "276201",   幀數
            "tags": {   標籤信息
                "creation_time": "2013-01-07 12:58:08",   創建時間
                "language": "eng",   語言
                "handler_name": "Sound Media Handler"   處理器名字
            }
        }
    ],
    "format": {
        "nb_streams": 2,   流的數目
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",   格式名  
        "format_long_name": "QuickTime/MPEG-4/Motion JPEG 2000 format",   格式名全稱
        "start_time": "0.000000",   首幀時間
        "duration": "6413.359589",   時長
        "size": "101416337",   文件大小
        "bit_rate": "126506",   碼率
        "tags": {   標籤信息
            "major_brand": "mp42",   主品牌
            "minor_version": "1",   次要版本
            "compatible_brands": "M4V mp42isom",   兼容性品牌
            "creation_time": "2013-01-07 12:58:08"   創建時間
        }
    }
}

查看音視頻文件的封裝格式

ffprobe -show_format inputFile

輸出如下信息:

[FORMAT]
// 文件名
filename=VID_20190811_113717.mp4
// 容器中流的個數,即AVFormatContext->nb_streams
nb_streams=2
// 即AVFormatContext->nb_programs
nb_programs=0
// 封裝格式,即AVFormatContext->iformat->name
format_name=mov,mp4,m4a,3gp,3g2,mj2
// 即AVFormatContext->iformat->long_name
format_long_name=QuickTime / MOV
// 即AVFormatContext->start_time,基於AV_TIME_BASE_Q,換算爲秒
start_time=0.000000
// 即AVFormatContext->duration,基於AV_TIME_BASE_Q,換算爲秒
duration=10.508000
// 單位字節,即avio_size(AVFormatContext->pb)
size=27263322
// 碼率,即AVFormatContext->bit_rate
bit_rate=20756240
// 即AVFormatContext->probe_score
probe_score=100
[/FORMAT]

查看音視頻文件的流信息

ffprobe -show_streams inputFile

輸出如下信息:

[STREAM]
// 當前流的索引信息,對應於AVStream->index
index=0
// AVCodecDescriptor * cd = avcodec_descriptor_get(AVStream->codecpar->codec_id)
// 編碼名稱,即cd->name
codec_name=h264
// 編碼全稱,即cd->long_name
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
// 一個編碼參數,可以爲Baseline、Main、High等,Baseline無B幀,Main及以後可以包含B幀
// 通過avcodec_profile_name(AVStream->codecpar->codec_id, AVStream->codecpar->profile)獲得
profile=High
// 流類型,即av_get_media_type_string(AVStream->codecpar->codec_type)
codec_type=video
// 即AVStream->codec->time_base
codec_time_base=14777/877500
// 通過宏av_fourcc2str(AVStream->codecpar->codec_tag)獲得
codec_tag_string=avc1
// 對應AVStream->codecpar->codec_tag
codec_tag=0x31637661
// 有效區域的寬度,即AVStream->codecpar->width
width=1920
// 有效區域的高度,即AVStream->codecpar->height
height=1080
// 視頻幀寬度,可能與上面的寬度不同,即AVStream->codec->coded_width,例如:當解碼幀在輸出前裁剪或啓用低分辨率時
coded_width=1920
// 視頻幀高度,可能與上面的高度不同,即AVStream->codec->coded_height,例如:當解碼幀在輸出前裁剪或啓用低分辨率時
coded_height=1088
// 視頻的延遲幀數,即AVStream->codecpar->video_delay
has_b_frames=0
// sar,圖像採集時,橫向採集點數與縱向採集點數的比例
// FFmpeg提供了多個sar:AVStream->sample_aspect_ratio、AVStream->codecpar->sample_aspect_ratio、AVFrame->sample_aspect_ratio
// 通過av_guess_sample_aspect_ratio獲取最終的sar
sample_aspect_ratio=1:1
// dar,真正展示的圖像寬高比,在渲染視頻時,必須根據這個比例進行縮放
// 通過av_reduce計算得到,par * sar = dar
display_aspect_ratio=16:9
// 像素格式,即av_get_pix_fmt_name(AVStream->codecpar->format)
pix_fmt=yuvj420p
// 編碼參數,即AVStream->codecpar->level
level=40
// 額外的色彩空間特徵,即av_color_range_name(AVStream->codecpar->color_range),AVCOL_RANGE_MPEG對應tv,AVCOL_RANGE_JPEG對應pc
color_range=pc
// YUV彩色空間類型,即av_color_space_name(AVStream->codecpar->color_space)
color_space=bt470bg
// 顏色傳輸特性,即av_color_transfer_name(AVStream->codecpar->color_trc)
color_transfer=smpte170m
// 即av_color_primaries_name(AVStream->codecpar->color_primaries)
color_primaries=bt470bg
// 色度樣品的位置,即av_chroma_location_name(AVStream->codecpar->chroma_location)
chroma_location=left
// 交錯視頻中字段的順序,即AVStream->codecpar->field_order
field_order=unknown
// av_timecode_make_mpeg_tc_string處理AVStream->codec->timecode_frame_start獲得
timecode=N/A
// 參考幀數量,即AVStream->codec->refs
refs=1
is_avc=true
// 表示用幾個字節表示NALU的長度
nal_length_size=4
id=N/A
// 當前流的基本幀率,這個值僅是一個猜測,對應於AVStream->r_frame_rate
r_frame_rate=30/1
// 平均幀率,對應於AVStream->avg_frame_rate
avg_frame_rate=438750/14777
// AVStream的時間基準,即AVStream->time_base
time_base=1/90000
// 流開始時間,基於time_base,即AVStream->start_time
start_pts=0
// 轉換(start_pts * time_base)之後的開始時間,單位秒
start_time=0.000000
// 流時長,基於time_base,即AVStream->duration
duration_ts=945728
// 轉換(duration_ts * time_base)之後的時長,單位秒
duration=10.508089
// 碼率,即AVStream->codecpar->bit_rate
bit_rate=19983544
// 最大碼率,即AVStream->codec->rc_max_rate
max_bit_rate=N/A
// Bits per sample/pixel,即AVStream->codec->bits_per_raw_sample
bits_per_raw_sample=8
// 視頻流中的幀數,即AVStream->nb_frames
nb_frames=312
nb_read_frames=N/A
nb_read_packets=N/A
// 下面TAG爲AVStream->metadata中的信息
// 逆時針的旋轉角度(相當於正常視頻的逆時針旋轉角度)
TAG:rotate=90
// 創建時間
TAG:creation_time=2019-08-11T03:37:28.000000Z
// 語言
TAG:language=eng
TAG:handler_name=VideoHandle
// SIDE_DATA爲AVStream->side_data數據
[SIDE_DATA]
// side_data數據類型,Display Matrix表示一個3*3的矩陣,這個矩陣需要應用到解碼後的視頻幀上,才能正確展示
side_data_type=Display Matrix
displaymatrix=
00000000:            0       65536           0
00000001:       -65536           0           0
00000002:            0           0  1073741824
// 順時針旋轉90度還原視頻
rotation=-90
[/SIDE_DATA]
[/STREAM]
[STREAM]
// 當前流的索引信息,對應於AVStream->index
index=1
// AVCodecDescriptor * cd = avcodec_descriptor_get(AVStream->codecpar->codec_id)
// 編碼名稱,即cd->name
codec_name=aac
// 編碼全稱,即cd->long_name
codec_long_name=AAC (Advanced Audio Coding)
// 通過avcodec_profile_name(AVStream->codecpar->codec_id, AVStream->codecpar->profile)獲得
profile=LC
// 流類型,即av_get_media_type_string(AVStream->codecpar->codec_type)
codec_type=audio
// 即AVStream->codec->time_base
codec_time_base=1/48000
// 通過宏av_fourcc2str(AVStream->codecpar->codec_tag)獲得
codec_tag_string=mp4a
// 對應AVStream->codecpar->codec_tag
codec_tag=0x6134706d
// 採樣點格式,通過av_get_sample_fmt_name(AVStream->codecpar->format)獲取
sample_fmt=fltp
// 採樣率,即AVStream->codecpar->sample_rate
sample_rate=48000
// 通道數,即AVStream->codecpar->channels
channels=2
// 通道佈局,與channels是相對應,通過av_bprint_channel_layout獲取,stereo表示立體聲
channel_layout=stereo
// 每個採樣點佔用多少bit,即av_get_bits_per_sample(par->codec_id)
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
// AVStream的時間基準,即AVStream->time_base
time_base=1/48000
// 流開始時間,基於time_base,即AVStream->start_time
start_pts=0
// 轉換(start_pts * time_base)之後的開始時間,單位秒
start_time=0.000000
// 流時長,基於time_base,即AVStream->duration
duration_ts=502776
// 轉換(duration_ts * time_base)之後的時長,單位秒
duration=10.474500
// 碼率,即AVStream->codecpar->bit_rate
bit_rate=156002
// 最大碼率,即AVStream->codec->rc_max_rate
max_bit_rate=156000
// Bits per sample/pixel,即AVStream->codec->bits_per_raw_sample
bits_per_raw_sample=N/A
// 音頻流中的幀數,即AVStream->nb_frames
nb_frames=491
nb_read_frames=N/A
nb_read_packets=N/A
TAG:creation_time=2019-08-11T03:37:28.000000Z
TAG:language=eng
TAG:handler_name=SoundHandle
[/STREAM]

查看音視頻文件的數據包信息

// -select_streams表示選擇音頻或者視頻
ffprobe -show_format [-select_streams audio | video] inputFile

首先看下視頻流的第一個Packet和第二個Packet:

[PACKET]
//Packet類型,即av_get_media_type_string(AVStream->codecpar->codec_type)
codec_type=video
// 當前幀所屬流的索引信息,對應於AVStream->index
stream_index=0
// 幀展示時間,即AVPacket->pts,基於AVStream->time_base時間基準
pts=0
// 換算爲秒
pts_time=0.000000
// 幀解碼時間,即AVPacket->dts,基於AVStream->time_base時間基準
dts=0
// 換算爲秒
dts_time=0.000000
// 當前幀的時長,等於下一幀的pts - 當前幀pts,即AVPacket->duration,基於AVStream->time_base時間基準
duration=12972
// 換算爲秒
duration_time=0.144133
// AVPacket->convergence_duration,也是基於AVStream->time_base時間基準
convergence_duration=N/A
// 換算爲秒
convergence_duration_time=N/A
// 當前幀的Size,字節,即AVPacket->size
size=187872
// 當前幀地址偏移量,即AVPacket->pos
pos=830842
flags=K_
[/PACKET]
[PACKET]
codec_type=video
stream_index=0
pts=12972
// 即 12972 / 90000
pts_time=0.144133
dts=12972
dts_time=0.144133
duration=2999
duration_time=0.033322
convergence_duration=N/A
convergence_duration_time=N/A
size=31200
// 上一幀的pos + size
pos=1018714
flags=__
[/PACKET]

然後看下音頻流的第一個Packet和第二個Packet:

[PACKET]
// 音頻幀
codec_type=audio
// 當前幀所屬流的索引信息,對應於AVStream->index
stream_index=1
// 幀展示時間,即AVPacket->pts,基於AVStream->time_base時間基準
pts=0
pts_time=0.000000
// 幀解碼時間,即AVPacket->dts,基於AVStream->time_base時間基準
dts=0
dts_time=0.000000
// 當前幀的時長,等於下一幀的pts - 當前幀pts,即AVPacket->duration,基於AVStream->time_base時間基準
duration=1024
// 1024 / 48000
duration_time=0.021333
convergence_duration=N/A
convergence_duration_time=N/A
size=416
pos=810458
flags=K_
[/PACKET]
[PACKET]
// 音頻幀
codec_type=audio
stream_index=1
pts=1024 
// 1024 / 48000
pts_time=0.021333
dts=1024
dts_time=0.021333
duration=1024
duration_time=0.021333
convergence_duration=N/A
convergence_duration_time=N/A
size=416
// 上一幀的pos + size
pos=810874
flags=K_
[/PACKET]

查看音視頻文件解碼後的幀信息

// -select_streams表示選擇音頻或者視頻
ffprobe -show_frames [-select_streams audio | video] inputFile

首先看下視頻流的第一幀和第二幀:

[FRAME]
// 幀類型,即av_get_media_type_string(AVStream->codecpar->codec_type)
media_type=video
// 當前幀所屬流的索引信息, 對應於AVStream->index
stream_index=0
// 是否關鍵幀,1:關鍵幀,0:非關鍵幀,即AVFrame->key_frame
key_frame=1
// 幀展示時間, 即AVFrame->pts, 基於AVStream->time_base時間基準
pkt_pts=0
// 換算爲秒
pkt_pts_time=0.000000
// 幀解碼時間,從對應的AVPacket copy而來,即AVFrame->pkt_dts,基於AVStream->time_base時間基準
pkt_dts=0
// 換算爲秒
pkt_dts_time=0.000000
// 幀時間戳,基本與pts相同,即AVFrame->best_effort_timestamp,基於AVStream->time_base時間基準
best_effort_timestamp=0
// 換算爲秒
best_effort_timestamp_time=0.000000
// 對應的AVPacket的幀時長,即AVFrame->pkt_duration,基於AVStream->time_base時間基準
pkt_duration=12972
// 換算爲秒
pkt_duration_time=0.144133
// 從最後一個已輸入解碼器的AVPacket重新排序的pos,即AVFrame->pkt_pos
pkt_pos=830842
// 對應的AVPacket的幀size,即AVFrame->pkt_size
pkt_size=187872
// 旋轉之前的幀寬度,即AVFrame->width
width=1920
// 旋轉之前的幀高度,即AVFrame->height
height=1080
// 視頻幀的像素格式,即av_get_pix_fmt_name(AVFrame->format)
pix_fmt=yuvj420p
// sar,圖像採集時,橫向採集點數與縱向採集點數的比例
// FFmpeg提供了多個sar:AVStream->sample_aspect_ratio、AVStream->codecpar->sample_aspect_ratio、AVFrame->sample_aspect_ratio
// 通過av_guess_sample_aspect_ratio獲取最終的sar
sample_aspect_ratio=1:1
// 視頻幀的圖片類型,此處爲I幀,即av_get_picture_type_char(frame->pict_type)
pict_type=I
// picture number in bitstream order, 即AVFrame->coded_picture_number
coded_picture_number=0
// picture number in display order, 即AVFrame->display_picture_number
display_picture_number=0
// 視頻幀內容是否是交錯的, 即AVFrame->interlaced_frame
interlaced_frame=0
// 若視頻幀內容是交錯的,表示首先展示的頂部字段,即AVFrame->top_field_first
top_field_first=0
// 當解碼時,這個信號表明視頻幀必須延遲多少。extra_delay = repeat_pict / (2*fps), 即AVFrame->repeat_pict
repeat_pict=0
// 額外的色彩空間特徵,即av_color_range_name(AVFrame->color_range),AVCOL_RANGE_MPEG對應tv,AVCOL_RANGE_JPEG對應pc
color_range=pc
// YUV彩色空間類型,即av_color_space_name(AVFrame->colorspace)
color_space=bt470bg
// 即av_color_primaries_name(AVFrame->color_primaries)
color_primaries=bt470bg
// 顏色傳輸特性,即av_color_transfer_name(AVFrame->color_trc)
color_transfer=smpte170m
// 色度樣品的位置,即av_chroma_location_name(AVFrame->chroma_location)
chroma_location=left
[/FRAME]
[FRAME]
media_type=video
stream_index=0
// 非關鍵幀
key_frame=0
pkt_pts=12972
// 12972 / 90000
pkt_pts_time=0.144133
pkt_dts=12972
pkt_dts_time=0.144133
best_effort_timestamp=12972
best_effort_timestamp_time=0.144133
pkt_duration=2999
pkt_duration_time=0.033322
pkt_pos=1018714
pkt_size=31200
width=1920
height=1080
pix_fmt=yuvj420p
sample_aspect_ratio=1:1
// 視頻幀的圖片類型,此處爲P幀,即av_get_picture_type_char(frame->pict_type)
pict_type=P
coded_picture_number=1
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
color_range=pc
color_space=bt470bg
color_primaries=bt470bg
color_transfer=smpte170m
chroma_location=left
[/FRAME]

然後看下音頻流的第一幀和第二幀:

[FRAME]
// 幀類型,即av_get_media_type_string(AVStream->codecpar->codec_type)
media_type=audio
// 當前幀所屬流的索引信息, 對應於AVStream->index
stream_index=1
// 是否關鍵幀
key_frame=1
// 幀展示時間, 即AVFrame->pts, 基於AVStream->time_base時間基準
pkt_pts=0
// 換算爲秒
pkt_pts_time=0.000000
// 幀解碼時間,從對應的AVPacket copy而來,即AVFrame->pkt_dts,基於AVStream->time_base時間基準
pkt_dts=0
// 換算爲秒
pkt_dts_time=0.000000
// 幀時間戳,基本與pts相同,即AVFrame->best_effort_timestamp,基於AVStream->time_base時間基準
best_effort_timestamp=0
// 換算爲秒
best_effort_timestamp_time=0.000000
// 對應的AVPacket的幀時長,即AVFrame->pkt_duration,基於AVStream->time_base時間基準
pkt_duration=1024
// 換算爲秒
pkt_duration_time=0.021333
// 從最後一個已輸入解碼器的AVPacket重新排序的pos,即AVFrame->pkt_pos
pkt_pos=810458
// 對應的AVPacket的幀size,即AVFrame->pkt_size
pkt_size=416
// 音頻採樣點格式,即av_get_sample_fmt_name(AVFrame->format)
sample_fmt=fltp
// 當前音頻幀的採樣點數,即AVFrame->nb_samples
nb_samples=1024
// 通道數,即AVFrame->channels
channels=2
// 通道佈局,通過av_bprint_channel_layout得到,與channels對應
channel_layout=stereo
[/FRAME]
[FRAME]
media_type=audio
stream_index=1
key_frame=1
pkt_pts=1024
pkt_pts_time=0.021333
pkt_dts=1024
pkt_dts_time=0.021333
best_effort_timestamp=1024
best_effort_timestamp_time=0.021333
pkt_duration=1024
pkt_duration_time=0.021333
pkt_pos=810874
pkt_size=416
sample_fmt=fltp
nb_samples=1024
channels=2
channel_layout=stereo
[/FRAME]

參考文章

https://developer.qiniu.com/dora/api/1269/pictures-basic-information-imageinfo
https://www.zybuluo.com/ltlovezh/note/1534824

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章