[FFmpeg-user] Burning DVD subtitles into video using overlay filter not working

Thierry Lelegard thierry at lelegard.fr
Fri Aug 30 14:00:28 CEST 2013


> De: "Nicolas George" <nicolas.george at normalesup.org>
> 
>> [graph 0 input from stream 0:0 @ 00000000022412a0] w:1280 h:536
>> [graph 0 input from stream 0:2 @ 0000000002240e20] w:1920 h:1080
> 
> Ok, here is the problem: the subtitle frames are much larger than the video
> frames, and the top-left corner you actually see is completely transparent.
> There was a time the overlay filter would have produced an error if the
> overlay frame overflows the underlying, but no longer, it is accepted.
> 
> You need to scale and/or crop the subtitles frames to get them to fit on the
> video. I suspect, in this particular case, you should scale to 1280×720 and
> then crop to 1280×536 to achieve the intended geometry.

Great, you got it Nicolas!

The following command does the job:

ffmpeg -i gg.mkv -filter_complex "[0:s]scale=width=1280:height=720,crop=w=1280:h=536:x=0:y=out_h[sub];[0:v][sub]overlay" -codec:v mpeg2video -codec:a mp2 -ac 2 -y gg.hardsubs.mpg

The subtitles are there and look nice. The width/height proportion of the
characters look fine.

I also tried without cropping, directly resizing to the video size, hence
without preserving the aspect ratio:

ffmpeg -i gg.mkv -filter_complex "[0:s]scale=width=1280:height=536[sub];[0:v][sub]overlay" -codec:v mpeg2video -codec:a mp2 -ac 2 -y gg.hardsubs.mpg

The subtitles are there but the characters are slightly vertically
compressed as expected. Interestingly, they now have exactly the same
appearance as displayed with vlc and mplayer. I suppose that both of
them simply resize the subtitle frames without preserving the aspect
ratio.

So far so good ... for this file. My original purpose is to automate
the processing of media files, making decisions based on the various
input streams. To get all characteristics of the input file, I use
ffprobe with "flat" print format. Based on these info, I generate
one or more ffmpeg commands to build the resulting media file.

Now, in the case of DVD subtitles, how can I compute the appropriate
filter? For this, I need the width and height of both the video and
dvdsub stream. However, ffprobe does not give me the size of the
dvdsub frames, only the video streams. See the example:

$ ffprobe gg.mkv -loglevel warning -show_streams -print_format flat | grep -e codec_name -e width -e height
streams.stream.0.codec_name="h264"
streams.stream.0.width=1280
streams.stream.0.height=536
streams.stream.1.codec_name="dca"
streams.stream.2.codec_name="dvdsub"

And if I look at all "stream.2" properties, I do not see anything usable:

streams.stream.2.index=2
streams.stream.2.codec_name="dvdsub"
streams.stream.2.codec_long_name="DVD subtitles"
streams.stream.2.profile="unknown"
streams.stream.2.codec_type="subtitle"
streams.stream.2.codec_time_base="1/1000"
streams.stream.2.codec_tag_string="[0][0][0][0]"
streams.stream.2.codec_tag="0x0000"
streams.stream.2.id="N/A"
streams.stream.2.r_frame_rate="0/0"
streams.stream.2.avg_frame_rate="0/0"
streams.stream.2.time_base="1/1000"
streams.stream.2.start_pts=0
streams.stream.2.start_time="0.000000"
streams.stream.2.duration_ts="N/A"
streams.stream.2.duration="N/A"
streams.stream.2.bit_rate="N/A"
streams.stream.2.nb_frames="N/A"
streams.stream.2.nb_read_frames="N/A"
streams.stream.2.nb_read_packets="N/A"
streams.stream.2.disposition.default=1
streams.stream.2.disposition.dub=0
streams.stream.2.disposition.original=0
streams.stream.2.disposition.comment=0
streams.stream.2.disposition.lyrics=0
streams.stream.2.disposition.karaoke=0
streams.stream.2.disposition.forced=0
streams.stream.2.disposition.hearing_impaired=0
streams.stream.2.disposition.visual_impaired=0
streams.stream.2.disposition.clean_effects=0
streams.stream.2.disposition.attached_pic=0

Maybe, as parameters of the scale and crop filters, I can use expressions
using the literal values of the video stream size. But I need to get more
familiar with the syntax of expressions in ffmpeg parameters.

Thanks a lot for your help,
-Thierry

PS:
> Le tridi 13 fructidor, an CCXXI, Thierry Lelégard a écrit :
Does anyone outside France understand the Revolutionary Calendar? :-)


More information about the ffmpeg-user mailing list