Commit 7a984c3c7d for ffmpeg

commit 7a984c3c7d773387c4dff74b1ca32eebb2cbbd32
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date:   Thu Nov 26 08:20:01 2026 -0600

    avformat/ogg/muxer: measure the first page duration in granule units

    The page duration is the difference between the timestamps of the page
    start and end granules, but the start of the first data page was the
    packet timestamp, which does not count the Opus pre-skip that its
    granule does. The first Opus page then ended early by the pre-skip.

diff --git a/libavformat/ogg/muxer.c b/libavformat/ogg/muxer.c
index a755a4747a..f9d75367c0 100644
--- a/libavformat/ogg/muxer.c
+++ b/libavformat/ogg/muxer.c
@@ -620,8 +620,10 @@ static int ogg_buffer_packet(AVFormatContext *s, AVStream *st,
     else
         granule = link_pts + pkt->duration + oggstream->packet_granule_offset;

+    /* In the units of ogg_granule_to_timestamp(), which ends the page. */
     if (oggstream->page.start_granule == AV_NOPTS_VALUE)
-        oggstream->page.start_granule = link_pts;
+        oggstream->page.start_granule = oggstream->mapping->packet_granule ? link_pts :
+                                        link_pts + oggstream->packet_granule_offset;

     ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule, 0);
     if (ret < 0)
diff --git a/tests/ref/fate/ogg-copy-trim-opus-large-priming b/tests/ref/fate/ogg-copy-trim-opus-large-priming
index 2d2a37d9bf..58e0205eba 100644
--- a/tests/ref/fate/ogg-copy-trim-opus-large-priming
+++ b/tests/ref/fate/ogg-copy-trim-opus-large-priming
@@ -4,12 +4,12 @@
 #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
+0,     -65535,     -65535,      960,      443, 0xc3d7d97c, S=1, Skip Samples,       10, 0x12ed01fe
+0,     -64575,     -64575,      960,      235, 0xb58f6d2f
+0,     -63615,     -63615,      960,      345, 0x88bcac2b
+0,     -62655,     -62655,      960,      239, 0x6cf572c4
+0,     -61695,     -61695,      960,      246, 0xd8108289
+0,     -60735,     -60735,      960,      189, 0xfd0962e4
 streams.stream.0.initial_padding=65535
-streams.stream.0.start_time="N/A"
-decoded copy: 695268 bytes, decoded source: 681248 bytes
+streams.stream.0.start_time="-0.093021"
+decoded copy: 699108 bytes, decoded source: 681248 bytes