Opened 11 months ago

Last modified 11 months ago

#10422 new defect

Concatenating raw AAC files directly into MP4 using concat demuxer has wrong duration

Reported by: fireattack Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

I often manually concat segments downloaded from HTTP live streaming (HLS) locally.

I noticed that if you do so with audio-only raw AAC (ADTS) segments using concat demuxer, and directly into mp4 container, the output will have wrong duration.

ffmpeg -f concat -safe 0 -i chunkindex.txt -c copy 01_directly_concat.m4a -y

it will generate a file that has wrong (usually longer) duration in its metadata.

The following ways will all generate correct file instead:

ffmpeg -i input.m3u8 -c copy 02_from_m3u8.m4a -y

copy /b 24b4547ddc1a4f528422970016d82c29\*.aac copyb.aac
ffmpeg -i copyb.aac -c copy 03_copyb.m4a -y
del copyb.aac

ffmpeg -f concat -safe 0 -i chunkindex.txt -c copy -f adts - | ffmpeg -i - -c copy 04_adts_to_m4a.m4a -y

How to reproduce:

(Removed all the "Estimating duration from bitrate, this may be inaccurate" to save space)

>ffmpeg -f concat -safe 0 -i chunkindex.txt -c copy 01_directly_concat.m4a -y > output_1.txt 2>&1

ffmpeg version 6.0-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      58.  2.100 / 58.  2.100
  libavcodec     60.  3.100 / 60.  3.100
  libavformat    60.  3.100 / 60.  3.100
  libavdevice    60.  1.100 / 60.  1.100
  libavfilter     9.  3.100 /  9.  3.100
  libswscale      7.  1.100 /  7.  1.100
  libswresample   4. 10.100 /  4. 10.100
  libpostproc    57.  1.100 / 57.  1.100
[aac @ 00000175883e44c0] Format aac detected only with low score of 25, misdetection possible!
[aac @ 00000175883e44c0] Estimating duration from bitrate, this may be inaccurate (lots of this, removed for clarity)
Input #0, concat, from 'chunkindex.txt':
  Duration: N/A, start: 0.000000, bitrate: 99 kb/s
  Stream #0:0: Audio: aac (LC), 48000 Hz, stereo, fltp, 99 kb/s
Output #0, ipod, to '01_directly_concat.m4a':
  Metadata:
    encoder         : Lavf60.3.100
  Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 99 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=       0kB time=00:00:00.00 bitrate=N/A speed=N/A    
[ipod @ 00000175883f1740] Non-monotonous DTS in output stream 0:0; previous: 3532404, current: 3531602; changing to 3532405. This may result in incorrect timestamps in the output file.
[ipod @ 00000175883f1740] Non-monotonous DTS in output stream 0:0; previous: 47332408, current: 47331976; changing to 47332409. This may result in incorrect timestamps in the output file.
size=   14080kB time=00:21:05.63 bitrate=  91.1kbits/s speed=2.53e+03x    
[ipod @ 00000175883f1740] Non-monotonous DTS in output stream 0:0; previous: 119049597, current: 119048794; changing to 119049598. This may result in incorrect timestamps in the output file.
size=   28928kB time=00:43:12.98 bitrate=  91.4kbits/s speed=2.59e+03x    
[ipod @ 00000175883f1740] Non-monotonous DTS in output stream 0:0; previous: 127887966, current: 127887839; changing to 127887967. This may result in incorrect timestamps in the output file.
[ipod @ 00000175883f1740] Non-monotonous DTS in output stream 0:0; previous: 184912256, current: 184910425; changing to 184912257. This may result in incorrect timestamps in the output file.
[ipod @ 00000175883f1740] Non-monotonous DTS in output stream 0:0; previous: 184912257, current: 184911449; changing to 184912258. This may result in incorrect timestamps in the output file.
[ipod @ 00000175883f1740] Non-monotonous DTS in output stream 0:0; previous: 186374370, current: 186373812; changing to 186374371. This may result in incorrect timestamps in the output file.
size=   44288kB time=01:06:02.61 bitrate=  91.6kbits/s speed=2.64e+03x    
size=   57088kB time=01:25:18.57 bitrate=  91.4kbits/s speed=2.56e+03x    
[ipod @ 00000175883f1740] Non-monotonous DTS in output stream 0:0; previous: 249295288, current: 249294951; changing to 249295289. This may result in incorrect timestamps in the output file.
size=   65236kB time=01:35:41.53 bitrate=  93.1kbits/s speed=2.47e+03x    
video:0kB audio:65976kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Change History (1)

comment:1 by fireattack, 11 months ago

An example set of files is provided here: https://1drv.ms/u/s!Akq11jtCTJYwhLBU4bGabrXo8mqjDA?e=lOeK7E

Note: See TracTickets for help on using tickets.