Commit 58a29a16af for ffmpeg
commit 58a29a16afdec9ac4d3ad4f35e3efc64029d6d6a
Author: James Almer <jamrial@gmail.com>
Date: Tue Dec 1 18:02:29 2026 -0300
avformat/matroskadec: mark blocks made from disposable packets as discardable
Signed-off-by: James Almer <jamrial@gmail.com>
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 136f3a1923..5d2af5f3da 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -3016,9 +3016,11 @@ static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv,
writer.elements[0].id = MATROSKA_ID_SIMPLEBLOCK;
if (keyframe)
mkv->cur_block.flags |= 1 << 7;
+ if (pkt->flags & AV_PKT_FLAG_DISPOSABLE)
+ mkv->cur_block.flags |= 1;
} else if (!keyframe)
ebml_writer_add_sint(&writer, MATROSKA_ID_BLOCKREFERENCE,
- track->last_timestamp - ts);
+ (pkt->flags & AV_PKT_FLAG_DISPOSABLE) ? 0 : track->last_timestamp - ts);
ret = ebml_writer_write(&writer, pb);
@@ -3128,6 +3130,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
int is_sub = par->codec_type == AVMEDIA_TYPE_SUBTITLE;
/* All subtitle blocks are considered to be keyframes. */
int keyframe = is_sub || !!(pkt->flags & AV_PKT_FLAG_KEY);
+ int discardable = !!(pkt->flags & AV_PKT_FLAG_DISPOSABLE);
int64_t duration = FFMAX(pkt->duration, 0);
int64_t cue_duration = is_sub ? duration : 0;
int ret;
@@ -3194,7 +3197,8 @@ static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
track->has_cue = 1;
}
- track->last_timestamp = ts;
+ if (!discardable)
+ track->last_timestamp = ts;
mkv->duration = FFMAX(mkv->duration, ts + duration);
track->duration = FFMAX(track->duration, ts + duration);
diff --git a/tests/ref/fate/matroska-dovi-write-config8 b/tests/ref/fate/matroska-dovi-write-config8
index 90299b5118..a6341257c3 100644
--- a/tests/ref/fate/matroska-dovi-write-config8
+++ b/tests/ref/fate/matroska-dovi-write-config8
@@ -1,5 +1,5 @@
-fbb499078b671ad012c1bbd5ec7b78e2 *tests/data/fate/matroska-dovi-write-config8.matroska
-3601876 tests/data/fate/matroska-dovi-write-config8.matroska
+7473c6d70d3fe871d8ac00d24db4bcac *tests/data/fate/matroska-dovi-write-config8.matroska
+3601827 tests/data/fate/matroska-dovi-write-config8.matroska
#extradata 0: 551, 0xb1ddcd66
#extradata 1: 2, 0x00340022
#tb 0: 1/100000
@@ -17,9 +17,9 @@ fbb499078b671ad012c1bbd5ec7b78e2 *tests/data/fate/matroska-dovi-write-config8.ma
0, 0, 6667, 3333, 29766, 0x753c031a, F=0x0
1, 0, 0, 2322, 6, 0x031e0108
1, 2322, 2322, 2322, 251, 0x6b4a7cbd
-0, 3333, 3333, 3333, 19409, 0x4b948b6c, F=0x0
+0, 3333, 3333, 3333, 19409, 0x4b948b6c, F=0x10
1, 4644, 4644, 2322, 389, 0x6673c205
-0, 6667, 10000, 3333, 21086, 0x1b9412ce, F=0x0
+0, 6667, 10000, 3333, 21086, 0x1b9412ce, F=0x10
1, 6966, 6966, 2322, 356, 0x8c71a316
1, 9288, 9288, 2322, 339, 0x3018a45a
0, 10000, 26667, 3333, 62043, 0xc2356b56, F=0x0
@@ -27,19 +27,19 @@ fbb499078b671ad012c1bbd5ec7b78e2 *tests/data/fate/matroska-dovi-write-config8.ma
0, 13333, 20000, 3333, 36175, 0x0a7df38c, F=0x0
1, 13932, 13932, 2322, 449, 0x42eadf96
1, 16254, 16254, 2322, 416, 0x28a7c9b9
-0, 16667, 16667, 3333, 16028, 0xa57fcbe9, F=0x0
+0, 16667, 16667, 3333, 16028, 0xa57fcbe9, F=0x10
1, 18576, 18576, 2322, 426, 0x9a74d4ec
-0, 20000, 23333, 3333, 15428, 0x9a91f357, F=0x0
+0, 20000, 23333, 3333, 15428, 0x9a91f357, F=0x10
1, 20898, 20898, 2322, 419, 0xbe3dc54b
1, 23220, 23220, 2322, 424, 0x5102d50e
0, 23333, 40000, 3333, 66072, 0xa542b6d7, F=0x0
1, 25542, 25542, 2322, 402, 0xb11cc14c
0, 26667, 33333, 3333, 34985, 0xbfd8ff45, F=0x0
1, 27864, 27864, 2322, 401, 0x3820b8f9
-0, 30000, 30000, 3333, 16036, 0xfc39c6ea, F=0x0
+0, 30000, 30000, 3333, 16036, 0xfc39c6ea, F=0x10
1, 30186, 30186, 2322, 400, 0xe5c4c168
1, 32508, 32508, 2322, 435, 0x6dbecc33
-0, 33333, 36667, 3333, 19893, 0x7e746f4e, F=0x0
+0, 33333, 36667, 3333, 19893, 0x7e746f4e, F=0x10
1, 34830, 34830, 2322, 441, 0x0ad3d199
0, 36667, 53333, 3333, 77576, 0xeba2e5c8, F=0x0
1, 37152, 37152, 2322, 479, 0x44dce967