1

I am trying to write a C program that demuxes audio from an MP4 file and write demuxed AVPacket data to a file. But the resulting dump is missing ADTS headers. Any pointers on what is the best way to add ADTS headers.

I see that ffmpeg has 'adtsenc.c' file that seems to implement an ADTS muxer:

AVOutputFormat ff_adts_muxer = {
    .name              = "adts",
    .long_name         = NULL_IF_CONFIG_SMALL("ADTS AAC (Advanced Audio Coding)"),
    .mime_type         = "audio/aac",
    .extensions        = "aac,adts",
    .priv_data_size    = sizeof(ADTSContext),
    .audio_codec       = AV_CODEC_ID_AAC,
    .video_codec       = AV_CODEC_ID_NONE,
    .write_header      = adts_write_header,
    .write_packet      = adts_write_packet,
    .write_trailer     = adts_write_trailer,
    .priv_class        = &adts_muxer_class,
    .flags             = AVFMT_NOTIMESTAMPS,
};

Best wishes.

blackgreen
  • 34,072
  • 23
  • 111
  • 129
Malik
  • 87
  • 3
  • 11
  • mp4 files don't usually contain ADTS headers, as they [would be redundant](https://en.wikipedia.org/wiki/Advanced_Audio_Coding#Container_formats). If you save data as 'naked' aac files however, FFmpeg will add ADTS headers. – AkselA Jan 13 '17 at 11:46
  • Thanks AkselA for your comment. I think you are pointing me to the right direction. Could you give me some idea what I need to do to save data as 'naked' aac file? I really appreciate help on this. – Malik Jan 14 '17 at 17:09

1 Answers1

1

Update: I know that command line demuxing achieves putting ADTS headers when you try:

ffmpeg -i input.mp4 -acodec copy -vn output.aac

I checked that this process IS using adts.c i.e. ADTS muxer to achieve this by calling:

adts_write_header()
adts_write_packet()
adts_write_packet()
.....
adts_write_trailer()

I need to figure out how to use it in my program. I will post an update when if I figure it out.

Malik
  • 87
  • 3
  • 11
  • I ended up extracting code from adtsenc.c and modifying to suit my situation. If anyone needs the code, please let me know. – Malik Feb 03 '17 at 19:30
  • Very interesting Malik, I have the same problem. Since you offered the code, could you send it to me or post it somewhere? Thank you very much! – Jonatan Ienco Nov 19 '19 at 12:37