- 論壇徽章:
- 0
|
1. H.264起始碼
在網(wǎng)絡(luò)傳輸h264數(shù)據(jù)時(shí),一個(gè)UDP包就是一個(gè)NALU,解碼器可以很方便的檢測出NAL分界和解碼。但是如果編碼數(shù)據(jù)存儲為一個(gè)文件,原來的解碼器將無法從數(shù)據(jù)流中分別出每個(gè)NAL的起始位置和終止位置,為此h.264用起始碼來解決這一問題。
H.264編碼時(shí),在每個(gè)NAL前添加起始碼 0x000001,解碼器在碼流中檢測到起始碼,當(dāng)前NAL結(jié)束。為了防止NAL內(nèi)部出現(xiàn)0x000001的數(shù)據(jù),h.264又提出'防止競爭 emulation prevention"機(jī)制,在編碼完一個(gè)NAL時(shí),如果檢測出有連續(xù)兩個(gè)0x00字節(jié),就在后面插入一個(gè)0x03。當(dāng)解碼器在NAL內(nèi)部檢測到0x000003的數(shù)據(jù),就把0x03拋棄,恢復(fù)原始數(shù)據(jù)。
0x000000 >>>>>> 0x00000300
0x000001 >>>>>> 0x00000301
0x000002 >>>>>> 0x00000302
0x000003 >>>>>> 0x00000303
附上h.264解碼nalu中檢測起始碼的算法流程
for(;;)
{
if next 24 bits are 0x000001
{
startCodeFound = true
break;
}
else
{
flush 8 bits
}
}// for(;;)
if(true == startCodeFound)
{
//startcode found
// Flush the start code found
flush 24 bits
//Now navigate up to next start code and put the in between stuff
// in the nal structure.
for(;;)
{
get next 24 bits & check if it equals to 0x000001
if(false == (next 24 bits == 000001))
{
// search for pattern 0x000000
check if next 24 bits are 0x000000
if(false == result)
{
// copy the byte into the buffer
copy one byte to the Nal unit
}
else
{
break;
}
}
else
{
break;
}
}//for(;;)
}
2. MPEG4起始碼
MPEG4的特色是VOP,沒有NALU的概念,仍使用startcode對每幀進(jìn)行分界。MPEG4的起始碼是0x000001. 另外MPEG4中很多起始碼也很有用,比如video_object_sequence_start_code 0x000001B0 表示一個(gè)視頻對象序列的開始,VO_start_code 0x000001B6 表示一個(gè)VOP的開始. 0x000001B6之后的兩位,是00表示 I frame, 01 表示 P frame, 10 表示 B frame.
本文來自ChinaUnix博客,如果查看原文請點(diǎn):http://blog.chinaunix.net/u2/77292/showart_1983315.html |
|