Custom H264 encoder -> packetization

241 views
Skip to first unread message

Lander Noterman

unread,
Sep 19, 2018, 10:09:14 AM9/19/18
to discuss-webrtc
I have replaced OpenH264 with a hardware encoder.
I have confirmed (by writing the encoded_images_[i]->buffer to a file) that my custom encoder (using ffmpeg) produces H264 frames.
However, it still does not start playing in Chrome.

I suspect two related problems are interfering with the correct functioning of the code:
1) The frames produced by my encoder are too large, resulting in the error: (rtp_format_h264.cc:307): Failed to fit a fragment to packet in SingleNalu packetization mode. Payload size left 1174, fragment length 7693, packet capacity 1178
2) I am still not sure how to set the frag_header correctly. At the moment, I determined that the encoder produces two types of frames: frames with 2 NAL units and frames with 1 NAL unit. Temporarily, I have hardcoded the frag_header like this:
if (info.iFrameSizeInBytes > 18 && info.sLayerInfo[0].pBsBuf[18] == 0 &&
info.sLayerInfo[0].pBsBuf[19] == 0 &&
info.sLayerInfo[0].pBsBuf[20] == 0 &&
info.sLayerInfo[0].pBsBuf[21] == 1) {
frag_header.VerifyAndAllocateFragmentationHeader(2);
frag_header.fragmentationOffset[0] = 4;
frag_header.fragmentationLength[0] = 14;
frag_header.fragmentationOffset[1] = 18;
frag_header.fragmentationLength[1] = info.iFrameSizeInBytes - 18;
} else {
frag_header.VerifyAndAllocateFragmentationHeader(1);
frag_header.fragmentationOffset[0] = 4;
frag_header.fragmentationLength[0] = info.iFrameSizeInBytes - 4;
}

I have tried setting the packetization mode to H264PacketizationMode::NonInterleaved instead of H264PacketizationMode::SingleNalUnit, but this didn't seem to make a difference.

Can someone offer me some insight into how I might fix this?

ssi...@google.com

unread,
Sep 21, 2018, 3:33:56 AM9/21/18
to discuss-webrtc
::SinleNalUnit requires length of slice to be <= MTU. If your encoder doesn't allow you to set maximum length of slice than you should use ::NonInterleaved.

What sort of error do you get when using ::NonInterleaved?
Reply all
Reply to author
Forward
0 new messages