PR #23617 opened by James Almer (jamrial) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23617 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23617.patch
When writing edit lists and the last packet has skip samples side data to report discard padding, for codecs that have a fixed frame size it's best to always use the full packet duration to calculate track duration (and thus bitrate in some cases) and let the edit list be the sole source of triming information. >From a475017603705b7f2ebca4383213ef63ba28f91b Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Sat, 27 Jun 2026 13:50:28 +0000 Subject: [PATCH] avformat/movenc: unify remainder samples signaling When writing edit lists and the last packet has skip samples side data to report discard padding, for codecs that have a fixed frame size it's best to always use the full packet duration to calculate track duration (and thus bitrate in some cases) and let the edit list be the sole source of triming information. Signed-off-by: James Almer <[email protected]> --- libavformat/movenc.c | 2 ++ tests/ref/fate/autorotate | 4 ++-- tests/ref/fate/mov-mp4-iamf-5_1_4 | 16 ++++++++-------- tests/ref/fate/mov-mp4-iamf-7_1_4-video-first | 14 +++++++------- .../ref/fate/mov-mp4-iamf-7_1_4-video-first-2 | 2 +- .../ref/fate/mov-mp4-iamf-7_1_4-video-first-3 | 2 +- tests/ref/fate/mov-mp4-iamf-7_1_4-video-last | 18 +++++++++--------- tests/ref/fate/mov-mp4-iamf-ambisonic_1 | 12 ++++++------ tests/ref/fate/mov-mp4-iamf-stereo | 6 +++--- 9 files changed, 39 insertions(+), 37 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index c14f05ecc8..2d3994e7c0 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -7310,6 +7310,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) if (sd && sd->size >= 10 && trk->par->frame_size) { duration = FFMAX(av_rescale_q(trk->par->frame_size, (AVRational){ 1, trk->par->sample_rate }, trk->st->time_base), duration); + if (mov->use_editlist) + pkt->duration = duration; duration -= av_rescale_q(AV_RL32(sd->data + 4), (AVRational){ 1, trk->par->sample_rate }, trk->st->time_base); if (duration < 0) diff --git a/tests/ref/fate/autorotate b/tests/ref/fate/autorotate index 1166bb63fc..212035c52c 100644 --- a/tests/ref/fate/autorotate +++ b/tests/ref/fate/autorotate @@ -1,5 +1,5 @@ -bb03affe94dfbe39c8cad8eb69dc367c *tests/data/fate/autorotate.mov -197366 tests/data/fate/autorotate.mov +585a9e2d06f94a887a4bab9a7054a8c4 *tests/data/fate/autorotate.mov +197358 tests/data/fate/autorotate.mov #extradata 0: 34, 0x9d7d073f #tb 0: 1/15360 #media_type 0: video diff --git a/tests/ref/fate/mov-mp4-iamf-5_1_4 b/tests/ref/fate/mov-mp4-iamf-5_1_4 index 437663b099..e7bcce54d0 100644 --- a/tests/ref/fate/mov-mp4-iamf-5_1_4 +++ b/tests/ref/fate/mov-mp4-iamf-5_1_4 @@ -1,5 +1,5 @@ -3e12bd652a42de8329a4171c36b6d5a7 *tests/data/fate/mov-mp4-iamf-5_1_4.mp4 -86164 tests/data/fate/mov-mp4-iamf-5_1_4.mp4 +b8a3031c9ce9abe17368842c9744a18c *tests/data/fate/mov-mp4-iamf-5_1_4.mp4 +86156 tests/data/fate/mov-mp4-iamf-5_1_4.mp4 #extradata 0: 34, 0xa77c0cd6 #extradata 1: 34, 0xa77c0cd6 #extradata 2: 34, 0xa7500cd4 @@ -96,12 +96,12 @@ 3, 36864, 36864, 4096, 1251, 0x0b380fcb 4, 36864, 36864, 4096, 1254, 0xf6f01051 5, 36864, 36864, 4096, 1254, 0xf6f01051 -0, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -1, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -2, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf -3, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf -4, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -5, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +0, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +1, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +2, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +3, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +4, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +5, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf [STREAM_GROUP] index=0 id=0x1 diff --git a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first index af1620575e..8154e09e19 100644 --- a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first +++ b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first @@ -140,13 +140,13 @@ 0, 10752, 10752, 512, 1884, 0x2c567db6, F=0x0 0, 11264, 11264, 512, 1880, 0x72237c52, F=0x0 0, 11776, 11776, 512, 1970, 0x60708ff8, F=0x0 -1, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -2, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -3, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf -4, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf -5, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -6, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -7, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +1, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +2, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +3, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +4, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +5, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +6, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +7, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf 0, 12288, 12288, 512, 11659, 0x6bcb830e [STREAM_GROUP] index=0 diff --git a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first-2 b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first-2 index a0d0a63244..2cca39ef85 100644 --- a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first-2 +++ b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first-2 @@ -14,4 +14,4 @@ 0, 28672, 28672, 4096, 1313, 0x2e79ffa2 0, 32768, 32768, 4096, 1323, 0xb9f70fce 0, 36864, 36864, 4096, 1254, 0xf6f01051 -0, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +0, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf diff --git a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first-3 b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first-3 index 8097c9df1c..49130fe1e3 100644 --- a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first-3 +++ b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first-3 @@ -14,4 +14,4 @@ 0, 28672, 28672, 4096, 1310, 0x1f77ff91 0, 32768, 32768, 4096, 1320, 0xea180f1a 0, 36864, 36864, 4096, 1251, 0x0b380fcb -0, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +0, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf diff --git a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-last b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-last index 7f858d8cf4..99d89c7c90 100644 --- a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-last +++ b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-last @@ -1,5 +1,5 @@ -b41682705ad3331c1e8a1c1700d9ddd7 *tests/data/fate/mov-mp4-iamf-7_1_4-video-last.mp4 -416432 tests/data/fate/mov-mp4-iamf-7_1_4-video-last.mp4 +1e81db49be5b9631d52ef2bc9ca42913 *tests/data/fate/mov-mp4-iamf-7_1_4-video-last.mp4 +416424 tests/data/fate/mov-mp4-iamf-7_1_4-video-last.mp4 #extradata 0: 34, 0xa77c0cd6 #extradata 1: 34, 0xa77c0cd6 #extradata 2: 34, 0xa7500cd4 @@ -142,13 +142,13 @@ b41682705ad3331c1e8a1c1700d9ddd7 *tests/data/fate/mov-mp4-iamf-7_1_4-video-last. 7, 10752, 10752, 512, 1884, 0x2c567db6, F=0x0 7, 11264, 11264, 512, 1880, 0x72237c52, F=0x0 7, 11776, 11776, 512, 1970, 0x60708ff8, F=0x0 -0, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -1, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -2, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf -3, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf -4, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -5, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf -6, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +0, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +1, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +2, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +3, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +4, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +5, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +6, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf 7, 12288, 12288, 512, 11659, 0x6bcb830e [STREAM_GROUP] index=0 diff --git a/tests/ref/fate/mov-mp4-iamf-ambisonic_1 b/tests/ref/fate/mov-mp4-iamf-ambisonic_1 index c789b9b57f..d3504a6bc7 100644 --- a/tests/ref/fate/mov-mp4-iamf-ambisonic_1 +++ b/tests/ref/fate/mov-mp4-iamf-ambisonic_1 @@ -1,5 +1,5 @@ -a7107b8604e26720cea8b2b55dd517b9 *tests/data/fate/mov-mp4-iamf-ambisonic_1.mp4 -57619 tests/data/fate/mov-mp4-iamf-ambisonic_1.mp4 +5b419591f207d4a2636ef93a41446244 *tests/data/fate/mov-mp4-iamf-ambisonic_1.mp4 +57611 tests/data/fate/mov-mp4-iamf-ambisonic_1.mp4 #extradata 0: 34, 0x9f9f0c6b #extradata 1: 34, 0x9f9f0c6b #extradata 2: 34, 0x9f9f0c6b @@ -64,10 +64,10 @@ a7107b8604e26720cea8b2b55dd517b9 *tests/data/fate/mov-mp4-iamf-ambisonic_1.mp4 1, 36864, 36864, 4096, 1251, 0x0b380fcb 2, 36864, 36864, 4096, 1251, 0x0b380fcb 3, 36864, 36864, 4096, 1251, 0x0b380fcb -0, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf -1, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf -2, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf -3, 40960, 40960, 3140, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +0, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +1, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +2, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf +3, 40960, 40960, 4096, 1231, 0x98611f9f, S=1, Skip Samples, 10, 0x047700bf [STREAM_GROUP] index=0 id=0x1 diff --git a/tests/ref/fate/mov-mp4-iamf-stereo b/tests/ref/fate/mov-mp4-iamf-stereo index 11b3aca65a..ce00ebc72e 100644 --- a/tests/ref/fate/mov-mp4-iamf-stereo +++ b/tests/ref/fate/mov-mp4-iamf-stereo @@ -1,5 +1,5 @@ -cd36f114d163e2cd93e6e80a68726170 *tests/data/fate/mov-mp4-iamf-stereo.mp4 -15138 tests/data/fate/mov-mp4-iamf-stereo.mp4 +e3da79a8ab08184a51dd0bc2c752b3b3 *tests/data/fate/mov-mp4-iamf-stereo.mp4 +15130 tests/data/fate/mov-mp4-iamf-stereo.mp4 #extradata 0: 34, 0xa77c0cd6 #tb 0: 1/44100 #media_type 0: audio @@ -16,7 +16,7 @@ cd36f114d163e2cd93e6e80a68726170 *tests/data/fate/mov-mp4-iamf-stereo.mp4 0, 28672, 28672, 4096, 1313, 0x2e79ffa2 0, 32768, 32768, 4096, 1323, 0xb9f70fce 0, 36864, 36864, 4096, 1254, 0xf6f01051 -0, 40960, 40960, 3140, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf +0, 40960, 40960, 4096, 1235, 0xcf181f77, S=1, Skip Samples, 10, 0x047700bf [STREAM_GROUP] index=0 id=0x1 -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
