diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 3b0998ecc8..0f292eb5b6 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -44,6 +44,7 @@
 #include "libavutil/channel_layout.h"
 #include "libavutil/crc.h"
 #include "libavutil/dict.h"
+#include "libavutil/hdr_dynamic_metadata.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/lfg.h"
@@ -1612,6 +1613,10 @@ static void mkv_write_blockadditionmapping(AVFormatContext *s, MatroskaMuxContex
         // we either write the default value here, or a void element. Either of them will
         // be overwritten when finishing the track.
         put_ebml_uint(mkv->track.bc, MATROSKA_ID_TRACKMAXBLKADDID, 0);
+        // Similarly, reserve space for an eventual HDR10+ ITU T.35 metadata BlockAdditionMapping.
+        put_ebml_void(pb, 3 /* BlockAdditionMapping */
+                        + 4 /* BlockAddIDValue */
+                        + 4 /* BlockAddIDType */);
     }
 
     if (dovi && dovi->dv_profile <= 10) {
@@ -2618,17 +2623,27 @@ static int webm_reformat_vtt(MatroskaMuxContext *mkv, AVIOContext *pb,
     return 0;
 }
 
+static void mkv_write_blockadditional(EbmlWriter *writer, const uint8_t *buf,
+                                      size_t size, uint64_t additional_id)
+{
+    ebml_writer_open_master(writer, MATROSKA_ID_BLOCKMORE);
+    ebml_writer_add_uint(writer, MATROSKA_ID_BLOCKADDID, additional_id);
+    ebml_writer_add_bin (writer, MATROSKA_ID_BLOCKADDITIONAL, buf, size);
+    ebml_writer_close_master(writer);
+}
+
 static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv,
                            AVIOContext *pb, const AVCodecParameters *par,
                            mkv_track *track, const AVPacket *pkt,
                            int keyframe, int64_t ts, uint64_t duration,
                            int force_blockgroup, int64_t relative_packet_pos)
 {
-    uint8_t *side_data;
+    uint8_t *side_data, *buf = NULL;
     size_t side_data_size;
     uint64_t additional_id;
     unsigned track_number = track->track_num;
-    EBML_WRITER(9);
+    int ret;
+    EBML_WRITER(13);
 
     mkv->cur_block.track  = track;
     mkv->cur_block.pkt    = pkt;
@@ -2663,24 +2678,52 @@ static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv,
         }
     }
 
+    ebml_writer_open_master(&writer, MATROSKA_ID_BLOCKADDITIONS);
     side_data = av_packet_get_side_data(pkt,
                                         AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
                                         &side_data_size);
     if (side_data && side_data_size >= 8 &&
         // Only the Codec-specific BlockMore (id == 1) is currently supported.
         (additional_id = AV_RB64(side_data)) == MATROSKA_BLOCK_ADD_ID_TYPE_OPAQUE) {
-        ebml_writer_open_master(&writer, MATROSKA_ID_BLOCKADDITIONS);
-        ebml_writer_open_master(&writer, MATROSKA_ID_BLOCKMORE);
-        /* Until dbc50f8a our demuxer used a wrong default value
-         * of BlockAddID, so we write it unconditionally. */
-        ebml_writer_add_uint(&writer, MATROSKA_ID_BLOCKADDID, additional_id);
-        ebml_writer_add_bin (&writer, MATROSKA_ID_BLOCKADDITIONAL,
-                             side_data + 8, side_data_size - 8);
-        ebml_writer_close_master(&writer);
-        ebml_writer_close_master(&writer);
-        track->max_blockaddid = additional_id;
+        mkv_write_blockadditional(&writer, side_data + 8, side_data_size - 8,
+                                  additional_id);
+        track->max_blockaddid = FFMAX(track->max_blockaddid, additional_id);
     }
 
+    side_data = av_packet_get_side_data(pkt,
+                                        AV_PKT_DATA_DYNAMIC_HDR10_PLUS,
+                                        &side_data_size);
+    if (side_data && side_data_size) {
+        uint8_t *payload;
+        size_t payload_size, buf_size;
+        int ret = av_dynamic_hdr_plus_to_t35((AVDynamicHDRPlus *)side_data, &payload,
+                                             &payload_size);
+        if (ret < 0)
+            return ret;
+
+        buf_size = payload_size + 6;
+        buf = av_malloc(buf_size);
+        if (!buf) {
+            av_free(payload);
+            return AVERROR(ENOMEM);
+        }
+
+        AV_WB8 (buf + 0, 0xB5); // country_code
+        AV_WB16(buf + 1, 0x3C); // provider_code
+        AV_WB16(buf + 3, 0x01); // provider_oriented_code
+        AV_WB8 (buf + 5, 0x04); // application_identifier
+        memcpy(buf + 6, payload, payload_size);
+
+        mkv_write_blockadditional(&writer, buf, buf_size,
+                                  MATROSKA_BLOCK_ADD_ID_ITU_T_T35);
+        track->max_blockaddid = FFMAX(track->max_blockaddid,
+                                      MATROSKA_BLOCK_ADD_ID_ITU_T_T35);
+
+        av_free(payload);
+    }
+
+    ebml_writer_close_or_discard_master(&writer);
+
     if (!force_blockgroup && writer.nb_elements == 2) {
         /* Nothing except the BlockGroup + Block. Can use a SimpleBlock. */
         writer.elements++;    // Skip the BlockGroup.
@@ -2693,7 +2736,10 @@ static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv,
         ebml_writer_add_sint(&writer, MATROSKA_ID_BLOCKREFERENCE,
                              track->last_timestamp - ts);
 
-    return ebml_writer_write(&writer, pb);
+    ret = ebml_writer_write(&writer, pb);
+    av_free(buf);
+
+    return ret;
 }
 
 static int mkv_end_cluster(AVFormatContext *s)
@@ -3095,6 +3141,12 @@ after_cues:
                 avio_seek(mkv->track.bc, track->blockadditionmapping_offset, SEEK_SET);
 
                 put_ebml_uint(mkv->track.bc, MATROSKA_ID_TRACKMAXBLKADDID, track->max_blockaddid);
+                if (track->max_blockaddid == MATROSKA_BLOCK_ADD_ID_ITU_T_T35) {
+                    ebml_master mapping_master = start_ebml_master(mkv->track.bc, MATROSKA_ID_TRACKBLKADDMAPPING, 8);
+                    put_ebml_uint(mkv->track.bc, MATROSKA_ID_BLKADDIDTYPE, MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35);
+                    put_ebml_uint(mkv->track.bc, MATROSKA_ID_BLKADDIDVALUE, MATROSKA_BLOCK_ADD_ID_ITU_T_T35);
+                    end_ebml_master(mkv->track.bc, mapping_master);
+                }
             }
 
         avio_seek(pb, mkv->track.pos, SEEK_SET);
diff --git a/tests/ref/fate/aac-autobsf-adtstoasc b/tests/ref/fate/aac-autobsf-adtstoasc
index 76125083b6..12b80ef6bd 100644
--- a/tests/ref/fate/aac-autobsf-adtstoasc
+++ b/tests/ref/fate/aac-autobsf-adtstoasc
@@ -1,5 +1,5 @@
-3d4465a7ea2cfba31af737e288c892fe *tests/data/fate/aac-autobsf-adtstoasc.matroska
-6646 tests/data/fate/aac-autobsf-adtstoasc.matroska
+68cb46874ca6029d3ae3a184b4a71b04 *tests/data/fate/aac-autobsf-adtstoasc.matroska
+6657 tests/data/fate/aac-autobsf-adtstoasc.matroska
 #extradata 0:        2, 0x0030001c
 #tb 0: 1/1000
 #media_type 0: audio
diff --git a/tests/ref/fate/matroska-avoid-negative-ts b/tests/ref/fate/matroska-avoid-negative-ts
index 73616cbc5a..dcde937d52 100644
--- a/tests/ref/fate/matroska-avoid-negative-ts
+++ b/tests/ref/fate/matroska-avoid-negative-ts
@@ -1,5 +1,5 @@
-ff83530bf89f9ab1df0d181bb848c475 *tests/data/fate/matroska-avoid-negative-ts.matroska
-973063 tests/data/fate/matroska-avoid-negative-ts.matroska
+6a1a524a5700de7b94bce5a283bbe8b9 *tests/data/fate/matroska-avoid-negative-ts.matroska
+973085 tests/data/fate/matroska-avoid-negative-ts.matroska
 #extradata 0:       22, 0x2885037c
 #tb 0: 1/1000
 #media_type 0: video
diff --git a/tests/ref/fate/matroska-dovi-write-config7 b/tests/ref/fate/matroska-dovi-write-config7
index 8b40848f4a..ef4c87d885 100644
--- a/tests/ref/fate/matroska-dovi-write-config7
+++ b/tests/ref/fate/matroska-dovi-write-config7
@@ -1,5 +1,5 @@
-b4db571fe6304f159a0383a38c9c0cee *tests/data/fate/matroska-dovi-write-config7.matroska
-72680 tests/data/fate/matroska-dovi-write-config7.matroska
+82581e39700ff479516c33402e8b1d5d *tests/data/fate/matroska-dovi-write-config7.matroska
+72702 tests/data/fate/matroska-dovi-write-config7.matroska
 #extradata 0:      116, 0x2b8d1669
 #extradata 1:      116, 0x2b8d1669
 #tb 0: 1/1000
diff --git a/tests/ref/fate/matroska-dovi-write-config8 b/tests/ref/fate/matroska-dovi-write-config8
index c36d3a8a07..bb22563eee 100644
--- a/tests/ref/fate/matroska-dovi-write-config8
+++ b/tests/ref/fate/matroska-dovi-write-config8
@@ -1,5 +1,5 @@
-8c77c1d18ee58a8923c411d3ba006a46 *tests/data/fate/matroska-dovi-write-config8.matroska
-3600584 tests/data/fate/matroska-dovi-write-config8.matroska
+09ff3c0a038eec0cdf4773929b24f41a *tests/data/fate/matroska-dovi-write-config8.matroska
+3600606 tests/data/fate/matroska-dovi-write-config8.matroska
 #extradata 0:      551, 0xa18acf66
 #extradata 1:        2, 0x00340022
 #tb 0: 1/1000
diff --git a/tests/ref/fate/matroska-dvbsub-remux b/tests/ref/fate/matroska-dvbsub-remux
index 03341d9668..b5bb028343 100644
--- a/tests/ref/fate/matroska-dvbsub-remux
+++ b/tests/ref/fate/matroska-dvbsub-remux
@@ -1,5 +1,5 @@
-5d1591e9abd7e1373d43bc776572aaf7 *tests/data/fate/matroska-dvbsub-remux.matroska
-39018 tests/data/fate/matroska-dvbsub-remux.matroska
+7154511243fd7edb695c159bb12a0948 *tests/data/fate/matroska-dvbsub-remux.matroska
+39041 tests/data/fate/matroska-dvbsub-remux.matroska
 #extradata 0:        5, 0x00bb0064
 #extradata 1:        5, 0x00bb0064
 #tb 0: 1/1000
diff --git a/tests/ref/fate/matroska-encoding-delay b/tests/ref/fate/matroska-encoding-delay
index 401de4facf..086fe94e93 100644
--- a/tests/ref/fate/matroska-encoding-delay
+++ b/tests/ref/fate/matroska-encoding-delay
@@ -1,5 +1,5 @@
-1f6f9c0fbaba0f128acbea296cec1887 *tests/data/fate/matroska-encoding-delay.matroska
-961229 tests/data/fate/matroska-encoding-delay.matroska
+ce2ab14d45217a043f9f50fe6adfe5ce *tests/data/fate/matroska-encoding-delay.matroska
+961251 tests/data/fate/matroska-encoding-delay.matroska
 #extradata 0:       22, 0x32ea0490
 #tb 0: 1/1000
 #media_type 0: video
@@ -32,7 +32,7 @@ dts_time=-0.010000
 duration=24
 duration_time=0.024000
 size=1152
-pos=1246
+pos=1268
 flags=K__
 [/PACKET]
 [PACKET]
@@ -45,7 +45,7 @@ dts_time=0.000000
 duration=40
 duration_time=0.040000
 size=237628
-pos=2406
+pos=2428
 flags=K__
 [/PACKET]
 [PACKET]
@@ -58,7 +58,7 @@ dts_time=0.014000
 duration=24
 duration_time=0.024000
 size=1152
-pos=240041
+pos=240063
 flags=K__
 [/PACKET]
 [PACKET]
@@ -71,7 +71,7 @@ dts_time=0.038000
 duration=24
 duration_time=0.024000
 size=1152
-pos=241216
+pos=241238
 flags=K__
 [/PACKET]
 [PACKET]
@@ -84,7 +84,7 @@ dts_time=0.040000
 duration=40
 duration_time=0.040000
 size=238066
-pos=242376
+pos=242398
 flags=K__
 [/PACKET]
 [STREAM]
diff --git a/tests/ref/fate/matroska-flac-extradata-update b/tests/ref/fate/matroska-flac-extradata-update
index d6713aaafa..37e0367297 100644
--- a/tests/ref/fate/matroska-flac-extradata-update
+++ b/tests/ref/fate/matroska-flac-extradata-update
@@ -1,5 +1,5 @@
-fdbfdc51b519fd5e8f425aca1e7b8704 *tests/data/fate/matroska-flac-extradata-update.matroska
-1807 tests/data/fate/matroska-flac-extradata-update.matroska
+8a75767c14e63e7d15291c5c4918a661 *tests/data/fate/matroska-flac-extradata-update.matroska
+1840 tests/data/fate/matroska-flac-extradata-update.matroska
 #extradata 0:       34, 0x93650c81
 #extradata 1:       34, 0x93650c81
 #extradata 2:       34, 0x93650c81
diff --git a/tests/ref/fate/matroska-h264-remux b/tests/ref/fate/matroska-h264-remux
index 9a9a98217c..bfc80a273f 100644
--- a/tests/ref/fate/matroska-h264-remux
+++ b/tests/ref/fate/matroska-h264-remux
@@ -1,5 +1,5 @@
-fa3352ef6d3abd7d93f8627981a53f6f *tests/data/fate/matroska-h264-remux.matroska
-2036049 tests/data/fate/matroska-h264-remux.matroska
+38ede644af311f443d7446600f25a8e3 *tests/data/fate/matroska-h264-remux.matroska
+2036093 tests/data/fate/matroska-h264-remux.matroska
 #tb 0: 1/25
 #media_type 0: video
 #codec_id 0: rawvideo
diff --git a/tests/ref/fate/matroska-mastering-display-metadata b/tests/ref/fate/matroska-mastering-display-metadata
index 95df3594c7..c63365c181 100644
--- a/tests/ref/fate/matroska-mastering-display-metadata
+++ b/tests/ref/fate/matroska-mastering-display-metadata
@@ -1,5 +1,5 @@
-e9a5f7314d6ae2ef16713335df2b5903 *tests/data/fate/matroska-mastering-display-metadata.matroska
-1669571 tests/data/fate/matroska-mastering-display-metadata.matroska
+a4924bfe22ed0c72b0eddc353bbee10c *tests/data/fate/matroska-mastering-display-metadata.matroska
+1669615 tests/data/fate/matroska-mastering-display-metadata.matroska
 #extradata 0:        4, 0x040901a3
 #extradata 3:      200, 0x506463a8
 #tb 0: 1/1000
diff --git a/tests/ref/fate/matroska-move-cues-to-front b/tests/ref/fate/matroska-move-cues-to-front
index 79ccc2fd93..ce3b9fce92 100644
--- a/tests/ref/fate/matroska-move-cues-to-front
+++ b/tests/ref/fate/matroska-move-cues-to-front
@@ -1,5 +1,5 @@
-74a5ed3f0b14112322c8bf3e94d6e98b *tests/data/fate/matroska-move-cues-to-front.matroska
-23210297 tests/data/fate/matroska-move-cues-to-front.matroska
+03ed7fcf99dd993ebb9bc9c6c93ba73e *tests/data/fate/matroska-move-cues-to-front.matroska
+23210319 tests/data/fate/matroska-move-cues-to-front.matroska
 #tb 0: 1/1000
 #media_type 0: audio
 #codec_id 0: pcm_s24be
diff --git a/tests/ref/fate/matroska-mpegts-remux b/tests/ref/fate/matroska-mpegts-remux
index af41b57af1..1f211dfc29 100644
--- a/tests/ref/fate/matroska-mpegts-remux
+++ b/tests/ref/fate/matroska-mpegts-remux
@@ -1,5 +1,5 @@
-ca1b91e49b6e238b641007c186d8f424 *tests/data/fate/matroska-mpegts-remux.matroska
-6502 tests/data/fate/matroska-mpegts-remux.matroska
+53424355db1d78441b62ad114d6ea502 *tests/data/fate/matroska-mpegts-remux.matroska
+6524 tests/data/fate/matroska-mpegts-remux.matroska
 #tb 0: 1/1000
 #media_type 0: audio
 #codec_id 0: ac3
diff --git a/tests/ref/fate/matroska-ms-mode b/tests/ref/fate/matroska-ms-mode
index 0a42ab0748..b12e9ac9f2 100644
--- a/tests/ref/fate/matroska-ms-mode
+++ b/tests/ref/fate/matroska-ms-mode
@@ -1,5 +1,5 @@
-7f0b825626a028765098222816ba56b8 *tests/data/fate/matroska-ms-mode.matroska
-413094 tests/data/fate/matroska-ms-mode.matroska
+f3b1b804d40d70d012e85ba6d03ea8f1 *tests/data/fate/matroska-ms-mode.matroska
+413116 tests/data/fate/matroska-ms-mode.matroska
 #extradata 0:       40, 0x54290c93
 #extradata 1:      114, 0xb6c80771
 #tb 0: 1/1000
diff --git a/tests/ref/fate/matroska-ogg-opus-remux b/tests/ref/fate/matroska-ogg-opus-remux
index cd3eade361..c70c58a697 100644
--- a/tests/ref/fate/matroska-ogg-opus-remux
+++ b/tests/ref/fate/matroska-ogg-opus-remux
@@ -1,5 +1,5 @@
-b602a1a4aaa4fbca4b8aaf39b66d7235 *tests/data/fate/matroska-ogg-opus-remux.matroska
-10204 tests/data/fate/matroska-ogg-opus-remux.matroska
+d891990279e6ba202448f9fffde52d3f *tests/data/fate/matroska-ogg-opus-remux.matroska
+10215 tests/data/fate/matroska-ogg-opus-remux.matroska
 #extradata 0:       19, 0x399c0471
 #tb 0: 1/1000
 #media_type 0: audio
@@ -57,7 +57,7 @@ dts_time=-0.007000
 duration=20
 duration_time=0.020000
 size=402
-pos=544
+pos=555
 flags=K__
 [/PACKET]
 [PACKET]
@@ -70,7 +70,7 @@ dts_time=0.013000
 duration=20
 duration_time=0.020000
 size=216
-pos=953
+pos=964
 flags=K__
 [/PACKET]
 [PACKET]
@@ -83,7 +83,7 @@ dts_time=0.033000
 duration=20
 duration_time=0.020000
 size=215
-pos=1176
+pos=1187
 flags=K__
 [/PACKET]
 [STREAM]
diff --git a/tests/ref/fate/matroska-opus-remux b/tests/ref/fate/matroska-opus-remux
index 975510e167..f5dcbe164e 100644
--- a/tests/ref/fate/matroska-opus-remux
+++ b/tests/ref/fate/matroska-opus-remux
@@ -1,5 +1,5 @@
-fe0258eb0d4b525203ea240c87a154d3 *tests/data/fate/matroska-opus-remux.matroska
-9359 tests/data/fate/matroska-opus-remux.matroska
+dc14cd32921d86e03c155bb745edf44b *tests/data/fate/matroska-opus-remux.matroska
+9370 tests/data/fate/matroska-opus-remux.matroska
 #extradata 0:       19, 0x3a04048f
 #tb 0: 1/1000
 #media_type 0: audio
@@ -68,7 +68,7 @@ dts_time=-0.007000
 duration=20
 duration_time=0.020000
 size=320
-pos=500
+pos=511
 flags=K__
 [/PACKET]
 [PACKET]
@@ -81,7 +81,7 @@ dts_time=0.014000
 duration=20
 duration_time=0.020000
 size=159
-pos=827
+pos=838
 flags=K__
 [/PACKET]
 [PACKET]
@@ -94,7 +94,7 @@ dts_time=0.034000
 duration=20
 duration_time=0.020000
 size=148
-pos=993
+pos=1004
 flags=K__
 [/PACKET]
 [STREAM]
diff --git a/tests/ref/fate/matroska-pgs-remux b/tests/ref/fate/matroska-pgs-remux
index a086111495..482357b899 100644
--- a/tests/ref/fate/matroska-pgs-remux
+++ b/tests/ref/fate/matroska-pgs-remux
@@ -1,5 +1,5 @@
-d39daa393d66ae0b0c153be045897585 *tests/data/fate/matroska-pgs-remux.matroska
-49748 tests/data/fate/matroska-pgs-remux.matroska
+60161b7f8af39a8d280cc8b1f8693129 *tests/data/fate/matroska-pgs-remux.matroska
+49759 tests/data/fate/matroska-pgs-remux.matroska
 #tb 0: 1/1000
 #media_type 0: subtitle
 #codec_id 0: hdmv_pgs_subtitle
diff --git a/tests/ref/fate/matroska-pgs-remux-durations b/tests/ref/fate/matroska-pgs-remux-durations
index 37494cd98f..6280110948 100644
--- a/tests/ref/fate/matroska-pgs-remux-durations
+++ b/tests/ref/fate/matroska-pgs-remux-durations
@@ -1,5 +1,5 @@
-27af80eecea4f15f415f22841bc699d5 *tests/data/fate/matroska-pgs-remux-durations.matroska
-49760 tests/data/fate/matroska-pgs-remux-durations.matroska
+2c78a4337f61f24175a8ffe06087e581 *tests/data/fate/matroska-pgs-remux-durations.matroska
+49771 tests/data/fate/matroska-pgs-remux-durations.matroska
 #tb 0: 1/1000
 #media_type 0: subtitle
 #codec_id 0: hdmv_pgs_subtitle
diff --git a/tests/ref/fate/matroska-qt-mode b/tests/ref/fate/matroska-qt-mode
index d54f5d167c..e14584893b 100644
--- a/tests/ref/fate/matroska-qt-mode
+++ b/tests/ref/fate/matroska-qt-mode
@@ -1,5 +1,5 @@
-c3483a76cd0bfbaf80a32dad041b6f52 *tests/data/fate/matroska-qt-mode.matroska
-1884232 tests/data/fate/matroska-qt-mode.matroska
+a976ac0fd5c1ca916280f64525d12c10 *tests/data/fate/matroska-qt-mode.matroska
+1884254 tests/data/fate/matroska-qt-mode.matroska
 #extradata 0:       90, 0x817d0185
 #tb 0: 1/1000
 #media_type 0: video
diff --git a/tests/ref/fate/matroska-spherical-mono-remux b/tests/ref/fate/matroska-spherical-mono-remux
index c65d206e91..0940e3ea86 100644
--- a/tests/ref/fate/matroska-spherical-mono-remux
+++ b/tests/ref/fate/matroska-spherical-mono-remux
@@ -1,5 +1,5 @@
-dfc2e196ca14cce155b1a081a0628fd3 *tests/data/fate/matroska-spherical-mono-remux.matroska
-161562 tests/data/fate/matroska-spherical-mono-remux.matroska
+281555d95fca08f3ba103eefa1c22b54 *tests/data/fate/matroska-spherical-mono-remux.matroska
+161584 tests/data/fate/matroska-spherical-mono-remux.matroska
 #extradata 0:       43, 0x2b0e0d7b
 #extradata 1:       43, 0x2b0e0d7b
 #tb 0: 1/1000
diff --git a/tests/ref/fate/matroska-vp8-alpha-remux b/tests/ref/fate/matroska-vp8-alpha-remux
index 1fad574edd..86024b3477 100644
--- a/tests/ref/fate/matroska-vp8-alpha-remux
+++ b/tests/ref/fate/matroska-vp8-alpha-remux
@@ -1,5 +1,5 @@
-3339f3fa157bdd63f22f5a579f308c89 *tests/data/fate/matroska-vp8-alpha-remux.matroska
-235015 tests/data/fate/matroska-vp8-alpha-remux.matroska
+635702724143e90d2a3ec457f65676cf *tests/data/fate/matroska-vp8-alpha-remux.matroska
+235026 tests/data/fate/matroska-vp8-alpha-remux.matroska
 #tb 0: 1/1000
 #media_type 0: video
 #codec_id 0: vp8
diff --git a/tests/ref/fate/matroska-zero-length-block b/tests/ref/fate/matroska-zero-length-block
index 3987cc14c4..0f90ccbdd7 100644
--- a/tests/ref/fate/matroska-zero-length-block
+++ b/tests/ref/fate/matroska-zero-length-block
@@ -1,5 +1,5 @@
-f577fad2fff41d6e055f605281582b8d *tests/data/fate/matroska-zero-length-block.matroska
-634 tests/data/fate/matroska-zero-length-block.matroska
+b9a8a67ffdba18eec1c04827d3d404ca *tests/data/fate/matroska-zero-length-block.matroska
+645 tests/data/fate/matroska-zero-length-block.matroska
 #tb 0: 1/1000
 #media_type 0: subtitle
 #codec_id 0: subrip
diff --git a/tests/ref/fate/rgb24-mkv b/tests/ref/fate/rgb24-mkv
index d037c01b32..484198aaa4 100644
--- a/tests/ref/fate/rgb24-mkv
+++ b/tests/ref/fate/rgb24-mkv
@@ -1,5 +1,5 @@
-69dc9d35fdfadccb28c7baf401776ec3 *tests/data/fate/rgb24-mkv.matroska
-58215 tests/data/fate/rgb24-mkv.matroska
+4801308890e7a9db51fc13b05f817165 *tests/data/fate/rgb24-mkv.matroska
+58226 tests/data/fate/rgb24-mkv.matroska
 #tb 0: 1/10
 #media_type 0: video
 #codec_id 0: rawvideo
diff --git a/tests/ref/fate/shortest-sub b/tests/ref/fate/shortest-sub
index b6571b4f32..4db0e13328 100644
--- a/tests/ref/fate/shortest-sub
+++ b/tests/ref/fate/shortest-sub
@@ -1,5 +1,5 @@
-d334a0eee71351ddad0a63011107909f *tests/data/fate/shortest-sub.matroska
-139240 tests/data/fate/shortest-sub.matroska
+791a2ce136bef538491bbe31ac0134b1 *tests/data/fate/shortest-sub.matroska
+139262 tests/data/fate/shortest-sub.matroska
 #extradata 1:      167, 0xf7272d5f
 #tb 0: 1/1000
 #media_type 0: video
diff --git a/tests/ref/lavf-fate/av1.mkv b/tests/ref/lavf-fate/av1.mkv
index 382e3aeee3..685fd70811 100644
--- a/tests/ref/lavf-fate/av1.mkv
+++ b/tests/ref/lavf-fate/av1.mkv
@@ -1,3 +1,3 @@
-7d2c39dd98d5776425a4015e1eead6c6 *tests/data/lavf-fate/lavf.av1.mkv
-55646 tests/data/lavf-fate/lavf.av1.mkv
+279268e8d6ffcc2299e725a756bbb1a0 *tests/data/lavf-fate/lavf.av1.mkv
+55657 tests/data/lavf-fate/lavf.av1.mkv
 tests/data/lavf-fate/lavf.av1.mkv CRC=0x7c27cc15
diff --git a/tests/ref/lavf/mka b/tests/ref/lavf/mka
index 93a0b8f71a..40b1f07f9b 100644
--- a/tests/ref/lavf/mka
+++ b/tests/ref/lavf/mka
@@ -1,3 +1,3 @@
-77db16a9fe1c42a230c85124bfb40cad *tests/data/lavf/lavf.mka
-43573 tests/data/lavf/lavf.mka
+dffd74918d13be7dd07e83832de3a15c *tests/data/lavf/lavf.mka
+43584 tests/data/lavf/lavf.mka
 tests/data/lavf/lavf.mka CRC=0x3a1da17e
diff --git a/tests/ref/lavf/mkv b/tests/ref/lavf/mkv
index fbd40fc1cb..0aeb7cfae6 100644
--- a/tests/ref/lavf/mkv
+++ b/tests/ref/lavf/mkv
@@ -1,3 +1,3 @@
-32b87b6adbe76df1008bc074f82fabb0 *tests/data/lavf/lavf.mkv
-320417 tests/data/lavf/lavf.mkv
+fde4f0580865684b878f0e13997213af *tests/data/lavf/lavf.mkv
+320439 tests/data/lavf/lavf.mkv
 tests/data/lavf/lavf.mkv CRC=0xec6c3c68
diff --git a/tests/ref/lavf/mkv_attachment b/tests/ref/lavf/mkv_attachment
index 2966a827cc..6ab72b9a45 100644
--- a/tests/ref/lavf/mkv_attachment
+++ b/tests/ref/lavf/mkv_attachment
@@ -1,3 +1,3 @@
-41739c51209d94b4763f9dbe4d1e1dc9 *tests/data/lavf/lavf.mkv_attachment
-472567 tests/data/lavf/lavf.mkv_attachment
+c75c844f592d44c2a79ff5fc1e8179e0 *tests/data/lavf/lavf.mkv_attachment
+472589 tests/data/lavf/lavf.mkv_attachment
 tests/data/lavf/lavf.mkv_attachment CRC=0xec6c3c68
diff --git a/tests/ref/seek/lavf-mkv b/tests/ref/seek/lavf-mkv
index 06ba6e0380..90d91e3968 100644
--- a/tests/ref/seek/lavf-mkv
+++ b/tests/ref/seek/lavf-mkv
@@ -1,48 +1,48 @@
-ret: 0         st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos:    665 size:   208
+ret: 0         st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos:    687 size:   208
 ret: 0         st:-1 flags:0  ts:-1.000000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    881 size: 27837
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    903 size: 27837
 ret: 0         st:-1 flags:1  ts: 1.894167
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292297 size: 27834
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292319 size: 27834
 ret: 0         st: 0 flags:0  ts: 0.788000
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292297 size: 27834
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292319 size: 27834
 ret: 0         st: 0 flags:1  ts:-0.317000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    881 size: 27837
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    903 size: 27837
 ret:-1         st: 1 flags:0  ts: 2.577000
 ret: 0         st: 1 flags:1  ts: 1.471000
-ret: 0         st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320138 size:   209
+ret: 0         st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320160 size:   209
 ret: 0         st:-1 flags:0  ts: 0.365002
-ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146849 size: 27925
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146871 size: 27925
 ret: 0         st:-1 flags:1  ts:-0.740831
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    881 size: 27837
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    903 size: 27837
 ret:-1         st: 0 flags:0  ts: 2.153000
 ret: 0         st: 0 flags:1  ts: 1.048000
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292297 size: 27834
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292319 size: 27834
 ret: 0         st: 1 flags:0  ts:-0.058000
-ret: 0         st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos:    665 size:   208
+ret: 0         st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos:    687 size:   208
 ret: 0         st: 1 flags:1  ts: 2.836000
-ret: 0         st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320138 size:   209
+ret: 0         st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320160 size:   209
 ret:-1         st:-1 flags:0  ts: 1.730004
 ret: 0         st:-1 flags:1  ts: 0.624171
-ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146849 size: 27925
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146871 size: 27925
 ret: 0         st: 0 flags:0  ts:-0.482000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    881 size: 27837
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    903 size: 27837
 ret: 0         st: 0 flags:1  ts: 2.413000
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292297 size: 27834
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292319 size: 27834
 ret:-1         st: 1 flags:0  ts: 1.307000
 ret: 0         st: 1 flags:1  ts: 0.201000
-ret: 0         st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos:    665 size:   208
+ret: 0         st: 1 flags:1 dts:-0.011000 pts:-0.011000 pos:    687 size:   208
 ret: 0         st:-1 flags:0  ts:-0.904994
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    881 size: 27837
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    903 size: 27837
 ret: 0         st:-1 flags:1  ts: 1.989173
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292297 size: 27834
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292319 size: 27834
 ret: 0         st: 0 flags:0  ts: 0.883000
-ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292297 size: 27834
+ret: 0         st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 292319 size: 27834
 ret: 0         st: 0 flags:1  ts:-0.222000
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    881 size: 27837
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    903 size: 27837
 ret:-1         st: 1 flags:0  ts: 2.672000
 ret: 0         st: 1 flags:1  ts: 1.566000
-ret: 0         st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320138 size:   209
+ret: 0         st: 1 flags:1 dts: 0.982000 pts: 0.982000 pos: 320160 size:   209
 ret: 0         st:-1 flags:0  ts: 0.460008
-ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146849 size: 27925
+ret: 0         st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146871 size: 27925
 ret: 0         st:-1 flags:1  ts:-0.645825
-ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    881 size: 27837
+ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    903 size: 27837
