Commit f94bc2f3e7 for ffmpeg

commit f94bc2f3e76fec7420bcc8deeaf58c9e11af1800
Author: Romain Beauxis <romain.beauxis@gmail.com>
Date:   Sat Nov 21 09:37:33 2026 -0500

    avformat/mov: set the frame size of IMA ADPCM

    Each IMA ADPCM block decodes 64 samples. Exporting it lets the generic
    end trim discard what a shortened last sample leaves out.

    With a frame size, movenc restores the full block length of a shortened
    last sample and leaves the trim to the edit list. That edit is
    open-ended in a fragment, and rounds to the movie clock otherwise, so
    keep the shortened duration for QuickTime IMA.

    The qt-ima4 samples now decode to the 578298 samples their duration
    declares, instead of 578304.

diff --git a/libavformat/mov.c b/libavformat/mov.c
index b89d9d0eca..75040c19e4 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3224,7 +3224,7 @@ static int mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb,
         sc->bytes_per_frame   = 1 * st->codecpar->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_ADPCM_IMA_QT:
-        sc->samples_per_frame = 64;
+        sc->samples_per_frame = st->codecpar->frame_size = 64;
         sc->bytes_per_frame   = 34 * st->codecpar->ch_layout.nb_channels;
         break;
     case AV_CODEC_ID_GSM:
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4b35a86c26..f832ae712a 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -7817,20 +7817,23 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
             coded_samples = par->frame_size;
     }
     if (coded_samples > 0) {
-        /* fragments have an open-ended edit list, their durations carry the end trim */
-        int adpcm_fragment = (par->codec_id == AV_CODEC_ID_ADPCM_MS ||
-                              par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) &&
-                             !mov_packet_uses_stbl(mov);
+        /* An edit list rounds to the movie clock, which can be coarser than
+         * the track's, so IMA4 keeps its trim in the sample duration. The
+         * open-ended edit list of a fragment needs it for all ADPCM. */
+        int adpcm_short_sample = par->codec_id == AV_CODEC_ID_ADPCM_IMA_QT ||
+                                 ((par->codec_id == AV_CODEC_ID_ADPCM_MS ||
+                                   par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) &&
+                                  !mov_packet_uses_stbl(mov));

         duration = FFMAX(av_rescale_q(coded_samples, (AVRational){ 1, trk->par->sample_rate },
                                       trk->st->time_base), pkt->duration);
-        if (mov->use_editlist && !adpcm_fragment)
+        if (mov->use_editlist && !adpcm_short_sample)
             pkt->duration = duration;
         duration -= av_rescale_q(discard, (AVRational){ 1, trk->par->sample_rate },
                                  trk->st->time_base);
         if (duration < 0)
             return AVERROR_INVALIDDATA;
-        if (adpcm_fragment)
+        if (adpcm_short_sample)
             pkt->duration = duration;
     } else
         duration = pkt->duration;
diff --git a/tests/ref/fate/mov-adpcm-ima-qt-flat-trim b/tests/ref/fate/mov-adpcm-ima-qt-flat-trim
index 1218d0d2e9..db7dbe3386 100644
--- a/tests/ref/fate/mov-adpcm-ima-qt-flat-trim
+++ b/tests/ref/fate/mov-adpcm-ima-qt-flat-trim
@@ -1,4 +1,4 @@
-f054476614cb9eced6947eb388b913a1 *tests/data/fate/mov-adpcm-ima-qt-flat-trim.mov
+4e623936757776bb481e93b43287bdfc *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
@@ -18,7 +18,7 @@ f054476614cb9eced6947eb388b913a1 *tests/data/fate/mov-adpcm-ima-qt-flat-trim.mov
 0,        640,        640,       64,       34, 0xe2c60cc2
 0,        704,        704,       64,       34, 0x18c310dc
 0,        768,        768,       64,       34, 0xf2470dd4
-0,        832,        832,       50,       34, 0xf3720d42
+0,        832,        832,       50,       34, 0xf3720d42, S=1, Skip Samples,       10, 0x0054000e
 [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
index d76eb92648..b07a21c98c 100644
--- a/tests/ref/fate/mov-adpcm-ima-qt-frag-trim
+++ b/tests/ref/fate/mov-adpcm-ima-qt-frag-trim
@@ -1,4 +1,4 @@
-8b1894bce4aef51e5024ac60209653be *tests/data/fate/mov-adpcm-ima-qt-frag-trim.mov
+81ce89fcc790b4df76051e1931d25e89 *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
diff --git a/tests/ref/fate/mov-adpcm-ima-qt-trim b/tests/ref/fate/mov-adpcm-ima-qt-trim
index 2d89d30b3b..3dce0cbacb 100644
--- a/tests/ref/fate/mov-adpcm-ima-qt-trim
+++ b/tests/ref/fate/mov-adpcm-ima-qt-trim
@@ -20,4 +20,4 @@ c261e4a193a0b122d120627031b6c10a *tests/data/fate/mov-adpcm-ima-qt-trim.mov
 0,        768,        768,       64,       34, 0x00000000
 0,        832,        832,       64,       34, 0x00000000
 0,        896,        896,       64,       34, 0x00000000
-0,        960,        960,       48,       34, 0x00000000
+0,        960,        960,       48,       34, 0x00000000, S=1, Skip Samples,       10, 0x00600010
diff --git a/tests/ref/fate/qt-ima4-mono b/tests/ref/fate/qt-ima4-mono
index b8fc5f99de..83f2958203 100644
--- a/tests/ref/fate/qt-ima4-mono
+++ b/tests/ref/fate/qt-ima4-mono
@@ -1 +1 @@
-e178ed520edf2f46492ae740d88f5815
+dd6ba393d7aee90d71ab35c72095d166
diff --git a/tests/ref/fate/qt-ima4-stereo b/tests/ref/fate/qt-ima4-stereo
index 84c9f46d02..c847af6ebe 100644
--- a/tests/ref/fate/qt-ima4-stereo
+++ b/tests/ref/fate/qt-ima4-stereo
@@ -1 +1 @@
-d22be0e193dcbba1068a1ca6ab04cf77
+5f2a3bedc62ea1ce63726e0eff29e741