#11493 closed defect (fixed)

ffmpeg causes mkv corruption when remuxing existing MKV with WEBVTT (.vtt) subtitles that have empty cue blocks

Reported by: agH94PeodEE9 Owned by: Michael Niedermayer <michael@niedermayer.cc>
Priority: normal Component: ffmpeg
Version: unspecified Keywords: mkv corrupted webvtt remux
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
-If I download - e.g. with yt-dlp - a video (including video, audio, vtt-subtitle(s) & thumbnail), merge the audio, video & subtitle streams into a MKV and then remux this MKV to include the thumbnail, the output MKV is corrupted: timeframes are dropped at different times of the track

How to reproduce:

  • Merge WEBVTT subtitle streams together with audio/video streams into a MKV.
  • The WEBVTT subtitles must have empty CUE blocks, as e.g.
    00:00:49.620 --> 00:00:51.620
    That's the beginning
    
    00:00:54.120 --> 00:00:56.220
    
    
    00:00:56.220 --> 00:00:58.220
    Reason and rhyme of hide and seek
    
  • Then, this MKV file must be remuxed to a MKV again, e.g. to include a thumbnail.
  • The result is a corrupted MKV: Timerframes are dropped - most likely where CUE blocks of WEBVTT subtitles are empty.
  • The bug is already documented here:

​https://github.com/yt-dlp/yt-dlp/issues/6918#issuecomment-1523817935

  • Here is the complete yt-dlp command including ffmpeg commands
    Summary of the bug:
    -If I download - e.g. with yt-dlp - a video (including video, audio, vtt-subtitle(s) & thumbnail), merge the audio, video & subtitle streams into a MKV and then remux this MKV to include the thumbnail, the output MKV is corrupted: timeframes are dropped at different times of the track
    
    How to reproduce:
    - Merge WEBVTT subtitle streams together with audio/video streams into a MKV.
    - The WEBVTT subtitles must have empty CUE blocks, as e.g.
    {{{
    00:00:49.620 --> 00:00:51.620
    That's the beginning
    
    00:00:54.120 --> 00:00:56.220
    
    
    00:00:56.220 --> 00:00:58.220
    Reason and rhyme of hide and seek
    }}}
    - Then, this MKV file must be remuxed to a MKV again, e.g. to include a thumbnail.
    - The result is a corrupted MKV: Timerframes are dropped- most likely where CUE blocks of WEBVTT subtitles are empty.
    
    Here is the complete yt-dlp command including ffmpeg commands
    {{{
    [debug] Command-line config: ['--format', 'bestvideo*+HLS-audio0-Deutsch+HLS-audio0-Français+HLS-audio0-Italiano', '--sub-langs', 'de,fr,it,en', '--parse-metadata', 'mkv_corruption_test_file:%(title)s', '--username', 'PRIVATE', '--password', 'PRIVATE', '--no-part', '--embed-metadata', '--embed-thumbnail', '--embed-subs', '--audio-multistreams', '--remux-video', 'mkv', '--concurrent-fragments', '5', '--output', 'mkv_corruption_test_file.%(ext)s', '-vU', 'https://www.playsuisse.ch/watch/804449?episodeId=812574']
    [debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
    [debug] yt-dlp version stable@2025.02.19 from yt-dlp/yt-dlp [4985a4041] (debian*)
    [debug] Python 3.12.7 (CPython x86_64 64bit) - Linux-6.11.0-19-generic-x86_64-with-glibc2.40 (OpenSSL 3.3.1 4 Jun 2024, glibc 2.40)
    [debug] exe versions: ffmpeg 7.0.2 (setts), ffprobe 7.0.2
    [debug] Optional libraries: brotli-1.1.0, certifi-2024.06.02, mutagen-1.46.0, pyxattr-0.8.1, requests-2.32.3, sqlite3-3.46.1, urllib3-2.0.7
    [debug] Proxy map: {}
    [debug] Request Handlers: urllib, requests
    [debug] Loaded 1841 extractors
    [debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
    Latest version: stable@2025.02.19 from yt-dlp/yt-dlp
    yt-dlp is up to date (stable@2025.02.19 from yt-dlp/yt-dlp)
    [PlaySuisse] Requesting session ID
    [PlaySuisse] Submitting username
    [PlaySuisse] Submitting password
    [PlaySuisse] Logging in
    [PlaySuisse] Downloading token
    [PlaySuisse] Extracting URL: https://www.playsuisse.ch/watch/804449?episodeId=812574
    [PlaySuisse] 812574: Downloading JSON metadata
    [PlaySuisse] 812574: Downloading m3u8 information
    [info] 812574: Downloading subtitles: de, fr, it
    [debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec, channels, acodec, size, br, asr, proto, vext, aext, hasaud, source, id
    [debug] Searching for '(?P<title>.+)' in '%(mkv_corruption_test_file)s'
    [MetadataParser] Parsed title from '%(mkv_corruption_test_file)s': 'NA'
    [info] 812574: Downloading 1 format(s): HLS-3111+HLS-audio0-Deutsch+HLS-audio0-Français+HLS-audio0-Italiano
    [info] Writing video subtitles to: mkv_corruption_test_file.de.vtt
    [debug] Invoking hlsnative downloader on "https://stipo2-vod-prod.akamaized.net/stipo/812574_0893624b52c1293545497f2f4b715e12/hdntl=exp=1741344203~acl=%2fstipo%2f812574_0893624b52c1293545497f2f4b715e12%2f*~data=hdntl,allowedCountries%3dswiss~hmac=9176a066e899e650d50baa9af90102e72e50baead1b910fce9134240e1982243/index-f11.m3u8"
    [hlsnative] Downloading m3u8 manifest
    [hlsnative] Total fragments: 438
    [download] Destination: mkv_corruption_test_file.de.vtt
    [download] 100% of   50.55KiB in 00:00:03 at 15.83KiB/s
    [info] Writing video subtitles to: mkv_corruption_test_file.fr.vtt
    [debug] Invoking hlsnative downloader on "https://stipo2-vod-prod.akamaized.net/stipo/812574_0893624b52c1293545497f2f4b715e12/hdntl=exp=1741344203~acl=%2fstipo%2f812574_0893624b52c1293545497f2f4b715e12%2f*~data=hdntl,allowedCountries%3dswiss~hmac=9176a066e899e650d50baa9af90102e72e50baead1b910fce9134240e1982243/index-f12.m3u8"
    [hlsnative] Downloading m3u8 manifest
    [hlsnative] Total fragments: 438
    [download] Destination: mkv_corruption_test_file.fr.vtt
    [download] 100% of   60.41KiB in 00:00:03 at 17.80KiB/s
    [info] Writing video subtitles to: mkv_corruption_test_file.it.vtt
    [debug] Invoking hlsnative downloader on "https://stipo2-vod-prod.akamaized.net/stipo/812574_0893624b52c1293545497f2f4b715e12/hdntl=exp=1741344203~acl=%2fstipo%2f812574_0893624b52c1293545497f2f4b715e12%2f*~data=hdntl,allowedCountries%3dswiss~hmac=9176a066e899e650d50baa9af90102e72e50baead1b910fce9134240e1982243/index-f10.m3u8"
    [hlsnative] Downloading m3u8 manifest
    [hlsnative] Total fragments: 438
    [download] Destination: mkv_corruption_test_file.it.vtt
    [download] 100% of   48.89KiB in 00:00:03 at 15.21KiB/s
    [info] Downloading video thumbnail thumbnail-5ea76155aab1480c8ec1dee1453876b4 ...
    [info] Writing video thumbnail thumbnail-5ea76155aab1480c8ec1dee1453876b4 to: mkv_corruption_test_file.jpg
    [debug] Invoking hlsnative downloader on "https://stipo2-vod-prod.akamaized.net/stipo/812574_0893624b52c1293545497f2f4b715e12/hdntl=exp=1741344203~acl=%2fstipo%2f812574_0893624b52c1293545497f2f4b715e12%2f*~data=hdntl,allowedCountries%3dswiss~hmac=9176a066e899e650d50baa9af90102e72e50baead1b910fce9134240e1982243/index-f6-v1.m3u8"
    [hlsnative] Downloading m3u8 manifest
    [hlsnative] Total fragments: 438
    [download] Destination: mkv_corruption_test_file.fHLS-3111.mp4
    [download] 100% of    1.28GiB in 00:00:13 at 97.29MiB/s
    [debug] Invoking hlsnative downloader on "https://stipo2-vod-prod.akamaized.net/stipo/812574_0893624b52c1293545497f2f4b715e12/hdntl=exp=1741344203~acl=%2fstipo%2f812574_0893624b52c1293545497f2f4b715e12%2f*~data=hdntl,allowedCountries%3dswiss~hmac=9176a066e899e650d50baa9af90102e72e50baead1b910fce9134240e1982243/index-f7-a1.m3u8"
    [hlsnative] Downloading m3u8 manifest
    [hlsnative] Total fragments: 438
    [download] Destination: mkv_corruption_test_file.fHLS-audio0-Deutsch.mp4
    [download] 100% of   30.22MiB in 00:00:03 at 8.09MiB/s
    [debug] Invoking hlsnative downloader on "https://stipo2-vod-prod.akamaized.net/stipo/812574_0893624b52c1293545497f2f4b715e12/hdntl=exp=1741344203~acl=%2fstipo%2f812574_0893624b52c1293545497f2f4b715e12%2f*~data=hdntl,allowedCountries%3dswiss~hmac=9176a066e899e650d50baa9af90102e72e50baead1b910fce9134240e1982243/index-f9-a1.m3u8"
    [hlsnative] Downloading m3u8 manifest
    [hlsnative] Total fragments: 438
    [download] Destination: mkv_corruption_test_file.fHLS-audio0-Français.mp4
    [download] 100% of   30.22MiB in 00:00:03 at 7.98MiB/s
    [debug] Invoking hlsnative downloader on "https://stipo2-vod-prod.akamaized.net/stipo/812574_0893624b52c1293545497f2f4b715e12/hdntl=exp=1741344203~acl=%2fstipo%2f812574_0893624b52c1293545497f2f4b715e12%2f*~data=hdntl,allowedCountries%3dswiss~hmac=9176a066e899e650d50baa9af90102e72e50baead1b910fce9134240e1982243/index-f8-a1.m3u8"
    [hlsnative] Downloading m3u8 manifest
    [hlsnative] Total fragments: 438
    [download] Destination: mkv_corruption_test_file.fHLS-audio0-Italiano.mp4
    [download] 100% of   30.22MiB in 00:00:03 at 8.53MiB/s
    [debug] ffmpeg command line: ffprobe -show_streams file:mkv_corruption_test_file.fHLS-audio0-Deutsch.mp4
    [debug] ffmpeg command line: ffprobe -show_streams 'file:mkv_corruption_test_file.fHLS-audio0-Français.mp4'
    [debug] ffmpeg command line: ffprobe -show_streams file:mkv_corruption_test_file.fHLS-audio0-Italiano.mp4
    [Merger] Merging formats into "mkv_corruption_test_file.mkv"
    [debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:mkv_corruption_test_file.fHLS-3111.mp4 -i file:mkv_corruption_test_file.fHLS-audio0-Deutsch.mp4 -i 'file:mkv_corruption_test_file.fHLS-audio0-Français.mp4' -i file:mkv_corruption_test_file.fHLS-audio0-Italiano.mp4 -c copy -map 0:v:0 -map 1:a:0 -bsf:a:0 aac_adtstoasc -map 2:a:0 -bsf:a:1 aac_adtstoasc -map 3:a:0 -bsf:a:2 aac_adtstoasc -movflags +faststart file:mkv_corruption_test_file.temp.mkv
    Deleting original file mkv_corruption_test_file.fHLS-3111.mp4 (pass -k to keep)
    Deleting original file mkv_corruption_test_file.fHLS-audio0-Deutsch.mp4 (pass -k to keep)
    Deleting original file mkv_corruption_test_file.fHLS-audio0-Français.mp4 (pass -k to keep)
    Deleting original file mkv_corruption_test_file.fHLS-audio0-Italiano.mp4 (pass -k to keep)
    [VideoRemuxer] Not remuxing media file "mkv_corruption_test_file.mkv"; already is in target format mkv
    [EmbedSubtitle] Embedding subtitles in "mkv_corruption_test_file.mkv"
    [debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:mkv_corruption_test_file.mkv -i file:mkv_corruption_test_file.de.vtt -i file:mkv_corruption_test_file.fr.vtt -i file:mkv_corruption_test_file.it.vtt -map 0 -dn -ignore_unknown -c copy -map -0:s -map 1:0 -metadata:s:s:0 language=deu -map 2:0 -metadata:s:s:1 language=fra -map 3:0 -metadata:s:s:2 language=ita -movflags +faststart file:mkv_corruption_test_file.temp.mkv
    Deleting original file mkv_corruption_test_file.fr.vtt (pass -k to keep)
    Deleting original file mkv_corruption_test_file.it.vtt (pass -k to keep)
    Deleting original file mkv_corruption_test_file.de.vtt (pass -k to keep)
    [Metadata] Adding metadata to "mkv_corruption_test_file.mkv"
    [debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:mkv_corruption_test_file.mkv -map 0 -dn -ignore_unknown -c copy -write_id3v1 1 -metadata title=NA -metadata 'description=Luc fehlen zwar handfeste Beweise, aber er ist sicher, dass der korrupte Anwalt Lorenz Ilgner etwas mit dem Mord an seinem besten Freund Bernhard Mäder zu tun hat. Ein persönliches Treffen mit dem aalglatten Erfolgstyp endet handgreiflich: Luc packt Ilgner am Kragen. In der folgenden Nacht wird Luc von Puffmutter Adriana Wanner, einer ehemaligen Schulkollegin, in ein Luxusbordell bestellt, um dort einen Toten abzuholen. Zu seiner Riesenüberraschung handelt es sich um Lorenz Ilgner. Ehe Luc Hilfe holen kann, um die Leiche abzutransportieren, marschiert bereits die Polizei mit Anna-Maria an der Spitze im Club auf. Adriana Wanner hat die Kriminalbeamtin in ihr Etablissement bestellt und Luc schwer belastet: Der Bestatter höchstpersönlich habe Lorenz Ilgner umgebracht. Anna-Maria bleibt nichts anderes übrig, als Luc zu verhaften. 
    
    Die resolute Erika ist schockiert. Sie besucht Luc im Gefängnis und informiert ihn über die Lage im Institut. Ihre selbstgebackene Rüeblitorte versöhnt Luc ein bisschen mit der Welt. Vertrauensvoll legt er die Bestattung eines jungen Lehrers und den damit verbundenen Auftrag, ein Referat über den Tod in der Schule zu halten, in ihre und Fabios Hände.
    
    Luc gelingt es, Anna-Maria davon zu überzeugen, dass er in eine Falle gelockt wurde. Sie glaubt an seine Unschuld und erwirkt bei Staatsanwalt Odermatt seine Freilassung. Luc ist verblüfft, dass Regina Ilgner, die Witwe des ermordeten Anwalts, ausgerechnet ihn mit der Bestattung beauftragt. Die geheimnisvolle Frau weiss sehr viel mehr, als sie zugeben mag. In ihrem Haus stösst Luc auf eine alte Geschichte im Umfeld eines Pontonier-Clubs, die seinem Fall eine überraschende Wendung gibt und ihn auf eine ganz neue Spur führt.
    
    Der Mörder von Illgner setzt unterdessen alles daran, Mitwisser und Zeugen auszuschalten, und schreckt nicht vor weiteren Anschlägen zurück. Dabei gerät auch Anna-Maria in tödliche Gefahr.' -metadata 'synopsis=Luc fehlen zwar handfeste Beweise, aber er ist sicher, dass der korrupte Anwalt Lorenz Ilgner etwas mit dem Mord an seinem besten Freund Bernhard Mäder zu tun hat. Ein persönliches Treffen mit dem aalglatten Erfolgstyp endet handgreiflich: Luc packt Ilgner am Kragen. In der folgenden Nacht wird Luc von Puffmutter Adriana Wanner, einer ehemaligen Schulkollegin, in ein Luxusbordell bestellt, um dort einen Toten abzuholen. Zu seiner Riesenüberraschung handelt es sich um Lorenz Ilgner. Ehe Luc Hilfe holen kann, um die Leiche abzutransportieren, marschiert bereits die Polizei mit Anna-Maria an der Spitze im Club auf. Adriana Wanner hat die Kriminalbeamtin in ihr Etablissement bestellt und Luc schwer belastet: Der Bestatter höchstpersönlich habe Lorenz Ilgner umgebracht. Anna-Maria bleibt nichts anderes übrig, als Luc zu verhaften. 
    
    Die resolute Erika ist schockiert. Sie besucht Luc im Gefängnis und informiert ihn über die Lage im Institut. Ihre selbstgebackene Rüeblitorte versöhnt Luc ein bisschen mit der Welt. Vertrauensvoll legt er die Bestattung eines jungen Lehrers und den damit verbundenen Auftrag, ein Referat über den Tod in der Schule zu halten, in ihre und Fabios Hände.
    
    Luc gelingt es, Anna-Maria davon zu überzeugen, dass er in eine Falle gelockt wurde. Sie glaubt an seine Unschuld und erwirkt bei Staatsanwalt Odermatt seine Freilassung. Luc ist verblüfft, dass Regina Ilgner, die Witwe des ermordeten Anwalts, ausgerechnet ihn mit der Bestattung beauftragt. Die geheimnisvolle Frau weiss sehr viel mehr, als sie zugeben mag. In ihrem Haus stösst Luc auf eine alte Geschichte im Umfeld eines Pontonier-Clubs, die seinem Fall eine überraschende Wendung gibt und ihn auf eine ganz neue Spur führt.
    
    Der Mörder von Illgner setzt unterdessen alles daran, Mitwisser und Zeugen auszuschalten, und schreckt nicht vor weiteren Anschlägen zurück. Dabei gerät auch Anna-Maria in tödliche Gefahr.' -metadata 'purl=https://www.playsuisse.ch/watch/804449?episodeId=812574' -metadata 'comment=https://www.playsuisse.ch/watch/804449?episodeId=812574' -metadata 'artist=Markus Fischer' -metadata 'show=Der Bestatter' -metadata season_number=1 -metadata 'episode_id=Stachel im Fleisch' -metadata episode_sort=4 -metadata:s:1 language=deu -metadata:s:2 language=fra -metadata:s:3 language=ita -movflags +faststart file:mkv_corruption_test_file.temp.mkv
    [debug] ffprobe command line: ffprobe -hide_banner -show_format -show_streams -print_format json file:mkv_corruption_test_file.mkv
    [EmbedThumbnail] ffmpeg: Adding thumbnail to "mkv_corruption_test_file.mkv"
    [debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i file:mkv_corruption_test_file.mkv -map 0 -dn -ignore_unknown -c copy -attach file:mkv_corruption_test_file.jpg -metadata:s:7 mimetype=image/jpeg -metadata:s:7 filename=cover.jpg -movflags +faststart file:mkv_corruption_test_file.temp.mkv
    
    [1]+  Done                    yt-dlp --format "bestvideo*+HLS-audio0-Deutsch+HLS-audio0-Français+HLS-audio0-Italiano" --sub-langs de,fr,it,en --parse-metadata "mkv_corruption_test_file:%(title)s" --username 'PRIVATE' --password 'PRIVATE' --no-part --embed-metadata --embed-thumbnail --embed-subs --audio-multistreams --remux-video mkv --concurrent-fragments 5 --output "mkv_corruption_test_file.%(ext)s" -vU https://www.playsuisse.ch/watch/804449?episodeId=812574
    }}}
    Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.
    

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Attachments (1)

bug-11493-demo.zip​ (1.6 MB ) - added by Marcos 18 months ago.

Download all attachments as: .zip

Change History (4)

comment:1 by agH94PeodEE9, 21 months ago

Component: undetermined → ffmpeg

by Marcos, 18 months ago

Attachment: bug-11493-demo.zip​ added

comment:2 by Marcos, 18 months ago

I've attached a minimal example that reproduces the behaviour, which should make triaging and fixing easier. I can reproduce it on the latest stable version (7.1.1).

comment:3 by Michael Niedermayer <michael@niedermayer.cc>, 18 months ago

Owner: set to Michael Niedermayer <michael@niedermayer.cc>
Resolution: → fixed
Status: new → closed

In a79720e1/ffmpeg:

avformat/matroskadec: Accept WebVTT subtitles with empty cues

Fixes: #11493
Signed-off-by: Michael Niedermayer <​michael@niedermayer.cc>

Note: See TracTickets for help on using tickets.