音視頻流的結構的分析對進行音視頻的處理或者對直播過程中的直播流的卡頓等情況的分析處理起到了至關重要的作用。目前剛剛開始接觸這塊兒,還是個小白,這里根據平時使用到的一些ffprobe的命令進行一些總結,以作備忘:
ffprobe常用的參數比較多,如果想知道具體的可以使用ffprobe --help來查看一些詳細的命令。
我目前涉及到的主要是查看視頻流的時間戳、編碼格式,主要用得到的命令如下:
- ** 使用 -show_frames 參數查看視頻中的幀信息:**
{
"media_type": "video",
"stream_index": 1,
"key_frame": 0,
"pkt_pts": 27275,
"pkt_pts_time": "45.458333",
"pkt_dts": 27274,
"pkt_dts_time": "45.456667",
"best_effort_timestamp": 27275,
"best_effort_timestamp_time": "45.458333",
"pkt_duration": 20,
"pkt_duration_time": "0.033333",
"pkt_pos": "4519791",
"pkt_size": "970",
"width": 568,
"height": 320,
"pix_fmt": "yuv420p",
"pict_type": "B",
"coded_picture_number": 1364,
"display_picture_number": 0,
"interlaced_frame": 0,
"top_field_first": 0,
"repeat_pict": 0
},
-show_frames打印出來的信息都是幀相關的,包括視頻幀和音頻幀,其中主要的數據及其含義如下:
key_frame:是否是關鍵幀
pkt_pts:幀的pts數值
pkt_pts_time:通過time_base計算出來的顯示時間
pkt_dts:幀的dts數值
pkt_dts_time:通過time_base計算出來的dts時間
pict_type:幀類型(I、B、P)
-
使用 -show_streams 參數查看視頻中的流信息:
"index": 1,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "Main",
"codec_type": "video",
"codec_time_base": "464/27825",
"codec_tag_string": "avc1",
"codec_tag": "0x31637661",
"width": 568,
"height": 320,
"coded_width": 568,
"coded_height": 320,
"has_b_frames": 0,
"sample_aspect_ratio": "0:1",
"display_aspect_ratio": "0:1",
"pix_fmt": "yuv420p",
"level": 30,
"color_range": "tv",
"color_space": "bt709",
"color_transfer": "bt709",
"color_primaries": "bt709",
"chroma_location": "left",
"refs": 1,
"is_avc": "true",
"nal_length_size": "4",
"r_frame_rate": "30000/1001",
"avg_frame_rate": "27825/928",
"time_base": "1/600",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 29696,
"duration": "49.493333",
"bit_rate": "705282",
"bits_per_raw_sample": "8",
"nb_frames": "1484",
"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-22T03:35:39.000000Z",
"language": "und",
"handler_name": "Core Media Video"
}
以上便是打印出來的信息,主要的就是編碼格式、原始數據格式、time_base和碼率等信息是使用較多的。 - ** 使用 -show_packets 參數查看包信息:**
{
"codec_type": "video",
"stream_index": 1,
"pts": 28676,
"pts_time": "47.793333",
"dts": 28675,
"dts_time": "47.791667",
"duration": 20,
"duration_time": "0.033333",
"size": "1199",
"pos": "4737832",
"flags": "__"
},
同上,主要輸出的都是關于流類型和pts、dts等信息。
上面的參數可以獲得音視頻相關的各種參數,但是顯示的可能比較亂,所以可以使用下面的參數進行輸出的格式化:
-of 或者 -print_format + compact/csv/flat/ini/json/xml
同時,可以通過使用如下參數進行視頻流或者音頻流的選擇:
-select_streams + a(音頻) / v(視頻)
利用好這個工具,可以在進行音視頻編解碼的時候對時間戳等信息進行更好的校對;同時在進行音視頻流卡頓的分析的時候也很有用處,比如可以通過觀察pts等信息查看是否有時間戳回退等問題的存在。
后續如果有新的收獲還會繼續更新。