openh264 icon indicating copy to clipboard operation
openh264 copied to clipboard

Get the H264 stream in AVCC format insted of Annex B format

Open tino197 opened this issue 12 years ago • 4 comments

Seems that the code in console application below encode the h264 to the file in Annex B format ( 0x00 0x00 0x00 0x01 ...) I need the stream to be in AVCC format. Is there an option to tell the openh264 lib to create the stream in AVCC format? If the lib only output Annex then do you have some code that can help me convert the stream to AVCC? Here is the code that encode and save the stream (in Annex B format): long iEncode = poDecoder->EncodeFrame(oSSourcePicture, &oSFrameBSInfo); while (iLayer < oSFrameBSInfo.iLayerNum) { SLayerBSInfo* pLayerBsInfo = &oSFrameBSInfo.sLayerInfo[iLayer]; int iNalIdx = pLayerBsInfo->iNalCount - 1; do { iLayerSize += pLayerBsInfo->iNalLengthInByte[iNalIdx];--iNalIdx; } while (iNalIdx >= 0); fwrite(pLayerBsInfo->pBsBuf, 1, iLayerSize, pFpBs); // write pure bit stream into file }++iLayer;

tino197 avatar Apr 29 '14 19:04 tino197

No, it does not support C format. Hope somebody can help you about the conversion.

huili2 avatar Apr 30 '14 03:04 huili2

I am not sure if codec level should provide AVCC format. AVCC is often defined in the media container. I prefer to convert annex B bitstream to AVCC at media container muxer, not codec level

volvet avatar Apr 30 '14 07:04 volvet

In that case hope someone will help me with the conversion. I tried this to convert from annex-b to AVCC: I extracted the SPS and PPS from the annex stream and created the Extra data. I then looked in the stream for 0x00 0x00 0x00 0x01 (which should be the start of each Nal) and continue looking for another 0x00 0x00 0x00 0x01 (which will be the end of the Nal) then did minus to get the Nal length, then replace the first 0x00 0x00 0x00 0x01 to 0x00 0x00 0x00 [NulSize] but seems that this does not produce valid stream. I then found out that NUL can starts/ends with 0x00 0x00 0x01 so i am little confused.

anyway, I hope someone will be able to write me function that convert from annex-b to AVCC.

Thanks.

tino197 avatar Apr 30 '14 19:04 tino197

You can find code sample at open source community, like FFMPEG. www.ffmpeg.org.

volvet avatar May 04 '14 00:05 volvet