diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index 2fcac34d62..b65a76411b 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -90,6 +90,23 @@ FATE_MATROSKA_FFMPEG_FFPROBE-$(call ALLYES, FILE_PROTOCOL MOV_DEMUXER       \
                                += fate-matroska-dovi-write-config7
 fate-matroska-dovi-write-config7: CMD = transcode mov $(TARGET_SAMPLES)/mov/dovi-p7.mp4 matroska "-map 0 -c copy -cues_to_front yes -reserve_index_space 40  -metadata_header_padding 64339" "-map 0 -c copy" "" "-show_entries stream_side_data_list"
 
+# This tests the scenario like tickets #4536, #5784 where
+# the first packet (with the overall lowest dts) is a video packet,
+# whereas an audio packet to be muxed later has the overall lowest pts
+# which happens to be negative and therefore needs to be shifted.
+# This is currently buggy (the timestamps of the video frames muxed
+# before the first audio frame are not shifted).
+# (-ss 1.09 ensures that a video frame has the lowest dts of all packets;
+# yet there is an audio packet with the overall lowest pts. output_ts_offset
+# makes the pts of the audio packet, but not the leading video packet negative
+# so that we run into the above issue.)
+FATE_MATROSKA-$(call ALLYES, FILE_PROTOCOL MPEGTS_DEMUXER MPEGVIDEO_PARSER  \
+                             MPEG2VIDEO_DECODER EXTRACT_EXTRADATA_BSF       \
+                             MP3FLOAT_DECODER MATROSKA_MUXER                \
+                             MATROSKA_DEMUXER FRAMECRC_MUXER PIPE_PROTOCOL) \
+                += fate-matroska-avoid-negative-ts
+fate-matroska-avoid-negative-ts: CMD = transcode mpegts $(TARGET_SAMPLES)/mpeg2/t.mpg matroska "-c copy -ss 1.09 -output_ts_offset -60ms" "-c copy -t 0.4"
+
 # This tests writing the MS-compatibility modes V_MS/VFW/FOURCC and A_MS/ACM.
 # It furthermore tests writing the Cues at the front if the cues_to_front
 # option is set and more than enough space has been reserved in advance.
diff --git a/tests/ref/fate/matroska-avoid-negative-ts b/tests/ref/fate/matroska-avoid-negative-ts
new file mode 100644
index 0000000000..a687c8f63c
--- /dev/null
+++ b/tests/ref/fate/matroska-avoid-negative-ts
@@ -0,0 +1,42 @@
+3349536550047c5c553215003ba2acb7 *tests/data/fate/matroska-avoid-negative-ts.matroska
+973070 tests/data/fate/matroska-avoid-negative-ts.matroska
+#extradata 0:       22, 0x2885037c
+#tb 0: 1/1000
+#media_type 0: video
+#codec_id 0: mpeg2video
+#dimensions 0: 352x288
+#sar 0: 12/11
+#tb 1: 1/1000
+#media_type 1: audio
+#codec_id 1: mp3
+#sample_rate 1: 44100
+#channel_layout 1: 4
+#channel_layout_name 1: mono
+0,        -37,         24,       40,     9156, 0xe5bd034a, S=1,       40
+1,          0,          0,       26,      417, 0x7198c15e
+0,          3,          3,       40,     1740, 0x29ac4480, F=0x0
+0,         24,        123,       40,     3672, 0x98652013, F=0x0
+1,         26,         26,       26,      417, 0x3c67c32d
+1,         52,         52,       26,      417, 0x8c24b1ca
+1,         78,         78,       26,      417, 0x6ee576b7
+0,         83,         83,       40,     2532, 0xa2c42769, F=0x0
+1,        104,        104,       26,      417, 0x407603db
+0,        123,        203,       40,     1728, 0xae823d3b, F=0x0
+1,        130,        130,       26,      417, 0xcf2804d2
+1,        156,        156,       26,      417, 0xcf2804d2
+0,        163,        163,       40,     1028, 0x286ac52a, F=0x0
+1,        182,        182,       26,      417, 0xcf2804d2
+0,        203,        283,       40,     1916, 0xd378899e, F=0x0
+1,        208,        208,       26,      417, 0xcf2804d2
+1,        235,        235,       26,      417, 0xcf2804d2
+0,        243,        243,       40,     1168, 0x424e12cf, F=0x0
+1,        261,        261,       26,      417, 0xcf2804d2
+0,        283,        363,       40,     1660, 0x5cec156c, F=0x0
+1,        287,        287,       26,      417, 0xcf2804d2
+1,        313,        313,       26,      417, 0xef163d04
+0,        323,        323,       40,     1004, 0xac0dce29, F=0x0
+1,        339,        339,       26,      417, 0x2a009b3a
+0,        363,        443,       40,     3008, 0x0fc798bf, F=0x0
+1,        365,        365,       26,      417, 0xbedccb9d
+1,        365,        365,       26,      417, 0x2214be3f
+1,        391,        391,       26,      417, 0x8953b878
