Commit 23b44ece43 for ffmpeg
commit 23b44ece43fee13961bff04383ea83debe49fda0
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Sun Nov 22 08:18:06 2026 -0500
tests/fate: add Ogg stream copy trim tests
Stream copy audio to Ogg and compare the decoded size of the copy with
that of the source decoded with the same options.
Cuts of audio muxed next to video whose only keyframe is at 0 start the
copied packets well before the cut point, as a real cut does with sparse
keyframes.
The refs record Opus cuts beyond the pre-skip giving unreadable files,
shorter ones keeping a stale pre-skip, FLAC playing the audio before the
cut, and chained links and Matroska end trims longer than their source.
diff --git a/tests/Makefile b/tests/Makefile
index 2fb8a368cc..cb81a98835 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -258,6 +258,7 @@ include $(SRC_PATH)/tests/fate/ogg-vorbis.mak
include $(SRC_PATH)/tests/fate/ogg-flac.mak
include $(SRC_PATH)/tests/fate/ogg-opus.mak
include $(SRC_PATH)/tests/fate/ogg-chain-copy.mak
+include $(SRC_PATH)/tests/fate/ogg-copy-trim.mak
include $(SRC_PATH)/tests/fate/ogg-theora.mak
include $(SRC_PATH)/tests/fate/oma.mak
include $(SRC_PATH)/tests/fate/opus.mak
diff --git a/tests/fate/ogg-copy-trim.mak b/tests/fate/ogg-copy-trim.mak
new file mode 100644
index 0000000000..bfaeb45259
--- /dev/null
+++ b/tests/fate/ogg-copy-trim.mak
@@ -0,0 +1,199 @@
+# Stream copies the audio of $(1), read with input options $(2), to $(3).ogg
+# with output options $(4).
+# Lists the first packets and the start of the copy, then the decoded sizes
+# of the copy and of $(1) decoded with the same options, which match when the
+# copy keeps the start and end trims.
+OGG_COPY_TRIM = \
+ ffmpeg $(2) -i $(1) -map 0:a -c copy -fflags +bitexact $(4) -f ogg -y $(TARGET_PATH)/$(3).ogg && \
+ framecrc -i $(TARGET_PATH)/$(3).ogg -c copy -frames:a 6 && \
+ probe -show_entries stream=start_time,initial_padding -of flat $(TARGET_PATH)/$(3).ogg && \
+ ffmpeg -auto_conversion_filters -i $(TARGET_PATH)/$(3).ogg -f s16le -y $(TARGET_PATH)/$(3).copy.pcm && \
+ ffmpeg -auto_conversion_filters $(2) -i $(1) -map 0:a -f s16le -y $(TARGET_PATH)/$(3).pcm && \
+ echo "decoded copy: $$(($$(wc -c < $(3).copy.pcm))) bytes, decoded source: $$(($$(wc -c < $(3).pcm))) bytes"
+
+# Muxes the audio of sample $(1) next to video whose only keyframe is at 0,
+# to $(2).mkv: a cut then starts the copied audio at the beginning of the file.
+OGG_COPY_TRIM_AV = \
+ ffmpeg -i $(TARGET_SAMPLES)/mov/spherical.mov -i $(TARGET_SAMPLES)/$(1) \
+ -map 0:v -map 1:a -c copy -t 2 -fflags +bitexact -f matroska -y $(TARGET_PATH)/$(2).mkv
+
+# Cuts sample $(1) muxed with video at $(2) seconds, into $(3), with output
+# options $(4).
+OGG_COPY_TRIM_CUT = \
+ $(call OGG_COPY_TRIM_AV,$(1),$(3)) && \
+ $(call OGG_COPY_TRIM,$(TARGET_PATH)/$(3).mkv,-ss $(2),$(3),$(4))
+
+# Number of packets of $(1) not starting at the end of the previous one.
+OGG_COPY_TRIM_GAPS = \
+ ogg_packets=$$(probe -show_entries packet=pts,duration -of csv=p=0 $(1)) && \
+ printf "%s\n" "$$ogg_packets" | \
+ awk -F, "NR > 1 && \$$1 != end { n++ } { end = \$$1 + \$$2 } END { print \"timestamp gaps: \" (n + 0) }"
+
+OGG_COPY_TRIM_FILES = .ogg .copy.pcm .pcm
+OGG_COPY_TRIM_DEPS = OGG_MUXER OGG_DEMUXER FRAMECRC_MUXER ARESAMPLE_FILTER \
+ PCM_S16LE_ENCODER PCM_S16LE_MUXER FILE_PROTOCOL PIPE_PROTOCOL
+OGG_COPY_TRIM_AV_DEPS = MOV_DEMUXER MATROSKA_MUXER MATROSKA_DEMUXER H264_PARSER $(OGG_COPY_TRIM_DEPS)
+
+# Opus cut 1.5 s after the start of the copy, more than the pre-skip can hold.
+OGG_COPY_TRIM_OPUS_CUT = tests/data/fate/ogg-copy-trim-opus-cut
+FATE_OGG_COPY_TRIM-$(call ALLYES, OPUS_DECODER $(OGG_COPY_TRIM_AV_DEPS)) += fate-ogg-copy-trim-opus-cut
+fate-ogg-copy-trim-opus-cut: CMD = $(call OGG_COPY_TRIM_CUT,audiomatch/tones_opus_48000_stereo.opus,1.5,$(OGG_COPY_TRIM_OPUS_CUT))
+fate-ogg-copy-trim-opus-cut: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_CUT),.mkv $(OGG_COPY_TRIM_FILES))
+
+# Opus cut 1 s after the start of the copy, which the pre-skip can hold.
+OGG_COPY_TRIM_OPUS_PRESKIP = tests/data/fate/ogg-copy-trim-opus-cut-preskip
+FATE_OGG_COPY_TRIM-$(call ALLYES, OPUS_PARSER OPUS_DECODER $(OGG_COPY_TRIM_AV_DEPS)) += fate-ogg-copy-trim-opus-cut-preskip
+fate-ogg-copy-trim-opus-cut-preskip: CMD = $(call OGG_COPY_TRIM_CUT,audiomatch/tones_opus_48000_stereo.opus,1.0,$(OGG_COPY_TRIM_OPUS_PRESKIP))
+fate-ogg-copy-trim-opus-cut-preskip: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_PRESKIP),.mkv $(OGG_COPY_TRIM_FILES))
+
+# Opus copied whole: only the encoder priming is trimmed.
+OGG_COPY_TRIM_OPUS_UNCUT = tests/data/fate/ogg-copy-trim-opus-uncut
+FATE_OGG_COPY_TRIM-$(call ALLYES, OPUS_PARSER OPUS_DECODER $(OGG_COPY_TRIM_AV_DEPS)) += fate-ogg-copy-trim-opus-uncut
+fate-ogg-copy-trim-opus-uncut: CMD = $(call OGG_COPY_TRIM_AV,audiomatch/tones_opus_48000_stereo.opus,$(OGG_COPY_TRIM_OPUS_UNCUT)) && \
+ $(call OGG_COPY_TRIM,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_UNCUT).mkv,,$(OGG_COPY_TRIM_OPUS_UNCUT))
+fate-ogg-copy-trim-opus-uncut: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_UNCUT),.mkv $(OGG_COPY_TRIM_FILES))
+
+OGG_COPY_TRIM_FLAC_CUT = tests/data/fate/ogg-copy-trim-flac-cut
+FATE_OGG_COPY_TRIM-$(call ALLYES, FLAC_DEMUXER FLAC_DECODER $(OGG_COPY_TRIM_AV_DEPS)) += fate-ogg-copy-trim-flac-cut
+fate-ogg-copy-trim-flac-cut: CMD = $(call OGG_COPY_TRIM_CUT,filter/hdcd.flac,1.3,$(OGG_COPY_TRIM_FLAC_CUT))
+fate-ogg-copy-trim-flac-cut: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_FLAC_CUT),.mkv $(OGG_COPY_TRIM_FILES))
+
+# FLAC cut within its first packet, which straddles the start.
+OGG_COPY_TRIM_FLAC_STRADDLE = tests/data/fate/ogg-copy-trim-flac-straddle
+FATE_OGG_COPY_TRIM-$(call ALLYES, FLAC_DEMUXER FLAC_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-flac-straddle
+fate-ogg-copy-trim-flac-straddle: CMD = $(call OGG_COPY_TRIM,$(TARGET_SAMPLES)/filter/hdcd.flac,-ss 1.3,$(OGG_COPY_TRIM_FLAC_STRADDLE))
+fate-ogg-copy-trim-flac-straddle: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_FLAC_STRADDLE),$(OGG_COPY_TRIM_FILES))
+
+# Later links start at the timestamps of the end of the previous ones.
+OGG_COPY_TRIM_OPUS_CHAINED = tests/data/fate/ogg-copy-trim-opus-chained
+FATE_OGG_COPY_TRIM-$(call ALLYES, OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-chained
+fate-ogg-copy-trim-opus-chained: CMD = $(call OGG_COPY_TRIM,$(TARGET_SAMPLES)/ogg-opus/chained-meta.ogg,,$(OGG_COPY_TRIM_OPUS_CHAINED))
+fate-ogg-copy-trim-opus-chained: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_CHAINED),$(OGG_COPY_TRIM_FILES))
+
+OGG_COPY_TRIM_VORBIS_CHAINED = tests/data/fate/ogg-copy-trim-vorbis-chained
+FATE_OGG_COPY_TRIM-$(call ALLYES, VORBIS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-vorbis-chained
+fate-ogg-copy-trim-vorbis-chained: CMD = $(call OGG_COPY_TRIM,$(TARGET_SAMPLES)/ogg-vorbis/chained-meta.ogg,,$(OGG_COPY_TRIM_VORBIS_CHAINED))
+fate-ogg-copy-trim-vorbis-chained: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_VORBIS_CHAINED),$(OGG_COPY_TRIM_FILES))
+
+# Opus from Matroska whose last packet carries an end trim.
+OGG_COPY_TRIM_OPUS_END = tests/data/fate/ogg-copy-trim-opus-end
+FATE_OGG_COPY_TRIM-$(call ALLYES, MATROSKA_DEMUXER OPUS_PARSER OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-end
+fate-ogg-copy-trim-opus-end: CMD = $(call OGG_COPY_TRIM,$(TARGET_SAMPLES)/mkv/codec_delay_opus.mkv,,$(OGG_COPY_TRIM_OPUS_END))
+fate-ogg-copy-trim-opus-end: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_END),$(OGG_COPY_TRIM_FILES))
+
+# Opus from MP4, whose last packet is shortened by the edit list.
+OGG_COPY_TRIM_OPUS_MP4 = tests/data/fate/ogg-copy-trim-opus-mp4
+FATE_OGG_COPY_TRIM-$(call ALLYES, MP4_MUXER MOV_DEMUXER OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-mp4
+fate-ogg-copy-trim-opus-mp4: CMD = \
+ ffmpeg -i $(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus -c copy -fflags +bitexact -f mp4 -y $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_MP4).mp4 && \
+ $(call OGG_COPY_TRIM,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_MP4).mp4,,$(OGG_COPY_TRIM_OPUS_MP4))
+fate-ogg-copy-trim-opus-mp4: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_MP4),.mp4 $(OGG_COPY_TRIM_FILES))
+
+# A single Opus packet from MP4 carries both start skip and end discard.
+OGG_COPY_TRIM_OPUS_MP4_ONE = tests/data/fate/ogg-copy-trim-opus-mp4-one
+FATE_OGG_COPY_TRIM-$(call ALLYES, MP4_MUXER MOV_DEMUXER SETTS_BSF OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-mp4-one
+fate-ogg-copy-trim-opus-mp4-one: CMD = \
+ ffmpeg -i $(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus -c copy -fflags +bitexact \
+ -frames:a 1 -bsf:a setts=duration=792 -f mp4 -y $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_MP4_ONE).mp4 && \
+ $(call OGG_COPY_TRIM,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_MP4_ONE).mp4,,$(OGG_COPY_TRIM_OPUS_MP4_ONE))
+fate-ogg-copy-trim-opus-mp4-one: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_MP4_ONE),.mp4 $(OGG_COPY_TRIM_FILES))
+
+# A shifted single-packet link retains the end trim rather than the offset.
+OGG_COPY_TRIM_OPUS_MP4_ONE_OFFSET = tests/data/fate/ogg-copy-trim-opus-mp4-one-offset
+FATE_OGG_COPY_TRIM-$(call ALLYES, MP4_MUXER MOV_DEMUXER SETTS_BSF OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-mp4-one-offset
+fate-ogg-copy-trim-opus-mp4-one-offset: CMD = \
+ ffmpeg -i $(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus -c copy -fflags +bitexact \
+ -frames:a 1 -bsf:a setts=duration=792 -f mp4 -y $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_MP4_ONE_OFFSET).mp4 && \
+ $(call OGG_COPY_TRIM,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_MP4_ONE_OFFSET).mp4,,$(OGG_COPY_TRIM_OPUS_MP4_ONE_OFFSET),-output_ts_offset 0.5)
+fate-ogg-copy-trim-opus-mp4-one-offset: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_MP4_ONE_OFFSET),.mp4 $(OGG_COPY_TRIM_FILES))
+
+# Opus through the segment muxer: the child trailer writes the trimmed
+# granule and marks the last page EOS. Compare the decoded samples as well.
+OGG_COPY_TRIM_OPUS_SEGMENT = tests/data/fate/ogg-copy-trim-opus-segment
+FATE_OGG_COPY_TRIM-$(call ALLYES, SEGMENT_MUXER OGG_MUXER OGG_DEMUXER FILE_PROTOCOL \
+ ARESAMPLE_FILTER PCM_S16LE_ENCODER PCM_S16LE_MUXER OPUS_DECODER) += fate-ogg-copy-trim-opus-segment
+fate-ogg-copy-trim-opus-segment: libavformat/tests/ogg_pages$(EXESUF)
+fate-ogg-copy-trim-opus-segment: CMD = \
+ ffmpeg -i $(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus -c copy -fflags +bitexact \
+ -avoid_negative_ts disabled -f segment -segment_time 100 -segment_format ogg -y $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_SEGMENT)-%d.ogg && \
+ run libavformat/tests/ogg_pages$(EXESUF) $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_SEGMENT)-0.ogg > $(OGG_COPY_TRIM_OPUS_SEGMENT).pages && \
+ grep -o "granule=[0-9]* flags=..." $(OGG_COPY_TRIM_OPUS_SEGMENT).pages | tail -n 1 && \
+ $(call OGG_CHAIN_COPY_DECODE,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_SEGMENT)-0.ogg,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_SEGMENT).copy.pcm) && \
+ $(call OGG_CHAIN_COPY_DECODE,$(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_SEGMENT).pcm) && \
+ $(call OGG_CHAIN_COPY_COMPARE,$(OGG_COPY_TRIM_OPUS_SEGMENT).pcm,$(OGG_COPY_TRIM_OPUS_SEGMENT).copy.pcm,decoded copy)
+fate-ogg-copy-trim-opus-segment: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_SEGMENT),-0.ogg .pages .pcm .copy.pcm)
+
+# Opus from CAF whose encoder priming is more than the pre-skip field can hold.
+OGG_COPY_TRIM_OPUS_PRIMING = tests/data/fate/ogg-copy-trim-opus-large-priming
+FATE_OGG_COPY_TRIM-$(call ALLYES, CAF_DEMUXER OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-large-priming
+fate-ogg-copy-trim-opus-large-priming: CMD = $(call OGG_COPY_TRIM,$(TARGET_SAMPLES)/caf/opus-large-priming.caf,,$(OGG_COPY_TRIM_OPUS_PRIMING))
+fate-ogg-copy-trim-opus-large-priming: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_PRIMING),$(OGG_COPY_TRIM_FILES))
+
+# Opus whose start the output offset moves past its encoder priming.
+OGG_COPY_TRIM_OPUS_OFFSET = tests/data/fate/ogg-copy-trim-opus-offset
+FATE_OGG_COPY_TRIM-$(call ALLYES, OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-offset
+fate-ogg-copy-trim-opus-offset: CMD = $(call OGG_COPY_TRIM,$(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus,,$(OGG_COPY_TRIM_OPUS_OFFSET),-output_ts_offset 0.004)
+fate-ogg-copy-trim-opus-offset: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_OFFSET),$(OGG_COPY_TRIM_FILES))
+
+# The same when the default packet layout would put everything on one page.
+OGG_COPY_TRIM_OPUS_OFFSET_PRIMING = tests/data/fate/ogg-copy-trim-opus-offset-priming
+FATE_OGG_COPY_TRIM-$(call ALLYES, OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-offset-priming
+fate-ogg-copy-trim-opus-offset-priming: CMD = $(call OGG_COPY_TRIM,$(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus,,$(OGG_COPY_TRIM_OPUS_OFFSET_PRIMING),-output_ts_offset 0.004 -page_duration 5000000)
+fate-ogg-copy-trim-opus-offset-priming: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_OFFSET_PRIMING),$(OGG_COPY_TRIM_FILES))
+
+# A larger offset that shifts the first coded PTS past zero.
+OGG_COPY_TRIM_OPUS_OFFSET_PAGE = tests/data/fate/ogg-copy-trim-opus-offset-page
+FATE_OGG_COPY_TRIM-$(call ALLYES, OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-offset-page
+fate-ogg-copy-trim-opus-offset-page: CMD = $(call OGG_COPY_TRIM,$(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus,,$(OGG_COPY_TRIM_OPUS_OFFSET_PAGE),-output_ts_offset 0.5 -page_duration 5000000)
+fate-ogg-copy-trim-opus-offset-page: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_OFFSET_PAGE),$(OGG_COPY_TRIM_FILES))
+
+# Opus through NUT, which starts it at zero without skip side data.
+OGG_COPY_TRIM_OPUS_NUT = tests/data/fate/ogg-copy-trim-opus-nut
+FATE_OGG_COPY_TRIM-$(call ALLYES, NUT_MUXER NUT_DEMUXER OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-nut
+fate-ogg-copy-trim-opus-nut: CMD = \
+ ffmpeg -i $(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus -c copy -fflags +bitexact -f nut -y $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_NUT).nut && \
+ $(call OGG_COPY_TRIM,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_NUT).nut,,$(OGG_COPY_TRIM_OPUS_NUT))
+fate-ogg-copy-trim-opus-nut: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_NUT),.nut $(OGG_COPY_TRIM_FILES))
+
+# Opus from two Matroska files joined by the concat demuxer: the end trim of the
+# first one falls inside the link. Use file: URLs so relative sample paths
+# are interpreted by the target rather than relative to the concat list.
+OGG_COPY_TRIM_OPUS_CONCAT = tests/data/fate/ogg-copy-trim-opus-concat
+FATE_OGG_COPY_TRIM-$(call ALLYES, CONCAT_DEMUXER MATROSKA_DEMUXER OPUS_PARSER OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-concat
+fate-ogg-copy-trim-opus-concat: CMD = \
+ echo file file:$(TARGET_SAMPLES)/mkv/codec_delay_opus.mkv > $(OGG_COPY_TRIM_OPUS_CONCAT).txt && \
+ echo file file:$(TARGET_SAMPLES)/mkv/codec_delay_opus.mkv >> $(OGG_COPY_TRIM_OPUS_CONCAT).txt && \
+ $(call OGG_COPY_TRIM,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_CONCAT).txt,-f concat -safe 0,$(OGG_COPY_TRIM_OPUS_CONCAT)) && \
+ $(call OGG_COPY_TRIM_GAPS,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_CONCAT).ogg)
+fate-ogg-copy-trim-opus-concat: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_CONCAT),.txt $(OGG_COPY_TRIM_FILES))
+
+# Shift the first coded PTS to zero on a one-packet native encode. The
+# encoder must preserve both its pre-skip and the packet's end padding.
+OGG_COPY_TRIM_OPUS_END_ONLY = tests/data/fate/ogg-copy-trim-opus-end-only
+FATE_OGG_COPY_TRIM-$(call ALLYES, OPUS_ENCODER OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-end-only
+fate-ogg-copy-trim-opus-end-only: CMD = \
+ ffmpeg -i $(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus -t 0.0125 -strict -2 -c:a opus \
+ -fflags +bitexact -f ogg -y $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_END_ONLY).control.ogg && \
+ ffmpeg -i $(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus -t 0.0125 -strict -2 -c:a opus \
+ -avoid_negative_ts make_zero -fflags +bitexact -f ogg -y $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_END_ONLY).ogg && \
+ $(call OGG_CHAIN_COPY_DECODE,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_END_ONLY).control.ogg,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_END_ONLY).pcm) && \
+ $(call OGG_CHAIN_COPY_DECODE,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_END_ONLY).ogg,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_END_ONLY).copy.pcm) && \
+ $(call OGG_CHAIN_COPY_COMPARE,$(OGG_COPY_TRIM_OPUS_END_ONLY).pcm,$(OGG_COPY_TRIM_OPUS_END_ONLY).copy.pcm,decoded copy)
+fate-ogg-copy-trim-opus-end-only: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_END_ONLY),.control.ogg $(OGG_COPY_TRIM_FILES))
+
+# Shorten a packet's duration without adding end discard side data. The
+# original packet already carries start skip.
+OGG_COPY_TRIM_OPUS_DURATION_ONLY = tests/data/fate/ogg-copy-trim-opus-duration-only
+FATE_OGG_COPY_TRIM-$(call ALLYES, SETTS_BSF OPUS_DECODER $(OGG_COPY_TRIM_DEPS)) += fate-ogg-copy-trim-opus-duration-only
+fate-ogg-copy-trim-opus-duration-only: CMD = \
+ ffmpeg -i $(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus -c copy \
+ -frames:a 1 -bsf:a setts=duration=792 -fflags +bitexact -f ogg -y $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_DURATION_ONLY).ogg && \
+ ffmpeg -auto_conversion_filters -i $(TARGET_SAMPLES)/audiomatch/tones_opus_48000_stereo.opus -t 0.010 \
+ -f s16le -y $(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_DURATION_ONLY).pcm && \
+ $(call OGG_CHAIN_COPY_DECODE,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_DURATION_ONLY).ogg,$(TARGET_PATH)/$(OGG_COPY_TRIM_OPUS_DURATION_ONLY).copy.pcm) && \
+ $(call OGG_CHAIN_COPY_COMPARE,$(OGG_COPY_TRIM_OPUS_DURATION_ONLY).pcm,$(OGG_COPY_TRIM_OPUS_DURATION_ONLY).copy.pcm,decoded copy)
+fate-ogg-copy-trim-opus-duration-only: CLEANFILES = $(addprefix $(OGG_COPY_TRIM_OPUS_DURATION_ONLY),$(OGG_COPY_TRIM_FILES))
+
+FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_OGG_COPY_TRIM-yes)
+
+fate-ogg-copy-trim: $(FATE_OGG_COPY_TRIM-yes)
diff --git a/tests/ref/fate/ogg-copy-trim-flac-cut b/tests/ref/fate/ogg-copy-trim-flac-cut
new file mode 100644
index 0000000000..a32b6e2dc6
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-flac-cut
@@ -0,0 +1,15 @@
+#extradata 0: 34, 0x8f590b9b
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: flac
+#sample_rate 0: 44100
+#channel_layout_name 0: stereo
+0, 0, 0, 4096, 11736, 0xdb0073ee
+0, 4096, 4096, 4096, 12370, 0xca19a21f
+0, 8192, 8192, 4096, 11903, 0xb493bd69
+0, 12288, 12288, 4096, 11242, 0x3240cab4
+0, 16384, 16384, 4096, 11372, 0x96b59721
+0, 16384, 16384, 4096, 10645, 0x05b74a79
+streams.stream.0.initial_padding=0
+streams.stream.0.start_time="0.000000"
+decoded copy: 360448 bytes, decoded source: 131128 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-flac-straddle b/tests/ref/fate/ogg-copy-trim-flac-straddle
new file mode 100644
index 0000000000..70f70b40b3
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-flac-straddle
@@ -0,0 +1,15 @@
+#extradata 0: 34, 0x8f590b9b
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: flac
+#sample_rate 0: 44100
+#channel_layout_name 0: stereo
+0, 0, 0, 4096, 8113, 0x9acd9413
+0, 4096, 4096, 4096, 8521, 0x2070136c
+0, 8192, 8192, 4096, 8687, 0xe48f4c68
+0, 12288, 12288, 4096, 10582, 0xe2d10986
+0, 16384, 16384, 4096, 11175, 0xda5442f1
+0, 20480, 20480, 4096, 8563, 0x31a3565e
+streams.stream.0.initial_padding=0
+streams.stream.0.start_time="0.000000"
+decoded copy: 1409024 bytes, decoded source: 1392696 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-chained b/tests/ref/fate/ogg-copy-trim-opus-chained
new file mode 100644
index 0000000000..a907e93059
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-chained
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x3a04048f
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: mono
+0, -312, -312, 960, 283, 0xe9f38292, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 219, 0x85986e41
+0, 1608, 1608, 960, 213, 0xe9a5717a
+0, 2568, 2568, 960, 213, 0x698a6b4c
+0, 3528, 3528, 960, 213, 0xed936c20
+0, 4488, 4488, 312, 315, 0x111b9206, F=0x21, S=1, Skip Samples, 10, 0x033a008a
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.000000"
+decoded copy: 20496 bytes, decoded source: 19200 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-concat b/tests/ref/fate/ogg-copy-trim-opus-concat
new file mode 100644
index 0000000000..7d0fd764ad
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-concat
@@ -0,0 +1,16 @@
+#extradata 0: 19, 0x3a04048f
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: mono
+0, -312, -312, 960, 320, 0x58b9a88d, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 159, 0x6c9c4b4c
+0, 1608, 1608, 960, 148, 0x0caf4b5d
+0, 2568, 2568, 960, 139, 0xc5624226
+0, 3528, 3528, 960, 146, 0x633c4937
+0, 4488, 4488, 960, 153, 0x3d0b4f93
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.007500"
+decoded copy: 199056 bytes, decoded source: 195608 bytes
+timestamp gaps: 1
diff --git a/tests/ref/fate/ogg-copy-trim-opus-cut b/tests/ref/fate/ogg-copy-trim-opus-cut
new file mode 100644
index 0000000000..a231f6ee95
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-cut
@@ -0,0 +1,9 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="N/A"
+decoded copy: 0 bytes, decoded source: 96000 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-cut-preskip b/tests/ref/fate/ogg-copy-trim-opus-cut-preskip
new file mode 100644
index 0000000000..a40c225624
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-cut-preskip
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -312, -312, 960, 354, 0xa2a7b0c8, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 366, 0xf507c0ab
+0, 1608, 1608, 960, 359, 0x0379b6ca
+0, 2568, 2568, 960, 377, 0x7a62c054
+0, 3528, 3528, 960, 369, 0x08c1c043
+0, 4488, 4488, 960, 357, 0x689bab86
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="-0.980000"
+decoded copy: 380160 bytes, decoded source: 192000 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-duration-only b/tests/ref/fate/ogg-copy-trim-opus-duration-only
new file mode 100644
index 0000000000..a8b0d2a32f
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-duration-only
@@ -0,0 +1 @@
+decoded copy: same
diff --git a/tests/ref/fate/ogg-copy-trim-opus-end b/tests/ref/fate/ogg-copy-trim-opus-end
new file mode 100644
index 0000000000..30999f344f
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-end
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x3a04048f
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: mono
+0, -312, -312, 960, 320, 0x58b9a88d, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 159, 0x6c9c4b4c
+0, 1608, 1608, 960, 148, 0x0caf4b5d
+0, 2568, 2568, 960, 139, 0xc5624226
+0, 3528, 3528, 960, 146, 0x633c4937
+0, 4488, 4488, 960, 153, 0x3d0b4f93
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.000500"
+decoded copy: 99216 bytes, decoded source: 97804 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-end-only b/tests/ref/fate/ogg-copy-trim-opus-end-only
new file mode 100644
index 0000000000..1cc3734c42
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-end-only
@@ -0,0 +1 @@
+decoded copy: different
diff --git a/tests/ref/fate/ogg-copy-trim-opus-large-priming b/tests/ref/fate/ogg-copy-trim-opus-large-priming
new file mode 100644
index 0000000000..2d2a37d9bf
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-large-priming
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x48fd0655
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -69040, -69040, 960, 678, 0x2a0146ba, S=1, Skip Samples, 10, 0x12ed01fe
+0, -68080, -68080, 960, 345, 0x88bcac2b
+0, -67120, -67120, 960, 239, 0x6cf572c4
+0, -66160, -66160, 960, 246, 0xd8108289
+0, -65200, -65200, 960, 189, 0xfd0962e4
+0, -64240, -64240, 960, 191, 0xdd5c5cb2
+streams.stream.0.initial_padding=65535
+streams.stream.0.start_time="N/A"
+decoded copy: 695268 bytes, decoded source: 681248 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-mp4 b/tests/ref/fate/ogg-copy-trim-opus-mp4
new file mode 100644
index 0000000000..fe5ca5fb22
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-mp4
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -312, -312, 960, 489, 0xb843f4b8, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 354, 0xa2a7b0c8
+0, 1608, 1608, 960, 366, 0xf507c0ab
+0, 2568, 2568, 960, 359, 0x0379b6ca
+0, 3528, 3528, 960, 377, 0x7a62c054
+0, 4488, 4488, 960, 369, 0x08c1c043
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.000000"
+decoded copy: 384000 bytes, decoded source: 384000 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-mp4-one b/tests/ref/fate/ogg-copy-trim-opus-mp4-one
new file mode 100644
index 0000000000..da83066579
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-mp4-one
@@ -0,0 +1,10 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -312, -312, 792, 489, 0xb843f4b8, F=0x21, S=1, Skip Samples, 10, 0x062900e1
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.000000"
+decoded copy: 1920 bytes, decoded source: 1920 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-mp4-one-offset b/tests/ref/fate/ogg-copy-trim-opus-mp4-one-offset
new file mode 100644
index 0000000000..d0221e6c61
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-mp4-one-offset
@@ -0,0 +1,10 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -312, -312, 960, 489, 0xb843f4b8, F=0x21, S=1, Skip Samples, 10, 0x02390039
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.000000"
+decoded copy: 2592 bytes, decoded source: 1920 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-nut b/tests/ref/fate/ogg-copy-trim-opus-nut
new file mode 100644
index 0000000000..9fceff229b
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-nut
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -312, -312, 960, 489, 0xb843f4b8, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 354, 0xa2a7b0c8
+0, 1608, 1608, 960, 366, 0xf507c0ab
+0, 2568, 2568, 960, 359, 0x0379b6ca
+0, 3528, 3528, 960, 377, 0x7a62c054
+0, 4488, 4488, 960, 369, 0x08c1c043
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="-0.013500"
+decoded copy: 386592 bytes, decoded source: 386592 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-offset b/tests/ref/fate/ogg-copy-trim-opus-offset
new file mode 100644
index 0000000000..af47920b46
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-offset
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -312, -312, 960, 489, 0xb843f4b8, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 354, 0xa2a7b0c8
+0, 1608, 1608, 960, 366, 0xf507c0ab
+0, 2568, 2568, 960, 359, 0x0379b6ca
+0, 3528, 3528, 960, 377, 0x7a62c054
+0, 4488, 4488, 960, 369, 0x08c1c043
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.004000"
+decoded copy: 384000 bytes, decoded source: 384000 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-offset-page b/tests/ref/fate/ogg-copy-trim-opus-offset-page
new file mode 100644
index 0000000000..d7a5dcc45c
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-offset-page
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -312, -312, 960, 489, 0xb843f4b8, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 354, 0xa2a7b0c8
+0, 1608, 1608, 960, 366, 0xf507c0ab
+0, 2568, 2568, 960, 359, 0x0379b6ca
+0, 3528, 3528, 960, 377, 0x7a62c054
+0, 4488, 4488, 960, 369, 0x08c1c043
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.000000"
+decoded copy: 386592 bytes, decoded source: 384000 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-offset-priming b/tests/ref/fate/ogg-copy-trim-opus-offset-priming
new file mode 100644
index 0000000000..698304abb5
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-offset-priming
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -312, -312, 960, 489, 0xb843f4b8, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 354, 0xa2a7b0c8
+0, 1608, 1608, 960, 366, 0xf507c0ab
+0, 2568, 2568, 960, 359, 0x0379b6ca
+0, 3528, 3528, 960, 377, 0x7a62c054
+0, 4488, 4488, 960, 369, 0x08c1c043
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.000000"
+decoded copy: 384768 bytes, decoded source: 384000 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-opus-segment b/tests/ref/fate/ogg-copy-trim-opus-segment
new file mode 100644
index 0000000000..ae08458fec
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-segment
@@ -0,0 +1,2 @@
+granule=96312 flags=---
+decoded copy: different
diff --git a/tests/ref/fate/ogg-copy-trim-opus-uncut b/tests/ref/fate/ogg-copy-trim-opus-uncut
new file mode 100644
index 0000000000..fe5ca5fb22
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-opus-uncut
@@ -0,0 +1,15 @@
+#extradata 0: 19, 0x38100445
+#tb 0: 1/48000
+#media_type 0: audio
+#codec_id 0: opus
+#sample_rate 0: 48000
+#channel_layout_name 0: stereo
+0, -312, -312, 960, 489, 0xb843f4b8, S=1, Skip Samples, 10, 0x02390039
+0, 648, 648, 960, 354, 0xa2a7b0c8
+0, 1608, 1608, 960, 366, 0xf507c0ab
+0, 2568, 2568, 960, 359, 0x0379b6ca
+0, 3528, 3528, 960, 377, 0x7a62c054
+0, 4488, 4488, 960, 369, 0x08c1c043
+streams.stream.0.initial_padding=312
+streams.stream.0.start_time="0.000000"
+decoded copy: 384000 bytes, decoded source: 384000 bytes
diff --git a/tests/ref/fate/ogg-copy-trim-vorbis-chained b/tests/ref/fate/ogg-copy-trim-vorbis-chained
new file mode 100644
index 0000000000..878e91da21
--- /dev/null
+++ b/tests/ref/fate/ogg-copy-trim-vorbis-chained
@@ -0,0 +1,15 @@
+#extradata 0: 3244, 0x21fbfdf4
+#tb 0: 1/44100
+#media_type 0: audio
+#codec_id 0: vorbis
+#sample_rate 0: 44100
+#channel_layout_name 0: mono
+0, -128, -128, 128, 28, 0xa5cb0b38, S=1, Strings Metadata, 51, 0xaec210c6
+0, 0, 0, 576, 59, 0xf30f1b21
+0, 576, 576, 1024, 85, 0x34322b3b
+0, 1600, 1600, 128, 28, 0xa5cb0b38, S=2, Strings Metadata, 52, 0xbfe6111a, New Extradata, 3302, 0xe4d01005
+0, 1728, 1728, 576, 59, 0xf30f1b21
+0, 2304, 2304, 1024, 85, 0x34322b3b
+streams.stream.0.initial_padding=0
+streams.stream.0.start_time="0.000000"
+decoded copy: 6400 bytes, decoded source: 5292 bytes