Commit f45a79f629 for ffmpeg
commit f45a79f62997ee2ee23611a121ec67325e8a7395
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date: Fri Nov 27 08:01:52 2026 -0600
avformat/ogg/demuxer/vorbis: do not count the priming packet in the end trim
The end trim of the last page is the duration of its packets beyond its
granule. When that page also holds the first packet of the link, the
duration of that priming packet was counted, although it returns no
samples, and the end trim cut that many samples of the last packet.
diff --git a/libavformat/ogg/demuxer/vorbis.c b/libavformat/ogg/demuxer/vorbis.c
index 23aa5e0dab..20858ce84d 100644
--- a/libavformat/ogg/demuxer/vorbis.c
+++ b/libavformat/ogg/demuxer/vorbis.c
@@ -485,6 +485,9 @@ static int vorbis_packet(AVFormatContext *s, int idx)
os->lastpts = os->lastdts = AV_NOPTS_VALUE;
if (os->flags & OGG_FLAG_EOS) {
+ /* The priming packet returns no samples. */
+ int samples = bos ? 0 : os->pduration;
+
/* Reset at the start of the EOS page to avoid carrying over stale
* duration from a previously processed EOS page, as can happen on
* short or chained ogg streams and when probing rescans the page.
@@ -494,9 +497,9 @@ static int vorbis_packet(AVFormatContext *s, int idx)
priv->eos_page_duration = 0;
if (os->segp != os->nsegs) {
- priv->eos_page_duration += os->pduration;
+ priv->eos_page_duration += samples;
} else {
- int64_t skip = priv->eos_page_duration + os->pduration -
+ int64_t skip = priv->eos_page_duration + samples -
(os->granule - priv->last_page_granule);
if (skip > 0)
os->end_trimming = skip;
diff --git a/tests/ref/fate/ogg-vorbis-chained-large-comment b/tests/ref/fate/ogg-vorbis-chained-large-comment
index 20ca11e82c..3799d4fa0e 100644
--- a/tests/ref/fate/ogg-vorbis-chained-large-comment
+++ b/tests/ref/fate/ogg-vorbis-chained-large-comment
@@ -29,7 +29,7 @@
0, 18368, 18368, 1024, 307, 0x331a8a6a
0, 19392, 19392, 1024, 293, 0x59eb908a
0, 20416, 20416, 1024, 294, 0x11dc9474
-0, 21440, 21440, 1024, 300, 0x7c9d9254, S=1, Skip Samples, 10, 0x03000080
+0, 21440, 21440, 1024, 300, 0x7c9d9254
0, 22464, 22464, 128, 3, 0x00000000, S=2, Strings Metadata, 70115, 0xf8df6f8e, New Extradata, 82871, 0x33479e75
0, 22592, 22592, 576, 4, 0x0028000a
0, 23168, 23168, 1024, 4, 0x0038000e
@@ -55,4 +55,4 @@
0, 40960, 40960, 1024, 307, 0x331a8a6a
0, 41984, 41984, 1024, 293, 0x59eb908a
0, 43008, 43008, 1024, 294, 0x11dc9474
-0, 44032, 44032, 1024, 300, 0x7c9d9254, S=1, Skip Samples, 10, 0x03000080
+0, 44032, 44032, 1024, 300, 0x7c9d9254
diff --git a/tests/ref/fate/ogg-vorbis-initial-padding-chained b/tests/ref/fate/ogg-vorbis-initial-padding-chained
index afc0483477..15d251a493 100644
--- a/tests/ref/fate/ogg-vorbis-initial-padding-chained
+++ b/tests/ref/fate/ogg-vorbis-initial-padding-chained
@@ -47,7 +47,7 @@ data_hash=CRC32:dab3c9f5
[SIDE_DATA]
side_data_type=Skip Samples
skip_samples=0
-discard_padding=405
+discard_padding=277
skip_reason=0
discard_reason=0
[/SIDE_DATA]
@@ -104,7 +104,7 @@ data_hash=CRC32:dab3c9f5
[SIDE_DATA]
side_data_type=Skip Samples
skip_samples=0
-discard_padding=405
+discard_padding=277
skip_reason=0
discard_reason=0
[/SIDE_DATA]