diff --git a/tests/fate/avformat.mak b/tests/fate/avformat.mak
index 3760e41..3d0d52b 100644
--- a/tests/fate/avformat.mak
+++ b/tests/fate/avformat.mak
@@ -80,3 +80,59 @@ $(FATE_LAVF_FATE): CMD = lavffatetest
 
 FATE_SAMPLES_FFMPEG += $(FATE_LAVF_FATE)
 fate-lavf-fate:        $(FATE_LAVF_FATE)
+
+tests/data/mp4-to-ts.m3u8: TAG = GEN
+tests/data/mp4-to-ts.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+        -i $(TARGET_SAMPLES)/h264/interlaced_crop.mp4 \
+        -f ssegment -segment_time 1 -map 0 -flags +bitexact -codec copy \
+        -segment_list $(TARGET_PATH)/$@ -y $(TARGET_PATH)/tests/data/mp4-to-ts-%03d.ts 2>/dev/null
+
+tests/data/adts-to-mkv.m3u8: TAG = GEN
+tests/data/adts-to-mkv.m3u8: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+        -i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts \
+        -f segment -segment_time 1 -map 0 -flags +bitexact -codec copy -segment_format_options live=1 \
+        -segment_list $(TARGET_PATH)/$@ -y $(TARGET_PATH)/tests/data/adts-to-mkv-%03d.mkv 2>/dev/null
+
+tests/data/adts-to-mkv-header.mkv: TAG = GEN
+tests/data/adts-to-mkv-header.mkv: ffmpeg$(PROGSSUF)$(EXESUF) | tests/data
+	$(M)$(TARGET_EXEC) $(TARGET_PATH)/$< \
+        -i $(TARGET_SAMPLES)/audiomatch/tones_afconvert_16000_mono_aac_lc.adts \
+        -f segment -segment_time 1 -map 0 -flags +bitexact -codec copy -segment_format_options live=1 \
+        -segment_header_filename $(TARGET_PATH)/tests/data/adts-to-mkv-header.mkv \
+        -y $(TARGET_PATH)/tests/data/adts-to-mkv-header-%03d.mkv 2>/dev/null
+
+tests/data/adts-to-mkv-header-%.mkv: tests/data/adts-to-mkv-header.mkv ;
+
+FATE_SEGMENT_PARTS += 000 001 002
+
+tests/data/adts-to-mkv-cated-all.mkv: TAG = GEN
+tests/data/adts-to-mkv-cated-all.mkv: tests/data/adts-to-mkv-header.mkv $(FATE_SEGMENT_PARTS:%=tests/data/adts-to-mkv-header-%.mkv) | tests/data
+	$(M)cat $^ >$@
+
+tests/data/adts-to-mkv-cated-%.mkv: TAG = GEN
+tests/data/adts-to-mkv-cated-%.mkv: tests/data/adts-to-mkv-header.mkv tests/data/adts-to-mkv-header-%.mkv | tests/data
+	$(M)cat $^ >$@
+
+FATE_SEGMENT += fate-segment-mp4-to-ts
+fate-segment-mp4-to-ts: tests/data/mp4-to-ts.m3u8
+fate-segment-mp4-to-ts: CMD = framecrc -flags +bitexact -i $(TARGET_PATH)/tests/data/mp4-to-ts.m3u8
+FATE_SEGMENT-$(call ALLYES, MOV_DEMUXER H264_MP4TOANNEXB_BSF MPEGTS_MUXER MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += fate-segment-mp4-to-ts
+
+FATE_SEGMENT += fate-segment-adts-to-mkv
+fate-segment-adts-to-mkv: tests/data/adts-to-mkv.m3u8
+fate-segment-adts-to-mkv: CMD = framecrc -flags +bitexact -i $(TARGET_PATH)/tests/data/adts-to-mkv.m3u8
+fate-segment-adts-to-mkv: REF = tests/ref/fate/segment-adts-to-mkv-header-all
+FATE_SEGMENT-$(call ALLYES, AAC_DEMUXER AAC_ADTSTOASC_BSF MATROSKA_MUXER MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += fate-segment-adts-to-mkv
+
+FATE_SEGMENT_ALLPARTS = $(FATE_SEGMENT_PARTS)
+FATE_SEGMENT_ALLPARTS += all
+FATE_SEGMENT_SPLIT += $(FATE_SEGMENT_ALLPARTS:%=fate-segment-adts-to-mkv-header-%)
+$(foreach N,$(FATE_SEGMENT_ALLPARTS),$(eval $(N:%=fate-segment-adts-to-mkv-header-%): tests/data/adts-to-mkv-cated-$(N).mkv))
+fate-segment-adts-to-mkv-header-%: CMD = framecrc -flags +bitexact -i $(TARGET_PATH)/tests/data/$(@:fate-segment-adts-to-mkv-header-%=adts-to-mkv-cated-%).mkv
+FATE_SEGMENT-$(call ALLYES, AAC_DEMUXER AAC_ADTSTOASC_BSF MATROSKA_MUXER MATROSKA_DEMUXER SEGMENT_MUXER HLS_DEMUXER) += $(FATE_SEGMENT_SPLIT)
+
+FATE_SAMPLES_FFMPEG += $(FATE_SEGMENT-yes)
+
+fate-segment: $(FATE_SEGMENT-yes)
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-000 b/tests/ref/fate/segment-adts-to-mkv-header-000
new file mode 100644
index 0000000..cc38a08
--- /dev/null
+++ b/tests/ref/fate/segment-adts-to-mkv-header-000
@@ -0,0 +1,20 @@
+#tb 0: 1/16000
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 16000
+#channel_layout 0: 4
+0,          0,          0,     1024,     2048, 0x00000000
+0,       1024,       1024,     1024,     2048, 0xae1f3a0a
+0,       2048,       2048,     1024,     2048, 0x5179fe36
+0,       3072,       3072,     1024,     2048, 0xd079fcb2
+0,       4096,       4096,     1024,     2048, 0x6a270442
+0,       5120,       5120,     1024,     2048, 0xff94df75
+0,       6144,       6144,     1024,     2048, 0x074163e0
+0,       7168,       7168,     1024,     2048, 0xc2753c59
+0,       8192,       8192,     1024,     2048, 0xf9bd1697
+0,       9216,       9216,     1024,     2048, 0x1bf1010c
+0,      10240,      10240,     1024,     2048, 0x498bdd5f
+0,      11264,      11264,     1024,     2048, 0x2cdbeddb
+0,      12288,      12288,     1024,     2048, 0xe4f2acb8
+0,      13312,      13312,     1024,     2048, 0xa0cfbfa1
+0,      14336,      14336,     1024,     2048, 0xe2b0ee0e
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-001 b/tests/ref/fate/segment-adts-to-mkv-header-001
new file mode 100644
index 0000000..97bb473
--- /dev/null
+++ b/tests/ref/fate/segment-adts-to-mkv-header-001
@@ -0,0 +1,21 @@
+#tb 0: 1/16000
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 16000
+#channel_layout 0: 4
+0,          0,          0,     1024,     2048, 0xf2b4077a
+0,       1024,       1024,     1024,     2048, 0xd0a70076
+0,       2048,       2048,     1024,     2048, 0x01d1d692
+0,       3072,       3072,     1024,     2048, 0x896f9f22
+0,       4096,       4096,     1024,     2048, 0x4754041c
+0,       5120,       5120,     1024,     2048, 0x5c89f447
+0,       6144,       6144,     1024,     2048, 0x9356087b
+0,       7168,       7168,     1024,     2048, 0xfb5afb0c
+0,       8192,       8192,     1024,     2048, 0xa2ad2aba
+0,       9216,       9216,     1024,     2048, 0x7440413e
+0,      10240,      10240,     1024,     2048, 0x4b96ee99
+0,      11264,      11264,     1024,     2048, 0x0ac31331
+0,      12288,      12288,     1024,     2048, 0x429beaa0
+0,      13312,      13312,     1024,     2048, 0x54dcf1a7
+0,      14336,      14336,     1024,     2048, 0x75de8ecd
+0,      15360,      15360,     1024,     2048, 0x4e6ce5c7
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-002 b/tests/ref/fate/segment-adts-to-mkv-header-002
new file mode 100644
index 0000000..fee717c
--- /dev/null
+++ b/tests/ref/fate/segment-adts-to-mkv-header-002
@@ -0,0 +1,8 @@
+#tb 0: 1/16000
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 16000
+#channel_layout 0: 4
+0,          0,          0,     1024,     2048, 0x0be4055b
+0,       1024,       1024,     1024,     2048, 0xe8a203d3
+0,       2048,       2048,     1024,     2048, 0x86e8f31a
diff --git a/tests/ref/fate/segment-adts-to-mkv-header-all b/tests/ref/fate/segment-adts-to-mkv-header-all
new file mode 100644
index 0000000..292bae7
--- /dev/null
+++ b/tests/ref/fate/segment-adts-to-mkv-header-all
@@ -0,0 +1,39 @@
+#tb 0: 1/16000
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 16000
+#channel_layout 0: 4
+0,          0,          0,     1024,     2048, 0x00000000
+0,       1024,       1024,     1024,     2048, 0xae1f3a0a
+0,       2048,       2048,     1024,     2048, 0x5179fe36
+0,       3072,       3072,     1024,     2048, 0xd079fcb2
+0,       4096,       4096,     1024,     2048, 0x6a270442
+0,       5120,       5120,     1024,     2048, 0xff94df75
+0,       6144,       6144,     1024,     2048, 0x074163e0
+0,       7168,       7168,     1024,     2048, 0xc2753c59
+0,       8192,       8192,     1024,     2048, 0xf9bd1697
+0,       9216,       9216,     1024,     2048, 0x1bf1010c
+0,      10240,      10240,     1024,     2048, 0x498bdd5f
+0,      11264,      11264,     1024,     2048, 0x2cdbeddb
+0,      12288,      12288,     1024,     2048, 0xe4f2acb8
+0,      13312,      13312,     1024,     2048, 0xa0cfbfa1
+0,      14336,      14336,     1024,     2048, 0xe2b0ee0e
+0,      15360,      15360,     1024,     2048, 0xa0a0fac2
+0,      16384,      16384,     1024,     2048, 0xd0a70076
+0,      17408,      17408,     1024,     2048, 0x01d1d692
+0,      18432,      18432,     1024,     2048, 0x896f9f22
+0,      19456,      19456,     1024,     2048, 0x4754041c
+0,      20480,      20480,     1024,     2048, 0x5c89f447
+0,      21504,      21504,     1024,     2048, 0x9356087b
+0,      22528,      22528,     1024,     2048, 0xfb5afb0c
+0,      23552,      23552,     1024,     2048, 0xa2ad2aba
+0,      24576,      24576,     1024,     2048, 0x7440413e
+0,      25600,      25600,     1024,     2048, 0x4b96ee99
+0,      26624,      26624,     1024,     2048, 0x0ac31331
+0,      27648,      27648,     1024,     2048, 0x429beaa0
+0,      28672,      28672,     1024,     2048, 0x54dcf1a7
+0,      29696,      29696,     1024,     2048, 0x75de8ecd
+0,      30720,      30720,     1024,     2048, 0x4e6ce5c7
+0,      31744,      31744,     1024,     2048, 0x44f7e39e
+0,      32768,      32768,     1024,     2048, 0xe8a203d3
+0,      33792,      33792,     1024,     2048, 0x86e8f31a
diff --git a/tests/ref/fate/segment-mp4-to-ts b/tests/ref/fate/segment-mp4-to-ts
new file mode 100644
index 0000000..265f184
--- /dev/null
+++ b/tests/ref/fate/segment-mp4-to-ts
@@ -0,0 +1,131 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 640x360
+#sar 0: 1/1
+0,          0,          0,        1,   345600, 0xa9cb7e5a
+0,          1,          1,        1,   345600, 0x73e47555
+0,          2,          2,        1,   345600, 0x87aac593
+0,          3,          3,        1,   345600, 0x5362a9dd
+0,          4,          4,        1,   345600, 0x46a50284
+0,          5,          5,        1,   345600, 0x79e440a1
+0,          6,          6,        1,   345600, 0xabd7564d
+0,          7,          7,        1,   345600, 0xc68836af
+0,          8,          8,        1,   345600, 0x559f8a80
+0,          9,          9,        1,   345600, 0xce7dcaa5
+0,         10,         10,        1,   345600, 0x1378b1f4
+0,         11,         11,        1,   345600, 0xad94979c
+0,         12,         12,        1,   345600, 0x1e71255a
+0,         13,         13,        1,   345600, 0x65ac7ab1
+0,         14,         14,        1,   345600, 0x0a0c8486
+0,         15,         15,        1,   345600, 0xc326864e
+0,         16,         16,        1,   345600, 0xb76e775d
+0,         17,         17,        1,   345600, 0x8dbb5e66
+0,         18,         18,        1,   345600, 0x21b2e208
+0,         19,         19,        1,   345600, 0x4c3cc396
+0,         20,         20,        1,   345600, 0x10e5a27c
+0,         21,         21,        1,   345600, 0x3435afdb
+0,         22,         22,        1,   345600, 0xb87b814e
+0,         23,         23,        1,   345600, 0x8e600597
+0,         24,         24,        1,   345600, 0xb3e88b8c
+0,         25,         25,        1,   345600, 0xaf6ff85d
+0,         26,         26,        1,   345600, 0x8c9f8b0a
+0,         27,         27,        1,   345600, 0xc6d38731
+0,         28,         28,        1,   345600, 0xe1c1d49e
+0,         29,         29,        1,   345600, 0xa52d82a7
+0,         30,         30,        1,   345600, 0xab3718bc
+0,         31,         31,        1,   345600, 0xb2f1fa8c
+0,         32,         32,        1,   345600, 0x906b103d
+0,         33,         33,        1,   345600, 0x02e78ba2
+0,         34,         34,        1,   345600, 0xf3210219
+0,         35,         35,        1,   345600, 0xbdc8814a
+0,         36,         36,        1,   345600, 0xfecbcc2e
+0,         37,         37,        1,   345600, 0x64952883
+0,         38,         38,        1,   345600, 0xe51657a4
+0,         39,         39,        1,   345600, 0x67731891
+0,         40,         40,        1,   345600, 0x5e1fef0a
+0,         41,         41,        1,   345600, 0x5821d236
+0,         42,         42,        1,   345600, 0x662734e8
+0,         43,         43,        1,   345600, 0xc5dbd34a
+0,         44,         44,        1,   345600, 0x5377f5cc
+0,         45,         45,        1,   345600, 0xe2106227
+0,         46,         46,        1,   345600, 0x0c0c2442
+0,         47,         47,        1,   345600, 0xafc77103
+0,         48,         48,        1,   345600, 0xe7ccee22
+0,         49,         49,        1,   345600, 0x1b7c4d58
+0,         50,         50,        1,   345600, 0x1ccbd381
+0,         51,         51,        1,   345600, 0xc004bac9
+0,         52,         52,        1,   345600, 0x9704cc11
+0,         53,         53,        1,   345600, 0x4df2d481
+0,         54,         54,        1,   345600, 0x2a6112fc
+0,         55,         55,        1,   345600, 0x52d4c65a
+0,         56,         56,        1,   345600, 0x322b7dcc
+0,         57,         57,        1,   345600, 0x94c5b934
+0,         58,         58,        1,   345600, 0xb8a212c3
+0,         59,         59,        1,   345600, 0x860bfc12
+0,         60,         60,        1,   345600, 0x9909e676
+0,         61,         61,        1,   345600, 0xdfaf82e4
+0,         62,         62,        1,   345600, 0x0e679c43
+0,         63,         63,        1,   345600, 0x04625c6f
+0,         64,         64,        1,   345600, 0xdee6716a
+0,         65,         65,        1,   345600, 0xfab06d18
+0,         66,         66,        1,   345600, 0xd7581b39
+0,         67,         67,        1,   345600, 0xe9b4444f
+0,         68,         68,        1,   345600, 0x012c0672
+0,         69,         69,        1,   345600, 0x076b65e3
+0,         70,         70,        1,   345600, 0xf3ffd53b
+0,         71,         71,        1,   345600, 0x7ff8fcd0
+0,         72,         72,        1,   345600, 0xd4c98ac8
+0,         73,         73,        1,   345600, 0xb538a830
+0,         74,         74,        1,   345600, 0xd0ecfaba
+0,         75,         75,        1,   345600, 0x179e6045
+0,         76,         76,        1,   345600, 0xfcec3e22
+0,         77,         77,        1,   345600, 0xec2cea65
+0,         78,         78,        1,   345600, 0x8e48c180
+0,         79,         79,        1,   345600, 0x9acca8cb
+0,         80,         80,        1,   345600, 0x1826294b
+0,         81,         81,        1,   345600, 0xf62a3625
+0,         82,         82,        1,   345600, 0x0e69dbf5
+0,         83,         83,        1,   345600, 0xe960fa73
+0,         84,         84,        1,   345600, 0x4db69150
+0,         85,         85,        1,   345600, 0x5b80984a
+0,         86,         86,        1,   345600, 0x51a384c4
+0,         87,         87,        1,   345600, 0x1691474d
+0,         88,         88,        1,   345600, 0xb7dd0e58
+0,         89,         89,        1,   345600, 0xa4315f74
+0,         90,         90,        1,   345600, 0x06c35e25
+0,         91,         91,        1,   345600, 0xb7718ce5
+0,         92,         92,        1,   345600, 0x5c5f3314
+0,         93,         93,        1,   345600, 0x08a1b6b5
+0,         94,         94,        1,   345600, 0x35dd94dd
+0,         95,         95,        1,   345600, 0x0890db4c
+0,         96,         96,        1,   345600, 0x55fb9f8c
+0,         97,         97,        1,   345600, 0xb03ed6d6
+0,         98,         98,        1,   345600, 0x59828bbe
+0,         99,         99,        1,   345600, 0xe36c32ca
+0,        100,        100,        1,   345600, 0x3a83eb0c
+0,        101,        101,        1,   345600, 0xa4e77478
+0,        102,        102,        1,   345600, 0x4adbb35e
+0,        103,        103,        1,   345600, 0x8267d16a
+0,        104,        104,        1,   345600, 0x5b6b2d0b
+0,        105,        105,        1,   345600, 0x8a0617a3
+0,        106,        106,        1,   345600, 0x77134bcc
+0,        107,        107,        1,   345600, 0x9e88067f
+0,        108,        108,        1,   345600, 0xf7baa29a
+0,        109,        109,        1,   345600, 0xb2d00624
+0,        110,        110,        1,   345600, 0x911c42f4
+0,        111,        111,        1,   345600, 0x7a1a4f51
+0,        112,        112,        1,   345600, 0x69c14300
+0,        113,        113,        1,   345600, 0x73e6f115
+0,        114,        114,        1,   345600, 0x44bfcab6
+0,        115,        115,        1,   345600, 0x354d97f0
+0,        116,        116,        1,   345600, 0x287f75f5
+0,        117,        117,        1,   345600, 0xbf9cfb15
+0,        118,        118,        1,   345600, 0x8f30ad56
+0,        119,        119,        1,   345600, 0x22640194
+0,        120,        120,        1,   345600, 0xdcdd3ec8
+0,        121,        121,        1,   345600, 0xb19c41f6
+0,        122,        122,        1,   345600, 0x50603d90
+0,        123,        123,        1,   345600, 0xcc0d35d2
+0,        124,        124,        1,   345600, 0x273b33a9
+0,        125,        125,        1,   345600, 0x5d593766
