Home/News | About | Download | Documentation | Forum | Bug Reports | Contact | Donations | Consulting | Projects | Legal | Security | FATE


This forum has not been maintained for a long time and will probably get deleted in the near future.
For faster responses to your questions, please use StackOverflow instead and tag your questions with "FFmpeg".
If you need a backup of the posts from this forum, please contact me directly.

subtitle extraction

Who doesn't love them :) But for faster response on your Bug Reports, please visit: http://www.ffmpeg.org/bugreports.html
Forum rules
First of all, please remember that all the developers working on FFmpeg are volunteers, we are not paid for analyzing, debugging, fixing and answering bug reports. While we try our best to create high quality software and be responsive, if you should not get an answer, please consider the above and be aware of the fact that we receive many bug reports and the amount of time it takes to deal with them can be substantial. Nevertheless most issues get resolved, just please understand that there are no guarantees nor promises.

subtitle extraction

Postby jkl » Sun Mar 16, 2014 8:38 pm

Hi,

I am posing this here because my distribution isn't on the latest ffmpeg, and this might have been fixed in a later release.

I am trying to extract subtitles from a file with ffmpeg. For some reason that I don't understand, I can only extract the first subtitle stream.

Code: Select all
$ mediainfo /path/to/some/file

 [...]

 Text #1
 ID                                       : 3
 Format                                   : UTF-8
 Codec ID                                 : S_TEXT/UTF8
 Codec ID/Info                            : UTF-8 Plain Text
 Language                                 : English
 Default                                  : No
 Forced                                   : No

 Text #2
 ID                                       : 4
 Format                                   : UTF-8
 Codec ID                                 : S_TEXT/UTF8
 Codec ID/Info                            : UTF-8 Plain Text
 Language                                 : English
 Default                                  : No
 Forced                                   : No

 Text #3
 ID                                       : 5
 Format                                   : UTF-8
 Codec ID                                 : S_TEXT/UTF8
 Codec ID/Info                            : UTF-8 Plain Text
 Language                                 : English
 Default                                  : No
 Forced                                   : No

 Text #4
 ID                                       : 6
 Format                                   : VobSub
 Codec ID                                 : S_VOBSUB
 Codec ID/Info                            : The same subtitle format used on DVDs
 Language                                 : French
 Default                                  : No
 Forced                                   : No

 Text #5
 ID                                       : 7
 Format                                   : VobSub
 Codec ID                                 : S_VOBSUB
 Codec ID/Info                            : The same subtitle format used on DVDs
 Language                                 : Spanish
 Default                                  : No
 Forced                                   : No

 Text #6
 ID                                       : 8
 Format                                   : VobSub
 Codec ID                                 : S_VOBSUB
 Codec ID/Info                            : The same subtitle format used on DVDs
 Language                                 : Portuguese
 Default                                  : No
 Forced                                   : No

 [...]


First set of subtitles, no problem:

Code: Select all
$ ffmpeg -i /path/to/some/file -an -vn -c:s:0 srt sub0.srt
 ffmpeg version 1.0.7 Copyright (c) 2000-2013 the FFmpeg developers
   built on Jun 30 2013 13:05:24 with gcc 4.6.3 (Gentoo 4.6.3 p1.13, pie-0.5.2)
   configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared --cc=x86_64-pc-linux-gnu-gcc --cxx=x86_64-pc-linux-gnu-g++ --ar=x86_64-pc-linux-gnu-ar --optflags='-O2 -fomit-frame-pointer -pipe -march=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=2048 -mfpmath=sse' --extra-cflags='-O2 -fomit-frame-pointer -pipe -march=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=2048 -mfpmath=sse' --extra-cxxflags='-O2 -fomit-frame-pointer -pipe -march=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=2048 -mfpmath=sse' --disable-static --enable-gpl --enable-version3 --enable-postproc --enable-avfilter --enable-avresample --disable-stripping --disable-debug --disable-doc --disable-vaapi --disable-runtime-cpudetect --enable-libmp3lame --enable-libvo-aacenc --enable-libtheora --enable-libx264 --enable-lib  libavutil      51. 73.101 / 51. 73.101
   libavcodec     54. 59.100 / 54. 59.100
   libavformat    54. 29.104 / 54. 29.104
   libavdevice    54.  2.101 / 54.  2.101
   libavfilter     3. 17.100 /  3. 17.100
   libswscale      2.  1.101 /  2.  1.101
   libswresample   0. 15.100 /  0. 15.100
   libpostproc    52.  0.100 / 52.  0.100

 [...]

     Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x800 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
     Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s (default)
     Stream #0:2(eng): Subtitle: subrip
     Stream #0:3(eng): Subtitle: subrip
     Stream #0:4(eng): Subtitle: subrip
     Stream #0:5(fre): Subtitle: dvd_subtitle
     Stream #0:6(spa): Subtitle: dvd_subtitle
     Stream #0:7(por): Subtitle: dvd_subtitle
 Output #0, srt, to 'sub0.srt':

 [...]

 Stream mapping:
   Stream #0:2 -> #0:0 (subrip -> srt)
 Press [q] to stop, [?] for help
 size=     100kB time=02:00:00.00 bitrate=   0.1kbits/s    ts/s   
 video:0kB audio:0kB subtitle:100 global headers:0kB muxing overhead 0.000000%


But any other set of subtitles gets me this:

Code: Select all
$ ffmpeg -i /path/to/some/file -an -vn -c:s:1 srt sub1.srt

 [...] (identical to above)

 Stream mapping:
   Stream #0:2 -> #0:0 (subrip -> ?)
 Encoder (codec none) not found for output stream #0:0


I also tried this incantation, but it always returns the first subtitle set no matter which one I ask for:

Code: Select all
$ ffmpeg -i /path/to/some/file -an -vn -c:s:0.2 srt sub2.srt
 ffmpeg version 1.0.7 Copyright (c) 2000-2013 the FFmpeg developers
   built on Jun 30 2013 13:05:24 with gcc 4.6.3 (Gentoo 4.6.3 p1.13, pie-0.5.2)
   configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared --cc=x86_64-pc-linux-gnu-gcc --cxx=x86_64-pc-linux-gnu-g++ --ar=x86_64-pc-linux-gnu-ar --optflags='-O2 -fomit-frame-pointer -pipe -march=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=2048 -mfpmath=sse' --extra-cflags='-O2 -fomit-frame-pointer -pipe -march=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=2048 -mfpmath=sse' --extra-cxxflags='-O2 -fomit-frame-pointer -pipe -march=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=2048 -mfpmath=sse' --disable-static --enable-gpl --enable-version3 --enable-postproc --enable-avfilter --enable-avresample --disable-stripping --disable-debug --disable-doc --disable-vaapi --disable-runtime-cpudetect --enable-libmp3lame --enable-libvo-aacenc --enable-libtheora --enable-libx264 --enable-lib  libavutil      51. 73.101 / 51. 73.101
   libavcodec     54. 59.100 / 54. 59.100
   libavformat    54. 29.104 / 54. 29.104
   libavdevice    54.  2.101 / 54.  2.101
   libavfilter     3. 17.100 /  3. 17.100
   libswscale      2.  1.101 /  2.  1.101
   libswresample   0. 15.100 /  0. 15.100
   libpostproc    52.  0.100 / 52.  0.100

 [...]

     Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x800 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
     Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s (default)
     Stream #0:2(eng): Subtitle: subrip
     Stream #0:3(eng): Subtitle: subrip
     Stream #0:4(eng): Subtitle: subrip
     Stream #0:5(fre): Subtitle: dvd_subtitle
     Stream #0:6(spa): Subtitle: dvd_subtitle
     Stream #0:7(por): Subtitle: dvd_subtitle
 Output #0, srt, to 'sub2.srt':

 [...]

   Stream #0:2 -> #0:0 (subrip -> srt)
 Press [q] to stop, [?] for help
 size=     129kB time=02:03:15.80 bitrate=   0.1kbits/s   
 video:0kB audio:0kB subtitle:129 global headers:0kB muxing overhead 0.000000%


Thanks in advance for any insight on this.
jkl
 
Posts: 8
Joined: Sun Mar 16, 2014 8:20 pm

Re: subtitle extraction

Postby burek » Mon Mar 17, 2014 7:16 pm

Hi and welcome to this forum :)

The option "c:s:0" specifies which subtitle codec (encoder) will be used on the first (zero-based indexes) OUTPUT subtitle stream. So, that is your first subtitle stream, which you always get, right? Right. Let's move on.

When you wrote:
Code: Select all
ffmpeg -i /path/to/some/file -an -vn -c:s:1 srt sub1.srt

you told ffmpeg to use the SRT subtitle encoder on the 2nd (zero-based indexes, so 1 == 2nd stream) OUTPUT subtitle stream. Now, that would work only if your output has got the 2nd subtitle stream. Does it? Let's check. Take a look at the ffmpeg's output of your first command:
Code: Select all
Stream mapping:
   Stream #0:2 -> #0:0 (subrip -> srt)

and that's it. No more streams in the output. Only ONE subtitle stream. So, your option to set the subtitle encoder on a non-existing 2nd output stream is just being ignored (which IMHO should be noted to the user with a warning, but it's not my decision to make that happen).

So, what do you need? You first need to map (using "-map") all the input subtitle streams to the output (or just the one you need). After that, you can tell ffmpeg which output stream should be encoded using which subtitle encoder. For example:
Code: Select all
ffmpeg -i /path/to/some/file -an -vn -map 0:2 -map 0:3 -map 0:4 -c:s:0 srt -c:s:1 blah -c:s:2 foobar sub0.srt

this would make ffmpeg first forward/map all the input subtitle streams to the output and then encode the 1st one using SRT encoder, the 2nd one using some bogus "blah" encoder and the 3rd one using "foobar" encoder. Got it?

Now, what you probably need is to select only one input subtitle stream and make it to the output and encode it using SRT encoder. This would do it:
Code: Select all
ffmpeg -i /path/to/some/file -an -vn -map 0:2 -c:s:0 srt sub1.srt

Code: Select all
ffmpeg -i /path/to/some/file -an -vn -map 0:3 -c:s:0 srt sub2.srt

Code: Select all
ffmpeg -i /path/to/some/file -an -vn -map 0:4 -c:s:0 srt sub3.srt

Please note that I always used only "-c:s:0" and that's because I always mapped only 1 input stream to the output, so my outputs always have only one output stream to encode. Thus "-c:s:0" in all those examples.

Btw, those "0:2", "0:3" and "0:4" are indexes of your input streams, which you can see in your ffmpeg output (or when you simply type "ffmpeg -i /path/to/some/file" in order to get the information on the input file):
Code: Select all
     Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x800 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
     Stream #0:1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s (default)
     Stream #0:2(eng): Subtitle: subrip
     Stream #0:3(eng): Subtitle: subrip
     Stream #0:4(eng): Subtitle: subrip
     Stream #0:5(fre): Subtitle: dvd_subtitle
     Stream #0:6(spa): Subtitle: dvd_subtitle
     Stream #0:7(por): Subtitle: dvd_subtitle
burek
 
Posts: 864
Joined: Mon May 09, 2011 10:16 pm
Location: Serbia


Return to Bugs, bugs, bugs :)

Who is online

Users browsing this forum: No registered users and 1 guest