2017-08-11 36 views
0

我修改了h264_encoder_impl以使用基於nvidia網格的硬件編碼器。這是通過用Nvidia API調用替換OpenH264特定的調用來完成的。編碼流可以成功寫入文件,但和_sizeencoded_image_是不夠的,RTPFragmentationHeader也需要填寫。WebRTC:編碼器實現中的RTPFragmentationHeader是什麼?

// RtpFragmentize(EncodedImage* encoded_image, 
//      std::unique_ptr<uint8_t[]>* encoded_image_buffer, 
//      const VideoFrameBuffer& frame_buffer, 
//      SFrameBSInfo* info, 
//      RTPFragmentationHeader* frag_header) 

// encode 
openh264_->Encode(input, &info /*out*/); 

// fragmentize ? 
RtpFragmentize(&encoded_image_ /*out*/, &encoded_image_buffer_, *frame_buffer, 
       &info, &frag_header /*out*/); 

// ... 

// send 
encoded_image_callback_->OnEncodedImage(encoded_image_, &codec_specific, &frag_header); 

基於當前Openh264實施填補了RTPFragmentize()frag_header和VP8不同填充它。我可以看到NAL untis和圖層,其中也計算encoded_image->_length,但我不知道如何。

我在任何地方都找不到任何文檔。我擁有的只有VP8和OpenH264。

那麼什麼是RTPFragmentationHeader?它有什麼作用?什麼是encoded_image->_length?使用定製H264編碼器時如何正確填充?我可以找到startcode,但接下來呢?如何填寫其所有成員?

回答

1

經過RTPFragmentize()h264_encoder_impl之後我已經想通了。

在編碼幀中有多個NALU。有不同的NALU包括AUD,SPS(67),PPS(68)和IDR。每個NALU由4個字節的起始碼分隔,即00 00 00 01

對於OpenH264,頭看上去像這樣第一幀

 
[00 00 00 01 67 42 c0 20 8c 8d 40 20 03 09 00 f0 
88 46 a0 00 00 00 01 68 ce 3c 80]00 00 00 01 .. 

你可以看到大膽啓動代碼。只有方括號內的字節屬於標題,最後的起始碼是幀數據。

RTPFragmentationHeader以上:

frag_header->fragmentationVectorSize = 3  // 2 fragments for header 
              // 3rd fragment for frame buffer 

frag_header->fragmentationOffset[0] = 4  
frag_header->fragmentationLength[0] = 15 

frag_header->fragmentationOffset[1] = 23 // 4 + 15 + sizeof(startcode) 
frag_header->fragmentationLength[1] = 4  

frag_header->fragmentationOffset[2] = 31 
frag_header->fragmentationLength[2] = 43218 // last fragment is frame buffer 

接着幀總是看起來像以下

00 00 00 01 67 b8 .. .. .. 

encoded_image->_length只有一個片段是實際編碼幀緩衝器的大小和
encoded_image->_size是最大尺寸一個編碼的幀緩衝器。

OpenH264 API提供了用於計算片段的編碼幀中的NALU數量,而API僅使用提供的頭和其大小,而不管幀頭是否實際添加了幀。僅爲頭部大小搜索幀字節允許正確計算碎片。

這樣做最終發送了編碼數據,並在客戶端瀏覽器上正確解碼。