Answers.Body: <p>Possibly <a href="https://trac.ffmpeg.org/ticket/6037" rel="noreferrer">#6037 mkv muxing broken</a> and <a href="https://trac.ffmpeg.org/ticket/7064" rel="noreferrer">#7064 External subtitle files cause wrong interleaving</a>. Workaround may be to try <code>-max_interleave_delta</code>. Experiment to see which values work for you.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-23T16:55:25.617Z
Answers.LastActivityDate: 2019-10-23T16:55:25.617Z
Answers.UserDisplayName: llogan
Body: <p>I try to add .srt subtitles to the mkv file and it doesn't work.
  I use the following very simple command:</p>
  <pre><code>$ ffmpeg -y -i original.mkv -i sub_original.srt -map 0 -map 1 -c copy ~/temp.mkv
  ffmpeg version n4.2 Copyright (c) 2000-2019 the FFmpeg developers
    built with gcc 9.1.0 (GCC)
    configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
    libavutil      56. 31.100 / 56. 31.100
    libavcodec     58. 54.100 / 58. 54.100
    libavformat    58. 29.100 / 58. 29.100
    libavdevice    58.  8.100 / 58.  8.100
    libavfilter     7. 57.100 /  7. 57.100
    libswscale      5.  5.100 /  5.  5.100
    libswresample   3.  5.100 /  3.  5.100
    libpostproc    55.  5.100 / 55.  5.100
  Input #0, matroska,webm, from 'original.mkv':
    Metadata:
      encoder         : libebml v1.3.0 + libmatroska v1.4.1
      creation_time   : 2019-09-14T13:50:43.000000Z
    Duration: 00:58:52.45, start: 0.000000, bitrate: 8212 kb/s
      Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
      Stream #0:1(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
      Metadata:
        title           : Dub
      Stream #0:2(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 640 kb/s
      Stream #0:3(rus): Subtitle: subrip (default) (forced)
      Metadata:
        title           : Forced
      Stream #0:4(rus): Subtitle: subrip
      Stream #0:5(eng): Subtitle: subrip
      Stream #0:6(ger): Subtitle: subrip
      Stream #0:7(fre): Subtitle: subrip
      Stream #0:8(ita): Subtitle: subrip
      Stream #0:9(spa): Subtitle: subrip
      Stream #0:10(dut): Subtitle: subrip
      Stream #0:11(por): Subtitle: subrip
      Stream #0:12(tur): Subtitle: subrip
      Stream #0:13(gre): Subtitle: subrip
      Stream #0:14: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 854x1280 [SAR 72:72 DAR 427:640], 90k tbr, 90k tbn, 90k tbc (attached pic)
      Metadata:
        filename        : Cover_Unbelievable.jpg
        mimetype        : image/jpeg
  Input #1, srt, from 'sub_original.srt':
    Duration: N/A, bitrate: N/A
      Stream #1:0: Subtitle: subrip
  Output #0, matroska, to 'temp.mkv':
    Metadata:
      encoder         : Lavf58.29.100
      Stream #0:0(eng): Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 23.98 tbr, 1k tbn, 1k tbc (default)
      Stream #0:1(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
      Metadata:
        title           : Dub
      Stream #0:2(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 640 kb/s
      Stream #0:3(rus): Subtitle: subrip (default) (forced)
      Metadata:
        title           : Forced
      Stream #0:4(rus): Subtitle: subrip
      Stream #0:5(eng): Subtitle: subrip
      Stream #0:6(ger): Subtitle: subrip
      Stream #0:7(fre): Subtitle: subrip
      Stream #0:8(ita): Subtitle: subrip
      Stream #0:9(spa): Subtitle: subrip
      Stream #0:10(dut): Subtitle: subrip
      Stream #0:11(por): Subtitle: subrip
      Stream #0:12(tur): Subtitle: subrip
      Stream #0:13(gre): Subtitle: subrip
      Stream #0:14: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj420p(pc, bt470bg/unknown/unknown), 854x1280 [SAR 72:72 DAR 427:640], q=2-31, 90k tbr, 1k tbn, 90k tbc (attached pic)
      Metadata:
        filename        : Cover_Unbelievable.jpg
        mimetype        : image/jpeg
      Stream #0:15: Subtitle: subrip
  Stream mapping:
    Stream #0:0 -&gt; #0:0 (copy)
    Stream #0:1 -&gt; #0:1 (copy)
    Stream #0:2 -&gt; #0:2 (copy)
    Stream #0:3 -&gt; #0:3 (copy)
    Stream #0:4 -&gt; #0:4 (copy)
    Stream #0:5 -&gt; #0:5 (copy)
    Stream #0:6 -&gt; #0:6 (copy)
    Stream #0:7 -&gt; #0:7 (copy)
    Stream #0:8 -&gt; #0:8 (copy)
    Stream #0:9 -&gt; #0:9 (copy)
    Stream #0:10 -&gt; #0:10 (copy)
    Stream #0:11 -&gt; #0:11 (copy)
    Stream #0:12 -&gt; #0:12 (copy)
    Stream #0:13 -&gt; #0:13 (copy)
    Stream #0:14 -&gt; #0:14 (copy)
    Stream #1:0 -&gt; #0:15 (copy)
  Press [q] to stop, [?] for help
  [matroska @ 0x564c2717f840] Starting new cluster due to timestamp
  [matroska @ 0x564c2717f840] Starting new cluster due to timestamp37 bitrate=8282.2kbits/s speed= 387x    
  frame=84685 fps=9337 q=-1.0 Lq=-1.0 size= 3542743kB time=00:58:52.41 bitrate=8215.9kbits/s speed= 389x    
  video:3070859kB audio:469153kB subtitle:265kB other streams:0kB global headers:0kB muxing overhead: 0.069655%
  </code></pre>
  <p>At first glance it seems to work - if I open new file with VLC I can see new subtitle stream, but the subtitles themselves are not visible!</p>
  <p>I get the followng warnings/errors in the console:</p>
  <blockquote>
  <p>[matroska @ 0x557924efe840] Starting new cluster due to timestamp</p>
  <p>[matroska @ 0x557924efe840] Starting new cluster due to timestamp</p>
  </blockquote>
  <p>So I suppose it's the root of the problem, but I don't know what to do with it. Some other videos work fine with the same command, some don't.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-21T22:00:54.873Z
Comments.Text: https://pastiebin.com/5dae2a8e2a1cb
Comments.UserDisplayName: Kirill Smirnov
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-21T22:02:17.227Z
Comments.Text: But I'm 100% sure that everything is fine with this file. Because in order to figure my problem out I used subtitle file from the original file. If I map it directly even multiple times everything works fine without any errors but once I try to map the file using input file it doesn't work.
Comments.UserDisplayName: Kirill Smirnov
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-21T22:05:20.010Z
Comments.Text: ffmpeg -y -i /path_to_original.mkv -map 0:v -map 0:a -map 0:s -map 0:s:0 -c copy ~/path_to_result.mkv
  
  this command works perfectly - here I map the first subtitle stream twice and it works, but once I try to map it using the external file it stops working.
Comments.UserDisplayName: Kirill Smirnov
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-21T22:06:58.540Z
Comments.Text: Show full log from command.
Comments.UserDisplayName: llogan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-21T22:10:04.187Z
Comments.Text: https://pastiebin.com/5dae2cb7038c5
Comments.UserDisplayName: Kirill Smirnov
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-21T22:13:34.510Z
Comments.Text: Possibly [#6037 mkv muxing broken](https://trac.ffmpeg.org/ticket/6037) and [#7064 External subtitle files cause wrong interleaving](https://trac.ffmpeg.org/ticket/7064). Workaround may be to try `-max_interleave_delta 0`.
Comments.UserDisplayName: llogan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-21T22:32:21.733Z
Comments.Text: Thank you so so so so so much! You've totally saved me, it works!!! Just one more question - it's a universal solution, right? I can add this option for all other similar subtitle injections?
Comments.UserDisplayName: Kirill Smirnov
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-10-23T09:32:46.717Z
Comments.Text: @llogan by the way would you post your comment as an answer so I can accept it?
Comments.UserDisplayName: Kirill Smirnov
Tags: <ffmpeg><matroska>
Title: .srt subtitles added to mkv with ffmpeg are not displayed
UserDisplayName: Kirill Smirnov
ThreadText: # .srt subtitles added to mkv with ffmpeg are not displayed
  
  (Asked by: username_0 on 2019-10-21)
  
  I try to add .srt subtitles to the mkv file and it doesn't work.
  I use the following very simple command:
  
  ```
  $ ffmpeg -y -i original.mkv -i sub_original.srt -map 0 -map 1 -c copy ~/temp.mkv
  ffmpeg version n4.2 Copyright (c) 2000-2019 the FFmpeg developers
    built with gcc 9.1.0 (GCC)
    configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3
    libavutil      56. 31.100 / 56. 31.100
    libavcodec     58. 54.100 / 58. 54.100
    libavformat    58. 29.100 / 58. 29.100
    libavdevice    58.  8.100 / 58.  8.100
    libavfilter     7. 57.100 /  7. 57.100
    libswscale      5.  5.100 /  5.  5.100
    libswresample   3.  5.100 /  3.  5.100
    libpostproc    55.  5.100 / 55.  5.100
  Input #0, matroska,webm, from 'original.mkv':
    Metadata:
      encoder         : libebml v1.3.0 + libmatroska v1.4.1
      creation_time   : 2019-09-14T13:50:43.000000Z
    Duration: 00:58:52.45, start: 0.000000, bitrate: 8212 kb/s
      Stream #0:0(eng): Video: h264 (High), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
      Stream #0:1(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
      Metadata:
        title           : Dub
      Stream #0:2(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 640 kb/s
      Stream #0:3(rus): Subtitle: subrip (default) (forced)
      Metadata:
        title           : Forced
      Stream #0:4(rus): Subtitle: subrip
      Stream #0:5(eng): Subtitle: subrip
      Stream #0:6(ger): Subtitle: subrip
      Stream #0:7(fre): Subtitle: subrip
      Stream #0:8(ita): Subtitle: subrip
      Stream #0:9(spa): Subtitle: subrip
      Stream #0:10(dut): Subtitle: subrip
      Stream #0:11(por): Subtitle: subrip
      Stream #0:12(tur): Subtitle: subrip
      Stream #0:13(gre): Subtitle: subrip
      Stream #0:14: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 854x1280 [SAR 72:72 DAR 427:640], 90k tbr, 90k tbn, 90k tbc (attached pic)
      Metadata:
        filename        : Cover_Unbelievable.jpg
        mimetype        : image/jpeg
  Input #1, srt, from 'sub_original.srt':
    Duration: N/A, bitrate: N/A
      Stream #1:0: Subtitle: subrip
  Output #0, matroska, to 'temp.mkv':
    Metadata:
      encoder         : Lavf58.29.100
      Stream #0:0(eng): Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 23.98 tbr, 1k tbn, 1k tbc (default)
      Stream #0:1(rus): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
      Metadata:
        title           : Dub
      Stream #0:2(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 640 kb/s
      Stream #0:3(rus): Subtitle: subrip (default) (forced)
      Metadata:
        title           : Forced
      Stream #0:4(rus): Subtitle: subrip
      Stream #0:5(eng): Subtitle: subrip
      Stream #0:6(ger): Subtitle: subrip
      Stream #0:7(fre): Subtitle: subrip
      Stream #0:8(ita): Subtitle: subrip
      Stream #0:9(spa): Subtitle: subrip
      Stream #0:10(dut): Subtitle: subrip
      Stream #0:11(por): Subtitle: subrip
      Stream #0:12(tur): Subtitle: subrip
      Stream #0:13(gre): Subtitle: subrip
      Stream #0:14: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj420p(pc, bt470bg/unknown/unknown), 854x1280 [SAR 72:72 DAR 427:640], q=2-31, 90k tbr, 1k tbn, 90k tbc (attached pic)
      Metadata:
        filename        : Cover_Unbelievable.jpg
        mimetype        : image/jpeg
      Stream #0:15: Subtitle: subrip
  Stream mapping:
    Stream #0:0 -> #0:0 (copy)
    Stream #0:1 -> #0:1 (copy)
    Stream #0:2 -> #0:2 (copy)
    Stream #0:3 -> #0:3 (copy)
    Stream #0:4 -> #0:4 (copy)
    Stream #0:5 -> #0:5 (copy)
    Stream #0:6 -> #0:6 (copy)
    Stream #0:7 -> #0:7 (copy)
    Stream #0:8 -> #0:8 (copy)
    Stream #0:9 -> #0:9 (copy)
    Stream #0:10 -> #0:10 (copy)
    Stream #0:11 -> #0:11 (copy)
    Stream #0:12 -> #0:12 (copy)
    Stream #0:13 -> #0:13 (copy)
    Stream #0:14 -> #0:14 (copy)
    Stream #1:0 -> #0:15 (copy)
  Press [q] to stop, [?] for help
  [matroska @ 0x564c2717f840] Starting new cluster due to timestamp
  [matroska @ 0x564c2717f840] Starting new cluster due to timestamp37 bitrate=8282.2kbits/s speed= 387x    
  frame=84685 fps=9337 q=-1.0 Lq=-1.0 size= 3542743kB time=00:58:52.41 bitrate=8215.9kbits/s speed= 389x    
  video:3070859kB audio:469153kB subtitle:265kB other streams:0kB global headers:0kB muxing overhead: 0.069655%
  
  ```
  
  At first glance it seems to work - if I open new file with VLC I can see new subtitle stream, but the subtitles themselves are not visible!
  
  I get the followng warnings/errors in the console:
  
  > [matroska @ 0x557924efe840] Starting new cluster due to timestamp
  >
  > [matroska @ 0x557924efe840] Starting new cluster due to timestamp
  
  So I suppose it's the root of the problem, but I don't know what to do with it. Some other videos work fine with the same command, some don't.
  
  **Tags:** ffmpeg, matroska
  
  > **Comments:**
  > **username_0**: https://pastiebin.com/5dae2a8e2a1cb  
  > **username_0**: But I'm 100% sure that everything is fine with this file. Because in order to figure my problem out I used subtitle file from the original file. If I map it directly even multiple times everything works fine without any errors but once I try to map the file using input file it doesn't work.  
  > **username_0**: ffmpeg -y -i /path_to_original.mkv -map 0:v -map 0:a -map 0:s -map 0:s:0 -c copy ~/path_to_result.mkv  this command works perfectly - here I map the first subtitle stream twice and it works, but once I try to map it using the external file it stops working.  
  > **username_1**: Show full log from command.  
  > **username_0**: https://pastiebin.com/5dae2cb7038c5  
  > **username_1**: Possibly [#6037 mkv muxing broken](https://trac.ffmpeg.org/ticket/6037) and [#7064 External subtitle files cause wrong interleaving](https://trac.ffmpeg.org/ticket/7064). Workaround may be to try `-max_interleave_delta 0`.  
  > **username_0**: Thank you so so so so so much! You've totally saved me, it works!!! Just one more question - it's a universal solution, right? I can add this option for all other similar subtitle injections?  
  > **username_0**: @username_1 by the way would you post your comment as an answer so I can accept it?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-10-23. Score: 8 | Accepted answer
  
  Possibly [#6037 mkv muxing broken](https://trac.ffmpeg.org/ticket/6037) and [#7064 External subtitle files cause wrong interleaving](https://trac.ffmpeg.org/ticket/7064). Workaround may be to try `-max_interleave_delta`. Experiment to see which values work for you.
  
  
  ---
  
  