2

According to Need to convert h264 stream from annex-b format to AVCC format:

AnnexB format:

([start code] NALU) | ( [start code] NALU) |

AVCC format:

([extradata]) | ([length] NALU) | ([length] NALU) |

Currently you can parse a bitstream (AnnexB format) using av_parser_parse2 and then pass this buffer to avcodec_send_frame, but what about AVCC format? Is there a parser for it?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • See: https://stackoverflow.com/questions/33550420/is-the-values-in-avcc-box-in-mp4-video-files-affected-only-by-ffmpeg-version and follow the link in the answer for more info. I never heard of AVCC but it looks like it's an alternative way to store meta info other than annex B in H.264 rather than a completely different format??? And `ffmpeg` can handle it – Craig Estey Aug 22 '21 at 02:42

1 Answers1

0

Yes, it's possible.

You will need to pass the content of the avcC box to AVCodecContext::extradata which will be parsed by the decoder to get the PPS and SPS NALUs necessary for decoding.

Here's an example of how to do that:

// `avcC` box retrieved from an MP4
char avcC[] = "...";

// Create codec parameters and copy the avcC box as extradata
codec_params = avcodec_parameters_alloc();
memcpy(codec_params.extradata, &avcC, sizeof(avcC));
codec_params.extradata_size = sizeof(avcC);

// Create the codec context and initialize it with codec parameters
codec_context = avcodec_alloc_context3();
avcodec_parameters_to_context(codec_context, codec_params);

// Create the codec and initialize it
codec = avcodec_find_decoder(AV_CODEC_ID_H264);
avcodec_open2(codec_context, codec, NULL);

The AVCC format assumes that PPS and SPS NALUs are provided "out of band", meaning they are not part of the stream like in the Annex B format. This excellent SO answer gives more details about the differences.

In an MP4 container, these NALUs are located in the avcC box, located at the following path in the MP4 box hierarchy:

moov > trak > mdia > minf > stbl > stsd > avc1 > avcC
ngryman
  • 7,112
  • 2
  • 26
  • 23