[FFmpeg-user] Burning DVD subtitles into video using overlay filter not working
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
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
And if I look at all "stream.2" properties, I do not see anything usable:
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,
> 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