Intel Media SDK H264 encoder GOP setting
1 I幀,P幀,B幀,IDR幀,NAL單元
I frame:幀內編碼幀,又稱intra picture,I 幀通常是每個 GOP(MPEG 所使用的一種視頻壓縮技術)的第一個幀,經過適度地壓縮,做為隨機訪問的參考點,可以當成圖象。I幀可以看成是一個圖像經過壓縮后的產物;
P frame: 前向預測編碼幀,又稱predictive-frame,通過充分將低于圖像序列中前面已編碼幀的時間冗余信息來壓縮傳輸數據量的編碼圖像,也叫預測幀;
B frame: 雙向預測內插編碼幀,又稱bi-directional interpolated prediction frame,既考慮與源圖像序列前面已編碼幀,也顧及源圖像序列后面已編碼幀之間的時間冗余信息來壓縮傳輸數據量的編碼圖像,也叫雙向預測幀;
IDR frame:I和IDR幀都是使用幀內預測的,在編碼和解碼中為了方便,要首個I幀和其他I幀區別開,把第一個I幀叫IDR,這樣就方便控制編碼和解碼流程,所以IDR幀一定是I幀,但I幀不一定是IDR幀;IDR幀的作用是立刻刷新,使錯誤不致傳播,從IDR幀開始,重新算一個新的序列開始編碼。
NAL單元:全稱Network Abstract Layer,即網絡抽象層,在H.264/AVC視頻編碼標準中,整個系統框架被分為了兩個層面:視頻編碼層面(VCL)和網絡抽象層面(NAL)。其中,前者負責有效表示視頻數據的內容,而后者則負責格式化數據并提供頭信息,以保證數據適合各種信道和存儲介質上的傳輸。因此我們平時的每幀數據就是一個NAL單元(SPS與PPS除外)。在實際的H264數據幀中,往往幀前面帶有00 00 00 01 或 00 00 01分隔符,一般來說編碼器編出的首幀數據為PPS與SPS,接著為I幀。
2 GOP(Group of pictures)
所謂GOP,意思是畫面組,一個GOP就是一組連續的畫面。GOP結構一般涉及兩個數字,例如,M=3,N=12。第一個數字M指定I幀和P幀之間的距離,第二個數字N指定兩個I幀之間的距離:及畫面組的大小。對于上面的例子M=3,N=12,GOP結構表示為:IBBPBBPBBPBBI。在一個GOP內I frame的解碼不依賴于任何的其它幀,而p frame的解碼則依賴于其前面的I frame或者P frame,B frame的解碼則依賴于其前的最近的一個I frame或者P frame 及其后的最近的一個P frame。
3 H264 encoder GOP setting
Intel Media SDK Encoding Sample 用法如下
sample_encode.exe h264 -i video.yuv -w 640 -h 480 -o out.mkv -hw -d3d -mkv -b 1000 -f 30
sample_encode.exe h264 -i video.yuv -w 640 -h 480 -o out.mp4 -hw -d3d -mux -b 1000 -f 30
編碼參數包括:輸入格式、幀速率、輸出比特率、輸入視頻流寬高、輸出視頻流寬高等等。這里我們發現,比沒有設置I、B、P幀信息的相關參數,也就是說Demo中并沒有開發這樣的參數設置。通過查看Intel Media SDK的Guide,發現Intel有提供這樣的參數讓我們可以調整I、B、P的構成,具體就是GopOptFlag:
GopOptFlag
Description
The GopOptFlag enumerator itemizes special properties in the GOP (Group of Pictures) sequence.
Name/Description
MFX_GOP_CLOSED
B-frames of the first B-interval can never reference the previous GOP
MFX_GOP_STRICT
The encoder must strictly follow the given GOP structure as defined by parameter GopPicSize,
GopRefDist etc in the mfxVideoParam structure. Otherwise, the encoder can adapt the GOP structure
for better efficiency, whose range is constrained by parameter GopPicSize and GopRefDist etc
而GopOptFlag所在的位置是:
mfxVideoParam -> mfxInfoMFX -> GopOptFlag
此外還需要利用到的相關參數可以參考mfxInfoMFX的說明,主要包括:
mfxU16 GopPicSize;
mfxU16 GopRefDist;
mfxU16 GopOptFlag;
mfxU16 IdrInterval;
GopPicSize
Number of pictures within the current GOP (Group of Pictures); if GopPicSize=0, then the GOP size is unspecified.
If GopPicSize=1, only I-frames are used.
當前GOP中畫面的個數,若GopPicSize=0,則認為GOP尺寸未指定,若GopPicSize=1,則將只使用I幀
GopRefDist
Distance between I- or P- key frames; if it is zero, the GOP structure is unspecified. Note:
If GopRefDist = 1, there are no B-frames used.
I或P關鍵幀之間的距離;若為零,則認為GOP結構未指定,若GopRefDist=1,則將不使用B幀
GopOptFlag
ORs of the GopOptFlag enumerator indicate the additional flags for the GOP specification;
IdrInterval
the sequence header before every Nth I-frame. If IdrInterval=0(default), SDK inserts the sequence header once at the beginning of the stream
對于H264,IdrInterval指定了IDR幀的間隔,單位為I幀;若IdrInterval=0,則每個I幀均為IDR幀。若IdrInterval=1,則每隔一個I幀為IDR幀,以此類推。對于
MPEG2, IdrInterval定義了序列頭間隔,單位為I幀,若IdrInterval=N,SDK將在每第N個I幀之前插入序列頭;若IdrInterval=0(默認),SDK將在流開頭一次 性插入序列頭。
圖 1
圖 2
圖 3
以上圖1和圖2中紅色表示I幀藍色表示P幀綠色表示B幀,其中圖2和圖3是同一個H264文件,圖3可體現IdrInterval = 1的作用,即兩個Idr幀間隔一個I幀,所以也可以把IDR幀看做是SPS和PPS后面第一個I幀!
參考:
http://www.cnblogs.com/cslunatic/p/3565984.html
http://en.wikipedia.org/wiki/Group_of_pictures
http://blog.csdn.net/jtujtujtu/article/details/6565287
總結
以上是生活随笔為你收集整理的Intel Media SDK H264 encoder GOP setting的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 消息称育碧《幽灵行动》新作将于 2025
- 下一篇: 上阴线下影线表示什么 最高最低价与收盘价