SODB 數據比特串-->最原始的編碼數據ide
RBSP 原始字節序列載荷-->在SODB的後面填加告終尾比特(RBSP trailing bits 一個bit「1」)若干比特「0」,以便字節對齊。編碼
EBSP 擴展字節序列載荷-->在RBSP基礎上填加了仿校驗字節(0X03)它的緣由是: 在NALU加到Annexb上時,須要填加每組NALU以前的開始碼StartCodePrefix,若是該NALU對應的slice爲一幀的開始則用4位字節表示,ox00000001,不然用3位字節表示ox000001.爲了使NALU主體中不包括與開始碼相沖突的,在編碼時,每遇到兩個字節連續爲0,就插入一個字節的0x03。解碼時將0x03去掉。也稱爲脫殼操做。ip
網上查詢的區別:it
在對整幀圖像的數據比特串(SODB)添加原始字節序列載荷(RBSP)結尾比特(RBSP trailing bits,添加一比特的「1」和若干比特「0」,以便字節對齊)後,再檢查RBSP 中是否存在連續的三字節「00000000 00000000 000000xx」;若存在這種連續的三字節碼,在第三字節前插入一字節的「0×03」,以避免與起始碼競爭,造成EBSP碼流,這須要將近兩倍的整幀圖像碼流大小。爲了減少存儲器需求,在每一個宏塊編碼結束後即檢查該宏塊SODB中的起始碼競爭問題,並保留SODB最後兩字節的零字節個數,以便與下一宏塊的SODB的開始字節造成連續的起始碼競爭檢測;對一幀圖像的最後一個宏塊,先添加結尾中止比特,再檢測起始碼競爭。io
程序:ast
typedef structclass
{stream
int byte_pos; //!< current position in bitstream;基礎
int bits_to_go; //!< current bitcounter擴展
byte byte_buf; //!< current buffer for last written byte
int stored_byte_pos; //!< storage for position in bitstream;
int stored_bits_to_go; //!< storage for bitcounter
byte stored_byte_buf; //!< storage for buffer of last written byte
byte byte_buf_skip; //!< current buffer for last written byte
int byte_pos_skip; //!< storage for position in bitstream;
int bits_to_go_skip; //!< storage for bitcounter
byte *streamBuffer; //!< actual buffer for written bytes
int write_flag; //!< Bitstream contains data and needs to be written
} Bitstream; 定義比特流結構
static byte *NAL_Payload_buffer;
void SODBtoRBSP(Bitstream *currStream)
{
currStream->byte_buf <<= 1; //左移1bit
currStream->byte_buf |= 1; //在尾部填一個「1」佔1bit
currStream->bits_to_go--;
currStream->byte_buf <<= currStream->bits_to_go;
currStream->streamBuffer[currStream->byte_pos++] = currStream->byte_buf;
currStream->bits_to_go = 8;
currStream->byte_buf = 0;
}
int RBSPtoEBSP(byte *streamBuffer, int begin_bytepos, int end_bytepos, int min_num_bytes)
{
int i, j, count;
for(i = begin_bytepos; i < end_bytepos; i++)
NAL_Payload_buffer[i] = streamBuffer[i];
count = 0; j = begin_bytepos; for(i = begin_bytepos; i < end_bytepos; i++) { if(count == ZEROBYTES_SHORTSTARTCODE && !(NAL_Payload_buffer[i] & 0xFC)) { streamBuffer[j] = 0x03; j++; count = 0; } streamBuffer[j] = NAL_Payload_buffer[i]; if(NAL_Payload_buffer[i] == 0x00) count++; else count = 0; j++; } while (j < begin_bytepos+min_num_bytes) { streamBuffer[j] = 0x00; // cabac stuffing word streamBuffer[j+1] = 0x00; streamBuffer[j+2] = 0x03; j += 3; stat->bit_use_stuffingBits[img->type]+=16; } return j;}