[FFmpeg-trac] #4340(undetermined:new): aac_adtstoasc adds extradata too late for dash muxer

FFmpeg trac at avcodec.org
Sun Mar 1 22:04:22 CET 2015

#4340: aac_adtstoasc adds extradata too late for dash muxer
             Reporter:  oromit       |                     Type:  defect
               Status:  new          |                 Priority:  normal
            Component:               |                  Version:  git-
  undetermined                       |  master
             Keywords:  dash aac     |               Blocked By:
  aac_adtstoasc                      |  Reproduced by developer:  0
             Blocking:               |
Analyzed by developer:  0            |
 Commandline i'm testing with:
 ffmpeg -v debug -i "$(livestreamer --stream-url
 "http://www.twitch.tv/somerandomstream" 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:

 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-
 [dash @ 0x2ebe4c0] Representation 1 init segment will be written to: init-
 (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

 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
 But it could also be the dash muxer beeing initialized too early, before
 the aac bsf could add the extradata.

Ticket URL: <https://trac.ffmpeg.org/ticket/4340>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker

More information about the FFmpeg-trac mailing list