Commit ab10be3a88 for ffmpeg

commit ab10be3a889c8761737f7351a5a140b7f3082b67
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date:   Fri Nov 27 10:29:12 2026 -0600

    tests/fate: add tests for the end trim of audio

    Without an edit list, the end of an audio track in MP4 is trimmed by
    shortening the duration of its last sample. The demuxer does not
    discard the trimmed samples for:

    - Opus, last packet shortened from 960 to 168 samples, also when
      encrypted
    - DTS, from 512 to 496
    - IMA ADPCM, from 64 to 48
    - Vorbis, from 1024 to 1008

    Two Opus samples on a 1 kHz track clock have 120-sample packets: one
    with a full last packet whose duration rounds below its length, one
    with the last packet shortened to a single tick. A third, on a 32 kHz
    clock, has a full last packet shortened by one tick, which is not
    trimmed.

    An IMA ADPCM sample on a 1 kHz clock has three full blocks whose
    durations round to 1, 2 and 1 ticks, which are not trimmed either.

diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 3e65bf6ab0..056e3e5ed7 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -225,6 +225,44 @@ fate-mov-t35-cdsc-track: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries str

 fate-mov-t35-rndr-track: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries stream_group=index,id,nb_streams,type:stream_group_stream=index,id,codec_name,codec_type,codec_tag_string,extradata_size $(TARGET_SAMPLES)/mov/mov-t35-rndr-track.mp4

+# Without an edit list, the end of an Opus stream is trimmed by shortening the
+# last sample, here from 960 to 168.
+FATE_MOV_FFMPEG-$(call REMUX, MP4 MOV, OPUS_ENCODER LAVFI_INDEV PCM_U8_DECODER ANULLSRC_FILTER ARESAMPLE_FILTER) += fate-mov-mp4-opus-trim
+fate-mov-mp4-opus-trim: CMD = transcode lavfi "anullsrc=r=48000:cl=stereo:d=0.021" mp4 "-auto_conversion_filters -c:a opus -strict -2 -use_editlist 0" "-c copy"
+
+# Decrypt and check the trim, then probe without a key and check that
+# ciphertext does not produce discard padding.
+FATE_MOV_FFMPEG_FFPROBE-$(call REMUX, MP4 MOV, OPUS_ENCODER LAVFI_INDEV PCM_U8_DECODER ANULLSRC_FILTER ARESAMPLE_FILTER) += fate-mov-mp4-opus-cenc-trim
+fate-mov-mp4-opus-cenc-trim: CMD = transcode lavfi "anullsrc=r=48000:cl=stereo:d=0.021" mp4 "-auto_conversion_filters -c:a opus -strict -2 -use_editlist 0 -encryption_scheme cenc-aes-ctr -encryption_key 00112233445566778899aabbccddeeff -encryption_kid 00112233445566778899aabbccddeeff" "-c copy" \
+  "-nofind_stream_info -show_entries packet=duration:packet_side_data=side_data_type,discard_padding -of compact" "" "-decryption_key 00112233445566778899aabbccddeeff"
+
+# Same trim for DTS, whose 512-sample last frame is shortened to 496.
+FATE_MOV_FFMPEG-$(call REMUX, MP4 MOV, DCA_ENCODER LAVFI_INDEV PCM_U8_DECODER ANULLSRC_FILTER ARESAMPLE_FILTER) += fate-mov-mp4-dts-trim
+fate-mov-mp4-dts-trim: CMD = transcode lavfi "anullsrc=r=48000:cl=mono:d=0.021" mp4 "-auto_conversion_filters -c:a dca -strict -2 -use_editlist 0" "-c copy"
+
+# Same trim for IMA ADPCM, whose 64-sample last frame is shortened to 48.
+FATE_MOV_FFMPEG-$(call REMUX, MOV, ADPCM_IMA_QT_ENCODER LAVFI_INDEV PCM_U8_DECODER ANULLSRC_FILTER ARESAMPLE_FILTER) += fate-mov-adpcm-ima-qt-trim
+fate-mov-adpcm-ima-qt-trim: CMD = transcode lavfi "anullsrc=r=48000:cl=mono:d=0.021" mov "-auto_conversion_filters -c:a adpcm_ima_qt -use_editlist 0" "-c copy"
+
+# Same trim for Vorbis, whose last 1024-sample packet is shortened to 1008.
+FATE_MOV_FFMPEG-$(call REMUX, MP4 MOV, VORBIS_ENCODER LAVFI_INDEV PCM_U8_DECODER ANULLSRC_FILTER ARESAMPLE_FILTER) += fate-mov-mp4-vorbis-trim
+fate-mov-mp4-vorbis-trim: CMD = transcode lavfi "anullsrc=r=48000:cl=stereo:d=0.021" mp4 "-auto_conversion_filters -c:a vorbis -strict -2 -use_editlist 0" "-c copy"
+
+# Opus on a 1 kHz track clock: a full 120-sample last packet rounds to 2 ticks
+# and must not be trimmed, a last packet shortened to 1 tick must be.
+# On a 32 kHz clock, a full 960-sample last packet shortened from 640 ticks to
+# 639 must be trimmed.
+# Three full 64-sample IMA ADPCM blocks at 48 kHz on a 1 kHz clock, with
+# durations rounded to 1, 2 and 1 ticks, must not be trimmed.
+FATE_MOV_FFMPEG_SAMPLES-$(call DEMMUX, MOV, FRAMECRC, PIPE_PROTOCOL) += fate-mov-opus-timescale1000-full \
+                                                                      fate-mov-opus-timescale1000-trim \
+                                                                      fate-mov-opus-timescale32000-trim \
+                                                                      fate-mov-ima-timescale1000-full
+fate-mov-opus-timescale1000-full: CMD = framecrc -i $(TARGET_SAMPLES)/mov/opus-timescale1000-full.mp4 -c copy
+fate-mov-opus-timescale1000-trim: CMD = framecrc -i $(TARGET_SAMPLES)/mov/opus-timescale1000-trim.mp4 -c copy
+fate-mov-opus-timescale32000-trim: CMD = framecrc -i $(TARGET_SAMPLES)/mov/opus-timescale32000-trim.mp4 -c copy
+fate-mov-ima-timescale1000-full: CMD = framecrc -i $(TARGET_SAMPLES)/mov/ima-timescale1000-full.mov -c copy
+
 FATE_MOV_FFMPEG_FFPROBE_SAMPLES-$(call REMUX, MP4 MOV, OGG_DEMUXER VORBIS_DECODER) \
                           += fate-mov-mp4-chapters
 fate-mov-mp4-chapters: CMD = transcode ogg $(TARGET_SAMPLES)/vorbis/vorbis_chapter_extension_demo.ogg mp4 "-c copy" "-c copy -t 0.1" "-show_chapters"
@@ -881,6 +919,22 @@ $(MOV_ADPCM_SRC): TAG = GEN
 $(MOV_ADPCM_SRC): ffmpeg$(PROGSSUF)$(EXESUF) tests/data/asynth-44100-2.wav | tests/data
 	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< -nostdin -v error -fflags +bitexact -i $(TARGET_PATH)/tests/data/asynth-44100-2.wav -t 0.1 -c:a $(patsubst mov-%,%,$(basename $(@F))) -flags +bitexact -fflags +bitexact -y $(TARGET_PATH)/$@

+# A shortened last block keeps its duration in a fragment.
+tests/data/mov-adpcm_ima_qt-trim.mov: TAG = GEN
+tests/data/mov-adpcm_ima_qt-trim.mov: ffmpeg$(PROGSSUF)$(EXESUF) tests/data/asynth-44100-1.wav | tests/data
+	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< -nostdin -v error -i $(TARGET_PATH)/tests/data/asynth-44100-1.wav -c:a adpcm_ima_qt -t 0.02 -use_editlist 0 -flags +bitexact -fflags +bitexact -y $(TARGET_PATH)/$@
+
+FATE_MOV_FFMPEG_FFPROBE-$(call REMUX, MOV, WAV_DEMUXER PCM_S16LE_DECODER ADPCM_IMA_QT_ENCODER ARESAMPLE_FILTER) += fate-mov-adpcm-ima-qt-frag-trim
+fate-mov-adpcm-ima-qt-frag-trim: tests/data/mov-adpcm_ima_qt-trim.mov
+fate-mov-adpcm-ima-qt-frag-trim: CMD = transcode mov $(TARGET_PATH)/tests/data/mov-adpcm_ima_qt-trim.mov mov \
+  "-c:a copy -movflags +frag_keyframe+empty_moov -use_editlist 1" "-c copy" "-show_entries stream=duration_ts"
+
+# The 882-sample trim cannot be represented exactly on a 1024 Hz movie clock.
+FATE_MOV_FFMPEG_FFPROBE-$(call REMUX, MOV, WAV_DEMUXER PCM_S16LE_DECODER ADPCM_IMA_QT_ENCODER ARESAMPLE_FILTER) += fate-mov-adpcm-ima-qt-flat-trim
+fate-mov-adpcm-ima-qt-flat-trim: tests/data/mov-adpcm_ima_qt-trim.mov
+fate-mov-adpcm-ima-qt-flat-trim: CMD = transcode mov $(TARGET_PATH)/tests/data/mov-adpcm_ima_qt-trim.mov mov \
+  "-c:a copy -movie_timescale 1024 -use_editlist 1" "-c copy" "-show_entries stream=duration_ts"
+
 FATE_MOV_FFMPEG_FFPROBE-$(call ALLYES, ADPCM_MS_ENCODER ADPCM_MS_DECODER PCM_S16LE_DECODER PCM_S16LE_ENCODER WAV_MUXER WAV_DEMUXER MOV_MUXER MOV_DEMUXER FRAMECRC_MUXER FILE_PROTOCOL PIPE_PROTOCOL) += fate-mov-adpcm-ms-remux
 FATE_MOV_FFMPEG_FFPROBE-$(call ALLYES, ADPCM_IMA_WAV_ENCODER ADPCM_IMA_WAV_DECODER PCM_S16LE_DECODER PCM_S16LE_ENCODER ARESAMPLE_FILTER WAV_MUXER WAV_DEMUXER MOV_MUXER MOV_DEMUXER FRAMECRC_MUXER FILE_PROTOCOL PIPE_PROTOCOL) += fate-mov-adpcm-ima-wav-remux
 fate-mov-adpcm-ms-remux: tests/data/mov-adpcm_ms.wav
diff --git a/tests/ref/fate/mov-adpcm-ima-qt-flat-trim b/tests/ref/fate/mov-adpcm-ima-qt-flat-trim
new file mode 100644
index 0000000000..1218d0d2e9
--- /dev/null
+++ b/tests/ref/fate/mov-adpcm-ima-qt-flat-trim
@@ -0,0 +1,24 @@
+f054476614cb9eced6947eb388b913a1 *tests/data/fate/mov-adpcm-ima-qt-flat-trim.mov
+1153 tests/data/fate/mov-adpcm-ima-qt-flat-trim.mov
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: adpcm_ima_qt
+#sample_rate 0: 44100
+#channel_layout_name 0: mono
+0,          0,          0,       64,       34, 0xef1a0f7f
+0,         64,         64,       64,       34, 0x04d50e2b
+0,        128,        128,       64,       34, 0x223910ba
+0,        192,        192,       64,       34, 0x11d70eb2
+0,        256,        256,       64,       34, 0xdcb50db3
+0,        320,        320,       64,       34, 0xfcf80f07
+0,        384,        384,       64,       34, 0x0b770ecd
+0,        448,        448,       64,       34, 0x19661063
+0,        512,        512,       64,       34, 0x01bc0da4
+0,        576,        576,       64,       34, 0x25b51142
+0,        640,        640,       64,       34, 0xe2c60cc2
+0,        704,        704,       64,       34, 0x18c310dc
+0,        768,        768,       64,       34, 0xf2470dd4
+0,        832,        832,       50,       34, 0xf3720d42
+[STREAM]
+duration_ts=882
+[/STREAM]
diff --git a/tests/ref/fate/mov-adpcm-ima-qt-frag-trim b/tests/ref/fate/mov-adpcm-ima-qt-frag-trim
new file mode 100644
index 0000000000..d76eb92648
--- /dev/null
+++ b/tests/ref/fate/mov-adpcm-ima-qt-frag-trim
@@ -0,0 +1,24 @@
+8b1894bce4aef51e5024ac60209653be *tests/data/fate/mov-adpcm-ima-qt-frag-trim.mov
+1348 tests/data/fate/mov-adpcm-ima-qt-frag-trim.mov
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: adpcm_ima_qt
+#sample_rate 0: 44100
+#channel_layout_name 0: mono
+0,          0,          0,       64,       34, 0xef1a0f7f
+0,         64,         64,       64,       34, 0x04d50e2b
+0,        128,        128,       64,       34, 0x223910ba
+0,        192,        192,       64,       34, 0x11d70eb2
+0,        256,        256,       64,       34, 0xdcb50db3
+0,        320,        320,       64,       34, 0xfcf80f07
+0,        384,        384,       64,       34, 0x0b770ecd
+0,        448,        448,       64,       34, 0x19661063
+0,        512,        512,       64,       34, 0x01bc0da4
+0,        576,        576,       64,       34, 0x25b51142
+0,        640,        640,       64,       34, 0xe2c60cc2
+0,        704,        704,       64,       34, 0x18c310dc
+0,        768,        768,       64,       34, 0xf2470dd4
+0,        832,        832,       50,       34, 0xf3720d42
+[STREAM]
+duration_ts=882
+[/STREAM]
diff --git a/tests/ref/fate/mov-adpcm-ima-qt-trim b/tests/ref/fate/mov-adpcm-ima-qt-trim
new file mode 100644
index 0000000000..2d89d30b3b
--- /dev/null
+++ b/tests/ref/fate/mov-adpcm-ima-qt-trim
@@ -0,0 +1,23 @@
+c261e4a193a0b122d120627031b6c10a *tests/data/fate/mov-adpcm-ima-qt-trim.mov
+1185 tests/data/fate/mov-adpcm-ima-qt-trim.mov
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: adpcm_ima_qt
+#sample_rate 0: 48000
+#channel_layout_name 0: mono
+0,          0,          0,       64,       34, 0x00000000
+0,         64,         64,       64,       34, 0x00000000
+0,        128,        128,       64,       34, 0x00000000
+0,        192,        192,       64,       34, 0x00000000
+0,        256,        256,       64,       34, 0x00000000
+0,        320,        320,       64,       34, 0x00000000
+0,        384,        384,       64,       34, 0x00000000
+0,        448,        448,       64,       34, 0x00000000
+0,        512,        512,       64,       34, 0x00000000
+0,        576,        576,       64,       34, 0x00000000
+0,        640,        640,       64,       34, 0x00000000
+0,        704,        704,       64,       34, 0x00000000
+0,        768,        768,       64,       34, 0x00000000
+0,        832,        832,       64,       34, 0x00000000
+0,        896,        896,       64,       34, 0x00000000
+0,        960,        960,       48,       34, 0x00000000
diff --git a/tests/ref/fate/mov-ima-timescale1000-full b/tests/ref/fate/mov-ima-timescale1000-full
new file mode 100644
index 0000000000..06aa7096b3
--- /dev/null
+++ b/tests/ref/fate/mov-ima-timescale1000-full
@@ -0,0 +1,8 @@
+#tb 0: 1/1000
+#media_type 0: audio
+#codec_id 0: adpcm_ima_qt
+#sample_rate 0: 48000
+#channel_layout_name 0: mono
+0,          0,          0,        1,       34, 0x00000000
+0,          1,          1,        2,       34, 0x00000000
+0,          3,          3,        1,       34, 0x00000000
diff --git a/tests/ref/fate/mov-mp4-dts-trim b/tests/ref/fate/mov-mp4-dts-trim
new file mode 100644
index 0000000000..af3d6cd5b0
--- /dev/null
+++ b/tests/ref/fate/mov-mp4-dts-trim
@@ -0,0 +1,9 @@
+d80c6a0cce6346e2a7547226c577bac9 *tests/data/fate/mov-mp4-dts-trim.mp4
+4458 tests/data/fate/mov-mp4-dts-trim.mp4
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: dts
+#sample_rate 0: 48000
+#channel_layout_name 0: mono
+0,          0,          0,      512,     1884, 0x56d32840
+0,        512,        512,      496,     1884, 0x56d32840
diff --git a/tests/ref/fate/mov-mp4-opus-cenc-trim b/tests/ref/fate/mov-mp4-opus-cenc-trim
new file mode 100644
index 0000000000..02eb500508
--- /dev/null
+++ b/tests/ref/fate/mov-mp4-opus-cenc-trim
@@ -0,0 +1,12 @@
+49daa6cbd5d595b275ccd202c1d0771a *tests/data/fate/mov-mp4-opus-cenc-trim.mp4
+820 tests/data/fate/mov-mp4-opus-cenc-trim.mp4
+#extradata 0:       19, 0x3c4604cf
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0,          0,          0,      960,        3, 0x05f002f9
+0,        960,        960,      168,        3, 0x05f002f9
+packet|duration=960|side_datum/encryption_info:side_data_type=Encryption info
+packet|duration=168|side_datum/encryption_info:side_data_type=Encryption info
diff --git a/tests/ref/fate/mov-mp4-opus-trim b/tests/ref/fate/mov-mp4-opus-trim
new file mode 100644
index 0000000000..8481cf8604
--- /dev/null
+++ b/tests/ref/fate/mov-mp4-opus-trim
@@ -0,0 +1,10 @@
+dcb4e18e9a275929672ff5a1df480e81 *tests/data/fate/mov-mp4-opus-trim.mp4
+671 tests/data/fate/mov-mp4-opus-trim.mp4
+#extradata 0:       19, 0x3c4604cf
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0,          0,          0,      960,        3, 0x05f002f9
+0,        960,        960,      168,        3, 0x05f002f9
diff --git a/tests/ref/fate/mov-mp4-vorbis-trim b/tests/ref/fate/mov-mp4-vorbis-trim
new file mode 100644
index 0000000000..2d599070d2
--- /dev/null
+++ b/tests/ref/fate/mov-mp4-vorbis-trim
@@ -0,0 +1,10 @@
+953f1e71b4689eb198ab0d43d456a277 *tests/data/fate/mov-mp4-vorbis-trim.mp4
+4051 tests/data/fate/mov-mp4-vorbis-trim.mp4
+#extradata 0:     3296, 0xe8f076bc
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: vorbis
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0,          0,          0,     1024,       30, 0x03e00022
+0,       1024,       1024,     1008,       30, 0x03e00022
diff --git a/tests/ref/fate/mov-opus-timescale1000-full b/tests/ref/fate/mov-opus-timescale1000-full
new file mode 100644
index 0000000000..6b51b30be7
--- /dev/null
+++ b/tests/ref/fate/mov-opus-timescale1000-full
@@ -0,0 +1,16 @@
+#extradata 0:       27, 0x636604e9
+#tb 0: 1/1000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: 5.1
+0,          0,          0,        2,      103, 0x8585323f
+0,          2,          2,        3,      103, 0xc3c93747
+0,          5,          5,        2,      103, 0x3b6130c1
+0,          7,          7,        3,      103, 0x86542e73
+0,         10,         10,        2,      103, 0x3d7b3404
+0,         12,         12,        3,      103, 0x6249336a
+0,         15,         15,        2,      103, 0x1bc130d9
+0,         17,         17,        3,      103, 0xb10e2c7b
+0,         20,         20,        2,      103, 0x99c83350
+0,         22,         22,        2,      103, 0x3a42336b
diff --git a/tests/ref/fate/mov-opus-timescale1000-trim b/tests/ref/fate/mov-opus-timescale1000-trim
new file mode 100644
index 0000000000..f5920f351e
--- /dev/null
+++ b/tests/ref/fate/mov-opus-timescale1000-trim
@@ -0,0 +1,16 @@
+#extradata 0:       27, 0x636604e9
+#tb 0: 1/1000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: 5.1
+0,          0,          0,        2,      103, 0x8585323f
+0,          2,          2,        3,      103, 0xc3c93747
+0,          5,          5,        2,      103, 0x3b6130c1
+0,          7,          7,        3,      103, 0x86542e73
+0,         10,         10,        2,      103, 0x3d7b3404
+0,         12,         12,        3,      103, 0x6249336a
+0,         15,         15,        2,      103, 0x1bc130d9
+0,         17,         17,        3,      103, 0xb10e2c7b
+0,         20,         20,        2,      103, 0x99c83350
+0,         22,         22,        1,      103, 0x3a42336b
diff --git a/tests/ref/fate/mov-opus-timescale32000-trim b/tests/ref/fate/mov-opus-timescale32000-trim
new file mode 100644
index 0000000000..df1c45ebc7
--- /dev/null
+++ b/tests/ref/fate/mov-opus-timescale32000-trim
@@ -0,0 +1,8 @@
+#extradata 0:       19, 0x3c4604cf
+#tb 0: 1/32000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0,          0,          0,      640,        3, 0x05f002f9
+0,        640,        640,      639,        3, 0x05f002f9