Opened 5 years ago

Closed 5 years ago

#4340 closed defect (fixed)

aac_adtstoasc adds extradata too late for dash muxer

Reported by: oromit Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: dash aac aac_adtstoasc
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Commandline i'm testing with:

ffmpeg -v debug -i "$(livestreamer --stream-url "" best)" -bsf:a aac_adtstoasc -c copy -f dash stream.mpd

Twitch is using HLS with h264 and aac, basicaly every input that makes the mp4 muxer hard-request the aac_adtstoasc filter will reproduce the issue.

This results in the dash mpd containing the following codec for the audio stream: mp4a.40
As far as i'm aware, that's not a valid codec for aac, it should be: mp4a.40.2

After looking into why it's missing the final .2, when reading the dashenc.c file, i found that it extracts that value from the codec extradata(See line 137 in libavformat/dashenc.c).

This extradata should be added by the aac_adtstoasc bitstream filter. I added some debug outputs, to see in which order stuff is happening, and i found this:

[dash @ 0x2ebe4c0] Representation 0 init segment will be written to: init-stream0.m4s
[dash @ 0x2ebe4c0] Representation 1 init segment will be written to: init-stream1.m4s
(I added this one) [dash @ 0x2ebe4c0] Generating tag-data for mp4a
(this one) [dash @ 0x2ebe4c0] extradata NOT big enough: 0
[AVIOContext @ 0x2fb5560] Statistics: 0 seeks, 1 writeouts
[dash @ 0x2ebe4c0] Manifest written to: stream.mpd
Output #0, dash, to 'stream.mpd':
    encoder         : Lavf56.23.106
    Stream #0:0, 0, 1/12800: Video: h264 ([33][0][0][0] / 0x0021), yuv420p(left), 1920x1080 (0x0), 1/25, q=2-31, 25 fps, 25 tbr, 12800 tbn, 25 tbc
    Stream #0:1, 0, 1/44100: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 210 kb/s
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
  Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
(this one) [NULL @ 0x2ed7640] In AAC ADTS Bitstream filter function!
(and this one) [NULL @ 0x2ed7640] Generated AAC extradata with size of 2

So the dash dash_write_header function is called before the aac bitstream filter was able to do its job of adding the extradata, and as it only calculates the codec information once, it is now stuck with a wrong codec string.

I'm not sure where the problem is located here. It could be the dash muxer, which does not check for the extradata existing/changing at a later point.
But it could also be the dash muxer beeing initialized too early, before the aac bsf could add the extradata.

Change History (1)

comment:1 Changed 5 years ago by oromit

  • Component changed from undetermined to avformat
  • Resolution set to fixed
  • Status changed from new to closed

Fixed in master

Note: See TracTickets for help on using tickets.