Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
subtitles [2019/06/29 03:59]
beandog
subtitles [2020/10/26 18:49] (current)
beandog [Detect CC]
Line 3: Line 3:
   * [[ffmpeg]]   * [[ffmpeg]]
  
 +** 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 ==== ==== Detect VobSub ====
  
Line 27: Line 28:
 </​code>​ </​code>​
  
 +For a DVD directly:
 +
 +<​code>​
 +dvd_copy -o - | ffprobe -probesize 67108864 -analyzeduration 60000000 -
 +</​code>​
  
 ==== Detect CC ==== ==== Detect CC ====
Line 32: Line 38:
 For DVDs, closed captioning streams are embedded in the video stream. For DVDs, closed captioning streams are embedded in the video stream.
  
-See if a DVD has closed captioning:+By default, ffmpeg will copy the Closed Captions. Even passing ''​-sn''​ will not disable them. They must be selected using lavfi and modified / ignored that way. 
 + 
 +The fastest way is to see if it has closed captioning ​is using ffprobe and looking for ''​Closed Captions''​ in the output:
  
 <​code>​ <​code>​
-dvd_copy -o - | ffprobe ​-v 0 -show_streams -show_entries stream=start_pts -select_streams s -f lavfi -i movie=pipe\\\\:​0[out+subcc]+ffprobe ​dvd_copy.mpg
 </​code>​ </​code>​
  
-See if a video has closed captioning:+<​code>​ 
 +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 
 +</​code>​ 
 + 
 +Use ffprobe'​s INI style output to look for it as well:
  
 <​code>​ <​code>​
 ffprobe -v 0 -show_streams -show_entries stream=start_pts -select_streams s -f lavfi -i movie=dvd_copy.mpg[out+subcc] ffprobe -v 0 -show_streams -show_entries stream=start_pts -select_streams s -f lavfi -i movie=dvd_copy.mpg[out+subcc]
 +</​code>​
 +
 +See if a DVD has closed captioning:
 +
 +<​code>​
 +dvd_copy -o - | ffprobe -v 0 -show_streams -show_entries stream=start_pts -select_streams s -f lavfi -i movie=pipe\\\\:​0[out+subcc]
 </​code>​ </​code>​
  
Line 85: Line 103:
 [/STREAM] [/STREAM]
 </​code>​ </​code>​
- 
  
 ==== Extract CC ==== ==== Extract CC ====
Line 99: Line 116:
 <​code>​ <​code>​
 dvd_copy -o dvd_copy.mpg dvd_copy -o dvd_copy.mpg
-ffmpeg -f lavfi -i move=dvd_copy.mpg[out+subcc] -map 0:s subtitles.srt+ffmpeg -f lavfi -i movie=dvd_copy.mpg[out+subcc] -map 0:s subtitles.srt
 </​code>​ </​code>​
  
Line 105: Line 122:
  
 <​code>​ <​code>​
-ffmpeg -f lavfi -i move=dvd_copy.mpg[out+subcc] -map 0:v -map 0:s video.mkv+ffmpeg -f lavfi -i movie=dvd_copy.mpg[out+subcc] -map 0:v -map 0:s video.mkv 
 +</​code>​ 
 + 
 +==== 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** 
 + 
 +<​code>​ 
 +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 
 +</​code>​ 
 +==== 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: 
 + 
 +<​code>​ 
 +dvd_copy -o - | ffmpeg -probesize 67108864 -analyzeduration 60000000 -i - -map 0:v -map i:0x80 -map i:0x20 -scodec copy dvd_copy.mkv 
 +</​code>​ 
 + 
 +<​code>​ 
 +mediainfo dvd_copy.mkv 
 +</​code>​ 
 + 
 +Here, ''​Default''​ is set to ''​yes''​. 
 + 
 +<​code>​ 
 +... 
 +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 
 +</​code>​ 
 + 
 +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. 
 + 
 +<​code>​ 
 +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 
 +</​code>​ 
 + 
 +<​code>​ 
 +mediainfo dvd_copy.mkv 
 +</​code>​ 
 + 
 +Both are set to default here: 
 + 
 +<​code>​ 
 +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 
 +</​code>​ 
 + 
 +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: 
 + 
 +<​code>​ 
 +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 
 +</​code>​ 
 + 
 +<​code>​ 
 +mediainfo dvd_copy.mkv 
 +</​code>​ 
 + 
 +<​code>​ 
 +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 
 +</​code>​ 
 + 
 +If you want to disable default for all subtitle tracks, use mkvpropedit (part of mkvtoolnix package), editing them individually:​ 
 + 
 +<​code>​ 
 +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
 </​code>​ </​code>​

Navigation