FFmpeg av_dump_format輸出的tbn、tbc、tbr、PAR、DAR的含義

av_dump_format(fmtCtx, 0, "rtmp://live.hkstv.hk.lxdns.com/live/hks", 0);會打印流媒體的信息,比如:

[flv @ 0x7fa6ec813400] Stream discovered after head already parsed
Input #0, flv, from 'rtmp://live.hkstv.hk.lxdns.com/live/hks':
  Metadata:
    author          : PowerSmart
    copyright       : 
    description     : 
    datarate        : 500
    livetime        : 1453688059
    timeshift       : 0
  Duration: 01:00:00.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Audio: aac (LC), 32000 Hz, stereo, fltp
    Stream #0:1: Video: h264 (Constrained Baseline), yuv420p, 640x480, 15.17 fps, 15 tbr, 1k tbn, 30 tbc

其中,15 tbr, 1k tbn, 30 tbc是什麼意思,很多人並不瞭解。

There are three different time bases for time stamps in FFmpeg. The values printed are actually reciprocals of these, i.e. 1/tbr, 1/tbn and 1/tbc.

tbn is the time base in AVStream that has come from the container, I think. It is used for all AVStream time stamps.

tbc is the time base in AVCodecContext for the codec used for a particular stream. It is used for all AVCodecContext and related time stamps.

tbr is guessed from the video stream and is the value users want to see when they look for the video frame rate, except sometimes it is twice what one would expect because of field rate versus frame rate.

tbr一般被當成幀率。當視頻的碼率爲固定碼率時,FFmpeg顯示tbr爲正常的碼率值。當視頻有變長碼率時,FFmpeg打印的tbr爲多個碼率的均值,看着像音頻流。比如:

Video: h264, yuv420p, 640x480, 22050 tbr, 22050 tbn, 44100 tbc

新問題
Stream #0.0[0xfe]: Video: h264, yuv420p, 1920x1080 [PAR 1:1 DAR 16:9], 59.94 tbr, 90k tbn, 59.94 tbc中PAR、DAR是什麼含義?

PAR - pixel aspect ratio大多數情況爲1:1,就是一個正方形像素,否則爲長方形像素

DAR - display aspect ratio就是視頻播放時,我們看到的圖像寬高的比例,縮放視頻也要按這個比例來,否則會使圖像看起來被壓扁或者拉長了似的。

SAR - storage aspect ratio就是對圖像採集時,橫向採集與縱向採集構成的點陣,橫向點數與縱向點數的比值。比如VGA圖像640/480 = 4:3,D-1 PAL圖像720/576 = 5:4

這三者的關係PAR x SAR = DAR或者PAR = DAR/SAR.

如果一段視頻的DAR爲4:3,它的SAR爲VGA存儲的4:3,那麼可推出PAR爲1:1,如果它的SAR爲D-1 PAL存儲的5:4,那麼可以推出PAR爲16:15


D-1 PAL圖像

看上圖,假設這就是一個D-1 PAL圖像,每個方格代表一個存儲的點,橫向有5個點,縱向有4個點,所以SAR爲5:4

現已知這幅圖象的寬度爲160,高度爲120,即DAR爲4:3

那這個方格的寬高比是多少呢?答案16:15,即PAR,這個方格代表的是一個長方形的像素。

視頻三比率SAR,PAR,DAR是從宏觀上描述一個視頻輪廓很重要的三個參數。在不同的文檔中,通常對這三個參數有不同的表述。但是,均指代同一事物。

參考及推薦閱讀:



文/賴__82084788(簡書作者)
原文鏈接:http://www.jianshu.com/p/5b78a91f1091
著作權歸作者所有,轉載請聯繫作者獲得授權,並標註“簡書作者”。
發佈了46 篇原創文章 · 獲贊 9 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章