[FFmpeg-user] MP4 -> ADTS Headers

Ronak ronak2121 at yahoo.com
Fri Oct 4 00:25:50 EEST 2019


> On Oct 3, 2019, at 12:48 AM, Ronak via ffmpeg-user <ffmpeg-user at ffmpeg.org> wrote:
> 
> Hi,
> 
> I’m writing a C++ program to validate the integrity of a Fragmented MP4 file containing AAC audio.
> This program would parse the FMP4 file, read each audio packet, attachment ADTS headers, and then try to decode the AAC using libfdk_aac.
> 
> I am using libavformat, and I am able to parse the MP4 atoms correctly, however I’m having issues figuring out the best way to attach the ADTS headers.
> 
> The best sample I was able to find was:
> 
> https://patchwork.ffmpeg.org/patch/3184/ <https://patchwork.ffmpeg.org/patch/3184/>
> 
> Is there a better example for me to use?
> 


Hi,

So I managed to figure out how to do this, and I’m up to the part of figuring out what I need to write in the extradata field of the AVCodecParameters here:

// create another context used to append ADTS headers to the parsed segments, if we need them
bool isBufferWritable = true;
avformat_alloc_output_context2(&this->adtsMuxerContext, NULL, "adts", NULL);
this->adtsMuxerWriterContext = avio_alloc_context(this->adtsPacketBuffer, this->adtsPacketBufferSize, isBufferWritable, this, NULL, AudioAssetReader::writeADTSPacket, NULL);
this->adtsMuxerContext->pb = this->adtsMuxerWriterContext;

// initialize an ADTS stream
AVCodecID aacCodec = AVCodecID::AV_CODEC_ID_AAC;
AVCodec *codec = avcodec_find_encoder(aacCodec);
AVStream *stream = avformat_new_stream(this->adtsMuxerContext, codec);
stream->id = this->adtsMuxerContext->nb_streams - 1;
stream->time_base.den = input.getSampleRateHz();
stream->time_base.num = 1;

// configure the stream with the details of the AAC packets
AVCodecParameters *codecParameters = stream->codecpar;
codecParameters->codec_id = aacCodec;
codecParameters->bit_rate = input.getBitrateBps();
codecParameters->profile = this->getAACProfileForCodec(input.getCodec());
codecParameters->sample_rate = input.getSampleRateHz();
codecParameters->channels = input.getChannelCount();
codecParameters->codec_type = AVMEDIA_TYPE_AUDIO;
codecParameters->channel_layout = av_get_default_channel_layout(input.getChannelCount());
codecParameters->extradata = new uint8_t[AV_INPUT_BUFFER_PADDING_SIZE + 2];
codecParameters->extradata_size = 2;
memset(codecParameters->extradata, 2, AV_INPUT_BUFFER_PADDING_SIZE + 2);

But this is still not working with errors about: [adts @ 0x7f87c4803a00] MPEG-4 AOT 0 is not allowed in ADTS


Reading the code in FFmpeg, it looks like I need to send in a full fledged ADTS header into extradata is that correct?

> Ronak
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
> 
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-user mailing list