[FFmpeg-user] Preserving AAC LC status when converting to fragmented MP4

Tobias Rapp t.rapp at noa-archive.com
Tue May 25 10:53:52 EEST 2021


On 24.05.2021 22:26, Moritz Barsnick wrote:
> On Wed, May 19, 2021 at 12:17:38 +0200, Tobias Rapp wrote:
>> Looks like the data that should be found in the "esds" atom is missing or
>> incomplete when using -c:a copy. See this link for details on how AAC
>> profile information is stored in MP4:
>>
>> https://stackoverflow.com/questions/3987850/mp4-atom-how-to-discriminate-the-audio-codec-is-it-aac-or-mp3
> 
> Interesting stuff.
> 
>> Don't know enough about TS (de)muxing, though, to find out where this
>> profile data should be parsed out from the input by FFmpeg.
> 
> MPEG-TS and demuxing isn't the problem. If you look at the ffmpeg
> output in the original e-mail from decoding the file, it correctly
> identifies the codec as "aac (LC)". The issue is the encoding to MP4.
> 
> The reason is that the AAC variants have only one codec tag
> AV_CODEC_ID_AAC, and that needs to map to various tags, e.g. 0x40 for
> AAC and 0x67 for AAC LC.
> 
> https://github.com/FFmpeg/FFmpeg/blob/3749eede66c3774799766b1f246afae8a6ffc9bb/libavformat/isom.c#L34
> 
> When writing the tag in the esds atom, there's no additional info
> available allowing mapping to 0x67, therefore 0x40 is written:
> 
> https://github.com/FFmpeg/FFmpeg/blob/3749eede66c3774799766b1f246afae8a6ffc9bb/libavformat/movenc.c#L711
> 
> I have no idea how this info could be carried forward.
 From the StackOverflow answers the AAC profile seems to be part of the 
AudioSpecificConfig (ASC) part which is written as "TAG 5" within the 
Elementary Stream Descriptor MP4 atom.

Looking at the FFmpeg movenc.c link you posted it is written some lines 
below the codec id from track->vos_data. This pointer is filled from 
AVCodecParameters->extradata in ff_mov_write_packet:

https://github.com/FFmpeg/FFmpeg/blob/3749eede66c3774799766b1f246afae8a6ffc9bb/libavformat/movenc.c#L5586

So it seems to be a matter of TS demuxing passing along the codec 
extradata correctly.

Regards,
Tobias



More information about the ffmpeg-user mailing list