Opened 10 years ago
Closed 9 years ago
#3491 closed defect (fixed)
MKV muxer corrupts subtitles
Reported by: | ValdikSS | Owned by: | ValdikSS |
---|---|---|---|
Priority: | normal | Component: | avformat |
Version: | git-master | Keywords: | mkv ass |
Cc: | nfxjfg@googlemail.com | Blocked By: | |
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
Remuxing MKV with embedded subtitles can cause some sort of subtitles corruption in the resulting MKV file. Some lines or karaoke effects could disappear in certain video players.
How to reproduce:
I've uploaded 2 files into incoming folder on FTP: mkv_subtitles.mkv (http://yadi.sk/d/NM69ZxZQKzNn7) and mkv_subtitles_ffmpeg.mkv (http://yadi.sk/d/qDFmsDPQKzNoQ). The second one was remuxed with the following command:
ffmpeg -i mkv_subtitles.mkv -map 0 -map_metadata 0 -c copy mkv_subtitles_ffmpeg.mkv
Subtitles in the first file are played correctly while in ffmpeg-remuxed file some karaoke effects and english translation is missing (tested with cmplayer, vlc, mpv and mplayer. It works correctly only in mplayer).
If you extract subtitles with
mkvextract tracks mkv_subtitles.mkv 1:sub_orig.ass mkvextract tracks mkv_subtitles_ffmpeg.mkv 1:sub_ffmpeg.ass
you can see the difference between them (with diff).
But if you remux MKV with extracted subtitles (extracted either with ffmpeg or mkvextract, either from original or remuxed mkv with broken subtitles), it works fine.
ffmpeg -i mkv_subtitles.mkv -i sub_ffmpeg.ass -map 0 -map -0:s -map 1 -c copy test.mkv
Attachments (1)
Change History (15)
follow-up: 4 comment:1 by , 10 years ago
Cc: | added |
---|
comment:3 by , 10 years ago
Replying to cehoyos:
Is this a regression?
I'm not sure. If this is a regression, then it was introduced a long time ago, more then 1.5 years.
Here is IRC log with the same issue from November 2012
https://gist.github.com/klaxa/197efb68e549d01193b8
comment:4 by , 10 years ago
Replying to gjdfgh:
Can you post the diff?
Subtitles extracted from original file with ffmpeg are the same as extracted from remuxed file with ffmpeg.
Subtitles extracted from remuxed file with ffmpeg are different from extracted with mkvextract. Here is the diff.
comment:5 by , 10 years ago
Sorry, your diff is pretty useless. Appears it thinks _all_ lines are different, maybe due to line ending issues or so.
Anyway, I made my own diff. Looking at this, it seems like ffmpeg reorders some lines when it shouldn't. In general, ffmpeg doesn't respect the order of the lines (ReadOrder field internal to matroska ASS packets), and this is probably the problen. But I'm surprised that this has such a large effect.
follow-ups: 7 10 comment:6 by , 10 years ago
That happens because, by default, the Matroska demuxer uses some legacy format for demuxed ASS packets.
You can get it to use the newer format, and thus preserve the read order, by adding -c:s ass
as input option.
comment:7 by , 10 years ago
Replying to Cigaes:
That happens because, by default, the Matroska demuxer uses some legacy format for demuxed ASS packets.
You can get it to use the newer format, and thus preserve the read order, by adding-c:s ass
as input option.
It doesn't work with this subtitles.
[ass @ 0x1156660] ASS encoder supports only one ASS rectangle field.
comment:8 by , 10 years ago
Actually, I was wrong.
The matroska file contains bogus packets with duplicate ReadOrder values. (Edit: I mean the ffmpeg produced matroska file. The source file is ok.)
The ffmpeg produced mkv files are thus 100% broken.
With mpv, it actually works with --demuxer=lavf, because that uses the old way to demux Matroska ASS packets, which "happens" to work (I can explain details). MPlayer works because it uses the libavformat demuxer.
What Cigaes said probably applies here.
by , 10 years ago
diff between remuxed subtitles extracted with mkvextract and ffmpeg
comment:9 by , 10 years ago
Just updated diff file with correct one.
This is not only this file or only this subtitles issue. I have two more mkvs with this issue.
comment:10 by , 10 years ago
Replying to Cigaes:
That happens because, by default, the Matroska demuxer uses some legacy format for demuxed ASS packets.
You can get it to use the newer format, and thus preserve the read order, by adding-c:s ass
as input option.
Sorry, it seems like i've added it after -i. Adding before -i solves the problem.
Should this option be used by default?
comment:11 by , 10 years ago
Depending on the reader, the extracted subtitles won't show the problem, btw.
libass uses the ReadOrder field to remove duplicates (so if two events have the same ReadOrder value, one of them is removed, even if they are different).
Extract from the file:
151,2,OP_Romaji_1,,0,0,0,,{\be1\an5\pos(784,56)\fscy230\fscx182\1c&HFFFFFF&\bord0\shad0}no 152,27,OP_Romaji_1,,0,0,0,,{\be1\an5\pos(774,50)\alpha&H79&}no 152,2,OP_Romaji_1,,0,0,0,,{\be1\an5\pos(779,61)\fscy206\fscx226\1c&HFFFFFF&\bord0\shad0}no 153,27,OP_Romaji_1,,0,0,0,,{\be1\an5\pos(774,46)\alpha&H79&}no
The 3rd event is never displayed, because it has the same ReadOrder as the 2nd.
comment:12 by , 10 years ago
Priority: | important → normal |
---|
comment:13 by , 10 years ago
Component: | undetermined → avformat |
---|---|
Owner: | set to |
Status: | new → open |
comment:14 by , 9 years ago
Keywords: | mkv ass added |
---|---|
Resolution: | → fixed |
Status: | open → closed |
Version: | unspecified → git-master |
Please reopen if this ticket is still reproducible, a larger patch that includes the change you suggested was committed some time ago.
Can you post the diff?