3

An MKV file containing multiple sets of subtitles refuses to play them on a SmartTV or similar devices, seeing no subtitles at all. mplayer manages the file without problems. Here's what is in the file:

$ ffprobe input.mkv |& grep Stream
Stream #0:0(zxx): Video: h264 (High), yuv420p(progressive), 716x360 [SAR 32:27 DAR 2864:1215], SAR 212:179 DAR 106:45, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(spa): Audio: ac3, 48000 Hz, stereo, fltp, 224 kb/s (default)
Stream #0:2(eng): Subtitle: dvd_subtitle, 720x480 (default)
Stream #0:3(fre): Subtitle: subrip
Stream #0:4(por): Subtitle: subrip

My assumption is that less capable players are unable to cope with subtitle formats other than SRT. The question is, how does one extract the existing English subtitle track from the MKV file, convert it into SRT, and optionally, add it back into the MKV file.

Other than "I've never seen a MP4 file with SRT subtitles", another thread (Converting DVD subtitles to text) that asked the same question has not been answered.

The supposedly definitive https://trac.ffmpeg.org/wiki/ExtractSubtitles contains information that does not match the actual ffmpeg operation. This is my ffmpeg:

$ ffmpeg -v
ffmpeg version 3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.1.0 (GCC)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/man --disable-static --enable-shared --enable-runtime-cpudetect --enable-avresample --enable-gpl --enable-version3 --enable-pthreads --enable-postproc --disable-debug --disable-indev=jack --disable-outdev=jack --arch=x86_64 --enable-pic --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-gnutls --enable-libcaca --enable-libcdio --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libmp3lame --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libpulse --enable-libsmbclient --enable-libwavpack
libavutil      55. 58.100 / 55. 58.100
libavcodec     57. 89.100 / 57. 89.100
libavformat    57. 71.100 / 57. 71.100
libavdevice    57.  6.100 / 57.  6.100
libavfilter     6. 82.100 /  6. 82.100
libavresample   3.  5.  0 /  3.  5.  0
libswscale      4.  6.100 /  4.  6.100
libswresample   2.  7.100 /  2.  7.100
libpostproc    54.  5.100 / 54.  5.100

And this is what I tried to do, without success:

$ ffmpeg -i input.mkv -map 0:2 subs-EN.srt
...
Stream mapping:
  Stream #0:2 -> #0:0 (dvd_subtitle (dvdsub) -> subrip (srt))
  Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
$ ffmpeg -codecs | grep dvdsub
...
DES... dvd_subtitle DVD subtitles (decoders: dvdsub ) (encoders: dvdsub )

So the dvdsub decoder is compiled into ffmpeg (as expected, or the subtitles would not show in mplayer), but is not being invoked to convert them.

I also tried

$ mplayer -dumpsrtsub -dumpfile subs-EN.srt -sid 0 input.mkv 
MPlayer 1.3.0-7.1.0 (C) 2000-2016 MPlayer Team
...
[lavf] stream 0: video (h264), -vid 0
[lavf] stream 1: audio (ac3), -aid 0, -alang spa
[lavf] stream 2: subtitle (dvdsub), -sid 0, -slang eng
[lavf] stream 3: subtitle (srt), -sid 1, -slang fre
[lavf] stream 4: subtitle (srt), -sid 2, -slang por
...

The correct subtitle stream is being played, but nothing gets written to subs-EN.srt.

What am I doing wrong?

  • 1
    See stackoverflow.com/a/36327919/5726027 – Gyan May 14 '17 at 14:59
  • I see. Thanks. To summarize "dvdsub" is not a text-based subtitle format (surprising, because I can change the font that is used to render it), and needs OCR to convert it to srt. However, it can be "burned in" as an overlay on the video. Unfortunately, of the two commands you offer there, neither works very well: ffmpeg -i input.mkv -vf subtitles=input.mkv -acodec copy -sn converted.mkv or ffmpeg -i input.mkv -filter_complex "[0:v:0][0:2]overlay" -acodec copy -sn converted.mkv – Edward Sternin May 16 '17 at 0:34
  • ffmpeg -i input.mkv -vf subtitles=input.mkv -acodec copy -sn converted.mkv complains No such filter: 'subtitles' while ffmpeg -i input.mkv -filter_complex "[0:v:0][0:2]overlay" -acodec copy -crf 20 -sn converted.mkv produces terrible quality output. – Edward Sternin May 16 '17 at 0:43
  • terrible quality output --> the subtitles portion or the whole picture? If the latter, the pictures may have wayward sprites within its pixels and/or low-resolution. I would suggest the OCR route to text first. The subtitles filter requires libass to be compiled/linked. – Gyan May 16 '17 at 4:42
  • The whole image, all blocky, as if a very limited video bandwidth. In fact, adding -crf 20 did not improve the quality much, if at all. There are some sprites (?) within the subtitles, and their resolution is also poor, but not critically so. I must say, you are the only person, on any forum, that seems to understand ffmpeg, a singularly idiosyncratic piece of software. Thanks for your patience, but you are light years ahead of the rest of us, trying to keep up. Is there an equivalent strategy within mplayer/mencoder? I seem to understand its logic better. – Edward Sternin May 16 '17 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.