Burning subtitles into video with ffmpeg with specific margin not working

949 views Asked by At

I am trying to build a tool where people can position their subtitles on an HTML5 video and then I will burn the subtitles into the video for them.

I can easily get the position of the subtitles, in whatever format I need, that's easy. However, no combination of values that I feed to ffmpeg are working.

My holy grail is an x and y offest (aka offset 5% from the left, 10% from the bottom, in terms of video height/width).

To achieve this, I would like the subtitles to start in the very bottom-left corner.

ffmpeg -y -i english.mp4 -vf "subtitles=english.srt:force_style='Alignment=1,OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,FontName=Arial,FontSize=24,MarginL=140,MarginV=0'"  -c:v libx264 -crf 23 -c:a copy output_video.mp4

Here is something that is approaching working, but it's behaving very strangely. The video is 850x480 but when I do a margin of 140 it goes way past the midway point of the video.

Am I missing something? How can I start the margin in the bottom left, and then apply the margin I want to push it away from the left and away from the bottom? I can do it either as a percentage of the video height/width if that API is supported or just pixels is fine too (but clearly doesn't seem to be working)

1

There are 1 answers

0
Rolf of Saxony On

You have omitted the right hand side instruction, which maybe confusing things.
try:

ffmpeg -y -i english.mp4 -vf "subtitles=english.srt:force_style='Alignment=1,OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,FontName=Arial,FontSize=24,MarginL=40,MarginR=140,MarginV=10'"  -c:v libx264 -crf 23 -c:a copy output_video.mp4

MarginL. This defines the Left Margin in pixels. It is the distance from the left-hand edge of the screen.The three onscreen margins (MarginL, MarginR, MarginV) define areas in which the subtitle text will be displayed.

MarginR. This defines the Right Margin in pixels. It is the distance from the right-hand edge of the screen. The three onscreen margins (MarginL, MarginR, MarginV) define areas in which the subtitle text will be displayed.

MarginV. This defines the vertical Left Margin in pixels. For a subtitle, it is the distance from the bottom of the screen. For a toptitle, it is the distance from the top of the screen. For a midtitle, the value is ignored - the text will be vertically centred