DVD Subtitles

WARNING: ffmpeg automatically muxes the closed captioning in with libx264 if it exists, and will not show up in the map output, meaning it cannot be disabled. Also, mediainfo may or may not display it, while other applications (mplayer, mpv, HandBrake) will. It can be disabled in encoding with -a53cc 0 for libx264. Using libx265 does not encode the CC at all.

Detect VobSub

The MPG will need to be probed deeper than normal to check for VobSub streams because they only are detected once they show up in the video.

An example:

ffprobe -probesize 67108864 -analyzeduration 60000000 dvd_video.mpg
Input #0, mpeg, from '1.665.2138.17690.TNTGO.mpg':
  Duration: 00:11:09.02, start: 0.045500, bitrate: 5708 kb/s
    Stream #0:0[0x1bf]: Data: dvd_nav_packet
    Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, progressive), 720x480 [SAR 32:27 DAR 16:9], 29.92 fps, 59.94 tbr, 90k tbn, 59.94 tbc
    Stream #0:2[0x82]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:3[0x81]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:4[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 192 kb/s
    Stream #0:5[0x21]: Subtitle: dvd_subtitle
    Stream #0:6[0x20]: Subtitle: dvd_subtitle
    Stream #0:7[0x23]: Subtitle: dvd_subtitle
    Stream #0:8[0x22]: Subtitle: dvd_subtitle

For a DVD directly:

dvd_copy -o - | ffprobe -probesize 67108864 -analyzeduration 60000000 -

Detect CC

For DVDs, closed captioning streams are embedded in the video stream.

The fastest way is to see if it has closed captioning is using ffprobe and looking for Closed Captions in the output:

ffprobe dvd_copy.mpg
Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p(tv, top first), 720x480 [SAR 32:27 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc

Use ffprobe's INI style output to look for it as well:

ffprobe -v 0 -show_streams -show_entries stream=start_pts -select_streams s -f lavfi -i movie=dvd_copy.mpg[out+subcc]

See if a DVD has closed captioning:

dvd_copy -o - | ffprobe -v 0 -show_streams -show_entries stream=start_pts -select_streams s -f lavfi -i movie=pipe\\\\:0[out+subcc]

When splitting the streams using lavfi device, ffmpeg will “create” a subtitle stream, even if one is not present. To make sure one exists or not, a closer look at the stream itself is actually needed.

This one has a starting presentation timestamp (PTS) that's a positive value, so it's safe to say that one exists.

[STREAM]
start_pts=25257
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]

Here's one without it present:

[STREAM]
start_pts=N/A
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
[/STREAM]

Extract CC

Use ffmpeg to extract the closed captioning stream from a DVD using dvd_copy:

dvd_copy -o - | ffmpeg -f lavfi -i movie=pipe\\\\:0[out+subcc] -map 0:s subtitles.srt

Extract CC subtitles from an MPG:

dvd_copy -o dvd_copy.mpg
ffmpeg -f lavfi -i movie=dvd_copy.mpg[out+subcc] -map 0:s subtitles.srt

Since the closed captioning is embedded in the video stream, you can re-encode that at the same time. It won't see any other streams though (audio, vobsub).

ffmpeg -f lavfi -i movie=dvd_copy.mpg[out+subcc] -map 0:v -map 0:s video.mkv

Encode with existing Closed Captioning

Since ffmpeg can input from two sources at once, you can input the same source twice, encode the audio and video from one, split the closed captioning data from the other, and mux them into one file all at once.

This will work on a file but not with piped input

ffmpeg -i dvd_copy.mpg -f lavfi -i movie=dvd_copy.mpg[out+subcc] -map 0:v -map 0:a -map 1:s? dvd_copy.mkv

Default Subtitles

If any subtitles are copied from the DVD, ffmpeg will mark them all as enabled by default. This means that when playing it back with mpv or mplayer, it will display the subtitles automatically.

ffmpeg has the ability to toggle some off and some on, but not the ability to mark all of them as not default.

An example …

Encode a video file using defaults for audio and video codec, and copying the first subtitle stream:

dvd_copy -o - | ffmpeg -probesize 67108864 -analyzeduration 60000000 -i - -map 0:v -map i:0x80 -map i:0x20 -scodec copy dvd_copy.mkv
mediainfo dvd_copy.mkv

Here, Default is set to yes.

...
Text
ID                                       : 3
Format                                   : VobSub
Codec ID                                 : S_VOBSUB
Codec ID/Info                            : Picture based subtitle format used on DVDs
Duration                                 : 26 s 660 ms
Default                                  : Yes
Forced                                   : No

If you were to copy multiple VobSub streams, it will set them all to default:

Switching to using an MPG file in the example here for simplicity.

ffmpeg -probesize 67108864 -analyzeduration 60000000 -i dvd_copy.mpg -map 0:v -map i:0x80 -map i:0x20 -map i:0x21 -scodec copy dvd_copy.mkv
mediainfo dvd_copy.mkv

Both are set to default here:

Text #1
ID                                       : 3
Format                                   : VobSub
Codec ID                                 : S_VOBSUB
Codec ID/Info                            : Picture based subtitle format used on DVDs
Duration                                 : 26 s 660 ms
Default                                  : Yes
Forced                                   : No

Text #2
ID                                       : 4
Format                                   : VobSub
Codec ID                                 : S_VOBSUB
Codec ID/Info                            : Picture based subtitle format used on DVDs
Duration                                 : 26 s 660 ms
Default                                  : Yes
Forced                                   : No

ffmpeg *does* let you set the disposition off for one or more, but not all.

Here's an example with three subtitles illustrating the point, where the first two will be disabled as default, and switching the third to enabled:

ffmpeg -probesize 67108864 -analyzeduration 60000000 -i dvd_copy.mpg -map 0:v -map i:0x80 -map i:0x20 -map i:0x21 -map i:0x22 -scodec copy -disposition:s:0 0 -disposition:s:1 0 -disposition:s:2 default dvd_copy.mkv
mediainfo dvd_copy.mkv
Text #1
ID                                       : 3
Format                                   : VobSub
Codec ID                                 : S_VOBSUB
Codec ID/Info                            : Picture based subtitle format used on DVDs
Duration                                 : 26 s 660 ms
Default                                  : No
Forced                                   : No

Text #2
ID                                       : 4
Format                                   : VobSub
Codec ID                                 : S_VOBSUB
Codec ID/Info                            : Picture based subtitle format used on DVDs
Duration                                 : 26 s 660 ms
Default                                  : No
Forced                                   : No

Text #3
ID                                       : 5
Format                                   : VobSub
Codec ID                                 : S_VOBSUB
Codec ID/Info                            : Picture based subtitle format used on DVDs
Duration                                 : 27 s 661 ms
Default                                  : Yes
Forced                                   : No

If you want to disable default for all subtitle tracks, use mkvpropedit (part of mkvtoolnix package), editing them individually:

mkvpropedit dvd_copy.mkv --edit track:s1 --set flag-default=0 --edit track:s2 --set flag-default=0 --edit track:s3 --set flag-default=0

Navigation