Opened 34 hours ago
Last modified 13 hours ago
#11312 new defect
MP4 Fragmented demuxer: does not respect audio duration from TRUN
Reported by: | Thierry | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avformat |
Version: | git-master | Keywords: | mov |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
While encoding AAC in a FMP4, ffprobe report the 1st and last packet with invalid duration.
For the 1st packet, ffprobe reports N/A
(and not 1024)
For the last packet, ffprobe reports 1024
, while in the trun, the duration is 68
How to reproduce:
Generate a 1 second file using ffmpeg and encode it to AAC at 44.1kHZ
The AAC encoder will add 1024 samples at the beginning. So, we should encode a total of 44100 + 1024 = 45124
samples.
Because AAC frame is 1024 samples, we have
round_up(45124 / 1024) = 45
entries in the trun.
The duration in the last entry in the trun is correct with a value of
45124 - (44 * 1024) = 68 samples
.
However, ffprobe reports a duraiton of 1024, while the duration of the last audio packet should be 68 ticks (at 44.1kHz)
Command line to generate a 1s of audio at 44.1kHz, encoding with native AAC codec and use Dash muxer.
ffmpeg -f lavfi -i "anoisesrc=c=pink:r=44100:a=0.5:d=1" -ac 2 -b:a 128k -movflags dash /tmp/fragment.mp4 ffmpeg version N-117835-g6309c7c974 Copyright (c) 2000-2024 the FFmpeg developers built with gcc 13 (Debian 13.2.0-13) configuration: --enable-nonfree --enable-libx265 --enable-gpl libavutil 59. 47.100 / 59. 47.100 libavcodec 61. 25.100 / 61. 25.100 libavformat 61. 9.100 / 61. 9.100 libavdevice 61. 4.100 / 61. 4.100 libavfilter 10. 6.101 / 10. 6.101 libswscale 8. 9.101 / 8. 9.101 libswresample 5. 4.100 / 5. 4.100 libpostproc 58. 4.100 / 58. 4.100 [out @ 0x56114ca2be80] The "sample_fmts" option is deprecated: set the supported sample formats [out @ 0x56114ca2be80] The "all_channel_counts" option is deprecated: accept all channel counts Input #0, lavfi, from 'anoisesrc=c=pink:r=44100:a=0.5:d=1': Duration: N/A, start: 0.000000, bitrate: 2822 kb/s Stream #0:0: Audio: pcm_f64le, 44100 Hz, mono, dbl, 2822 kb/s File '/tmp/fragment.mp4' already exists. Overwrite? [y/N] y Stream mapping: Stream #0:0 -> #0:0 (pcm_f64le (native) -> aac (native)) Press [q] to stop, [?] for help Output #0, mp4, to '/tmp/fragment.mp4': Metadata: encoder : Lavf61.9.100 Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s Metadata: encoder : Lavc61.25.100 aac [out#0/mp4 @ 0x56114ca31c80] video:0KiB audio:16KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 8.051185% size= 17KiB time=00:00:01.00 bitrate= 141.2kbits/s speed=16.4x [aac @ 0x56114ca2b9c0] Qavg: 1809.483
Output of ffprobe on the file generated.
ffprobe -show_packets -of compact /tmp/fragment.mp4 ffprobe version N-117835-g6309c7c974 Copyright (c) 2007-2024 the FFmpeg developers built with gcc 13 (Debian 13.2.0-13) configuration: --enable-nonfree --enable-libx265 --enable-gpl libavutil 59. 47.100 / 59. 47.100 libavcodec 61. 25.100 / 61. 25.100 libavformat 61. 9.100 / 61. 9.100 libavdevice 61. 4.100 / 61. 4.100 libavfilter 10. 6.101 / 10. 6.101 libswscale 8. 9.101 / 8. 9.101 libswresample 5. 4.100 / 5. 4.100 libpostproc 58. 4.100 / 58. 4.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/fragment.mp4': Metadata: major_brand : iso5 minor_version : 512 compatible_brands: iso5iso6mp41 encoder : Lavf61.9.100 Duration: 00:00:01.02, start: 0.000000, bitrate: 137 kb/s Stream #0:0[0x1](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default) Metadata: handler_name : SoundHandler vendor_id : [0][0][0][0] packet|codec_type=audio|stream_index=0|pts=0|pts_time=0.000000|dts=0|dts_time=0.000000|duration=N/A|duration_time=N/A|size=315|pos=1248|flags=K__ packet|codec_type=audio|stream_index=0|pts=1024|pts_time=0.023220|dts=1024|dts_time=0.023220|duration=1024|duration_time=0.023220|size=381|pos=1563|flags=K__ packet|codec_type=audio|stream_index=0|pts=2048|pts_time=0.046440|dts=2048|dts_time=0.046440|duration=1024|duration_time=0.023220|size=362|pos=1944|flags=K__ packet|codec_type=audio|stream_index=0|pts=3072|pts_time=0.069660|dts=3072|dts_time=0.069660|duration=1024|duration_time=0.023220|size=371|pos=2306|flags=K__ packet|codec_type=audio|stream_index=0|pts=4096|pts_time=0.092880|dts=4096|dts_time=0.092880|duration=1024|duration_time=0.023220|size=383|pos=2677|flags=K__ packet|codec_type=audio|stream_index=0|pts=5120|pts_time=0.116100|dts=5120|dts_time=0.116100|duration=1024|duration_time=0.023220|size=364|pos=3060|flags=K__ packet|codec_type=audio|stream_index=0|pts=6144|pts_time=0.139320|dts=6144|dts_time=0.139320|duration=1024|duration_time=0.023220|size=380|pos=3424|flags=K__ packet|codec_type=audio|stream_index=0|pts=7168|pts_time=0.162540|dts=7168|dts_time=0.162540|duration=1024|duration_time=0.023220|size=382|pos=3804|flags=K__ packet|codec_type=audio|stream_index=0|pts=8192|pts_time=0.185760|dts=8192|dts_time=0.185760|duration=1024|duration_time=0.023220|size=356|pos=4186|flags=K__ packet|codec_type=audio|stream_index=0|pts=9216|pts_time=0.208980|dts=9216|dts_time=0.208980|duration=1024|duration_time=0.023220|size=384|pos=4542|flags=K__ packet|codec_type=audio|stream_index=0|pts=10240|pts_time=0.232200|dts=10240|dts_time=0.232200|duration=1024|duration_time=0.023220|size=367|pos=4926|flags=K__ packet|codec_type=audio|stream_index=0|pts=11264|pts_time=0.255420|dts=11264|dts_time=0.255420|duration=1024|duration_time=0.023220|size=362|pos=5293|flags=K__ packet|codec_type=audio|stream_index=0|pts=12288|pts_time=0.278639|dts=12288|dts_time=0.278639|duration=1024|duration_time=0.023220|size=387|pos=5655|flags=K__ packet|codec_type=audio|stream_index=0|pts=13312|pts_time=0.301859|dts=13312|dts_time=0.301859|duration=1024|duration_time=0.023220|size=374|pos=6042|flags=K__ packet|codec_type=audio|stream_index=0|pts=14336|pts_time=0.325079|dts=14336|dts_time=0.325079|duration=1024|duration_time=0.023220|size=366|pos=6416|flags=K__ packet|codec_type=audio|stream_index=0|pts=15360|pts_time=0.348299|dts=15360|dts_time=0.348299|duration=1024|duration_time=0.023220|size=371|pos=6782|flags=K__ packet|codec_type=audio|stream_index=0|pts=16384|pts_time=0.371519|dts=16384|dts_time=0.371519|duration=1024|duration_time=0.023220|size=370|pos=7153|flags=K__ packet|codec_type=audio|stream_index=0|pts=17408|pts_time=0.394739|dts=17408|dts_time=0.394739|duration=1024|duration_time=0.023220|size=368|pos=7523|flags=K__ packet|codec_type=audio|stream_index=0|pts=18432|pts_time=0.417959|dts=18432|dts_time=0.417959|duration=1024|duration_time=0.023220|size=379|pos=7891|flags=K__ packet|codec_type=audio|stream_index=0|pts=19456|pts_time=0.441179|dts=19456|dts_time=0.441179|duration=1024|duration_time=0.023220|size=376|pos=8270|flags=K__ packet|codec_type=audio|stream_index=0|pts=20480|pts_time=0.464399|dts=20480|dts_time=0.464399|duration=1024|duration_time=0.023220|size=341|pos=8646|flags=K__ packet|codec_type=audio|stream_index=0|pts=21504|pts_time=0.487619|dts=21504|dts_time=0.487619|duration=1024|duration_time=0.023220|size=386|pos=8987|flags=K__ packet|codec_type=audio|stream_index=0|pts=22528|pts_time=0.510839|dts=22528|dts_time=0.510839|duration=1024|duration_time=0.023220|size=381|pos=9373|flags=K__ packet|codec_type=audio|stream_index=0|pts=23552|pts_time=0.534059|dts=23552|dts_time=0.534059|duration=1024|duration_time=0.023220|size=361|pos=9754|flags=K__ packet|codec_type=audio|stream_index=0|pts=24576|pts_time=0.557279|dts=24576|dts_time=0.557279|duration=1024|duration_time=0.023220|size=389|pos=10115|flags=K__ packet|codec_type=audio|stream_index=0|pts=25600|pts_time=0.580499|dts=25600|dts_time=0.580499|duration=1024|duration_time=0.023220|size=364|pos=10504|flags=K__ packet|codec_type=audio|stream_index=0|pts=26624|pts_time=0.603719|dts=26624|dts_time=0.603719|duration=1024|duration_time=0.023220|size=382|pos=10868|flags=K__ packet|codec_type=audio|stream_index=0|pts=27648|pts_time=0.626939|dts=27648|dts_time=0.626939|duration=1024|duration_time=0.023220|size=368|pos=11250|flags=K__ packet|codec_type=audio|stream_index=0|pts=28672|pts_time=0.650159|dts=28672|dts_time=0.650159|duration=1024|duration_time=0.023220|size=362|pos=11618|flags=K__ packet|codec_type=audio|stream_index=0|pts=29696|pts_time=0.673379|dts=29696|dts_time=0.673379|duration=1024|duration_time=0.023220|size=382|pos=11980|flags=K__ packet|codec_type=audio|stream_index=0|pts=30720|pts_time=0.696599|dts=30720|dts_time=0.696599|duration=1024|duration_time=0.023220|size=372|pos=12362|flags=K__ packet|codec_type=audio|stream_index=0|pts=31744|pts_time=0.719819|dts=31744|dts_time=0.719819|duration=1024|duration_time=0.023220|size=380|pos=12734|flags=K__ packet|codec_type=audio|stream_index=0|pts=32768|pts_time=0.743039|dts=32768|dts_time=0.743039|duration=1024|duration_time=0.023220|size=378|pos=13114|flags=K__ packet|codec_type=audio|stream_index=0|pts=33792|pts_time=0.766259|dts=33792|dts_time=0.766259|duration=1024|duration_time=0.023220|size=369|pos=13492|flags=K__ packet|codec_type=audio|stream_index=0|pts=34816|pts_time=0.789478|dts=34816|dts_time=0.789478|duration=1024|duration_time=0.023220|size=366|pos=13861|flags=K__ packet|codec_type=audio|stream_index=0|pts=35840|pts_time=0.812698|dts=35840|dts_time=0.812698|duration=1024|duration_time=0.023220|size=377|pos=14227|flags=K__ packet|codec_type=audio|stream_index=0|pts=36864|pts_time=0.835918|dts=36864|dts_time=0.835918|duration=1024|duration_time=0.023220|size=369|pos=14604|flags=K__ packet|codec_type=audio|stream_index=0|pts=37888|pts_time=0.859138|dts=37888|dts_time=0.859138|duration=1024|duration_time=0.023220|size=358|pos=14973|flags=K__ packet|codec_type=audio|stream_index=0|pts=38912|pts_time=0.882358|dts=38912|dts_time=0.882358|duration=1024|duration_time=0.023220|size=382|pos=15331|flags=K__ packet|codec_type=audio|stream_index=0|pts=39936|pts_time=0.905578|dts=39936|dts_time=0.905578|duration=1024|duration_time=0.023220|size=370|pos=15713|flags=K__ packet|codec_type=audio|stream_index=0|pts=40960|pts_time=0.928798|dts=40960|dts_time=0.928798|duration=1024|duration_time=0.023220|size=376|pos=16083|flags=K__ packet|codec_type=audio|stream_index=0|pts=41984|pts_time=0.952018|dts=41984|dts_time=0.952018|duration=1024|duration_time=0.023220|size=371|pos=16459|flags=K__ packet|codec_type=audio|stream_index=0|pts=43008|pts_time=0.975238|dts=43008|dts_time=0.975238|duration=1024|duration_time=0.023220|size=374|pos=16830|flags=K__ packet|codec_type=audio|stream_index=0|pts=44032|pts_time=0.998458|dts=44032|dts_time=0.998458|duration=1024|duration_time=0.023220|size=368|pos=17204|flags=K__ packet|codec_type=audio|stream_index=0|pts=45056|pts_time=1.021678|dts=45056|dts_time=1.021678|duration=1024|duration_time=0.023220|size=7|pos=17572|flags=K__
Please see attached a patch which seems to be working for us.
Attachments (1)
Change History (3)
by , 34 hours ago
Attachment: | 0001-libavformat-mov.c-update-the-audio-packet-duration-b.patch added |
---|
comment:1 by , 26 hours ago
Would be nice to apply edit list media duration and not only media time, yep.
comment:2 by , 13 hours ago
Can you comment whether we should apply this too: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20190429225027.81295-1-fumoboy007@me.com/
Patch which seems to fix the issue