简体   繁体   中英

ffmpeg: How to convert AAC audio packets to ADTS format

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.

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 ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM