PR #26256 opened by Baptiste Coudurier (bcoudurier) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26256 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26256.patch
Without an edit list, MS and IMA WAV ADPCM in MOV keep a stts covering every coded sample, while the last packet's discard padding was subtracted from mvhd, tkhd and mdhd (6108 vs 4410 for 0.1 s of MS ADPCM). The padding can't be trimmed there, so keep the coded duration. Fragmented output still shortens its last trun sample. Reported by Forgejo_Fairy on https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26095. FATE: `fate-mov-adpcm-ms-no-editlist`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) From ed53ac9fe9ed3bc8e951698194630f382ca0c3a2 Mon Sep 17 00:00:00 2001 From: Baptiste Coudurier <[email protected]> Date: Sat, 21 Nov 2026 12:09:42 -0800 Subject: [PATCH] avformat/movenc: keep the padding of constant size audio without edit lists Its stts counts every coded sample, so the track durations must too. Signed-off-by: Baptiste Coudurier <[email protected]> --- libavformat/movenc.c | 11 ++++++++--- tests/fate/mov.mak | 6 ++++++ tests/ref/fate/mov-adpcm-ms-no-editlist | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/ref/fate/mov-adpcm-ms-no-editlist diff --git a/libavformat/movenc.c b/libavformat/movenc.c index f302a366129..a6a1bb19c8c 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -7631,14 +7631,19 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) sd = av_packet_side_data_get(pkt->side_data, pkt->side_data_elems, AV_PKT_DATA_SKIP_SAMPLES); if (sd && sd->size >= 10 && trk->par->frame_size) { int coded_samples = av_get_audio_frame_duration2(trk->par, pkt->size); + /* Without an edit list, the stts of constant size audio cannot be trimmed */ + int untrimmed = !mov->use_editlist && !trk->audio_vbr && + (!(mov->flags & FF_MOV_FLAG_FRAGMENT) || + mov->flags & FF_MOV_FLAG_HYBRID_FRAGMENTED); if (coded_samples <= 0) coded_samples = trk->par->frame_size; duration = FFMAX(av_rescale_q(coded_samples, (AVRational){ 1, trk->par->sample_rate }, trk->st->time_base), pkt->duration); - if (mov->use_editlist) + if (mov->use_editlist || untrimmed) pkt->duration = duration; - duration -= av_rescale_q(AV_RL32(sd->data + 4), (AVRational){ 1, trk->par->sample_rate }, - trk->st->time_base); + if (!untrimmed) + duration -= av_rescale_q(AV_RL32(sd->data + 4), (AVRational){ 1, trk->par->sample_rate }, + trk->st->time_base); if (duration < 0) return AVERROR_INVALIDDATA; } else diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak index e8972bc3eb6..b6135463c4d 100644 --- a/tests/fate/mov.mak +++ b/tests/fate/mov.mak @@ -416,6 +416,12 @@ FATE_MOV_FFMPEG-$(call TRANSCODE, PCM_S16LE, MOV, WAV_DEMUXER PAN_FILTER) \ fate-mov-channel-description: tests/data/asynth-44100-1.wav tests/data/filtergraphs/mov-channel-description fate-mov-channel-description: CMD = transcode wav $(TARGET_PATH)/tests/data/asynth-44100-1.wav mov "-/filter_complex $(TARGET_PATH)/tests/data/filtergraphs/mov-channel-description -map [outFL] -map [outFR] -map [outFC] -map [outLFE] -map [outBL] -map [outBR] -map [outDL] -map [outDR] -c:a pcm_s16le" "-map 0 -c copy -frames:a 0" +# Without an edit list, the durations include the padding of the last MS ADPCM block +FATE_MOV_FFMPEG_FFPROBE-$(call TRANSCODE, ADPCM_MS, MOV, WAV_DEMUXER) \ + += fate-mov-adpcm-ms-no-editlist +fate-mov-adpcm-ms-no-editlist: tests/data/asynth-44100-1.wav +fate-mov-adpcm-ms-no-editlist: CMD = transcode wav $(TARGET_PATH)/tests/data/asynth-44100-1.wav mov "-c:a adpcm_ms -t 0.1 -use_editlist 0" "-c copy" "-show_entries format=duration:stream=duration_ts,duration" + # Test PCM in mp4 and channel layout FATE_MOV_FFMPEG-$(call TRANSCODE, PCM_S16LE, MP4 MOV, WAV_DEMUXER PAN_FILTER) \ += fate-mov-mp4-pcm diff --git a/tests/ref/fate/mov-adpcm-ms-no-editlist b/tests/ref/fate/mov-adpcm-ms-no-editlist new file mode 100644 index 00000000000..32a35fdc2f2 --- /dev/null +++ b/tests/ref/fate/mov-adpcm-ms-no-editlist @@ -0,0 +1,17 @@ +f918defff16985d8cf59639410bd23a4 *tests/data/fate/mov-adpcm-ms-no-editlist.mov +3767 tests/data/fate/mov-adpcm-ms-no-editlist.mov +#tb 0: 1/44100 +#media_type 0: audio +#codec_id 0: adpcm_ms +#sample_rate 0: 44100 +#channel_layout_name 0: mono +0, 0, 0, 2036, 1024, 0xec640cb3 +0, 2036, 2036, 2036, 1024, 0x9bd304fc +0, 4072, 4072, 2036, 1024, 0x3de16423 +[STREAM] +duration_ts=6108 +duration=0.138503 +[/STREAM] +[FORMAT] +duration=0.138503 +[/FORMAT] -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
