11

I am adding subtitles to a video using:

ffmpeg -i "imput.mp4" -lavfi "subtitles=subtitles.srt:force_style='OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,Fontsize=18'" -crf 1 -c:a copy "output.mp4"

Which results in:

No Alignment

I am repositioning this using Alignment :

ffmpeg -i "imput.mp4" -lavfi "subtitles=subtitles.srt:force_style='Alignment=9,OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,Fontsize=18'" -crf 1 -c:a copy "output.mp4"

Alignment=9

But according to the Line-Alignment ASS Tags docs, there are only 9 positions. 1: Bottom left, 2: Bottom center, 3: Bottom right, 5: Top left, 6: Top center, 7: Top right, 9: Middle left, 10: Middle center, 11: Middle right

Is there a way to tweak this positioning?

I want the subs to be left-aligned, but lower down. Like this:

result

friendlygiraffe
  • 871
  • 2
  • 6
  • 18
  • *subs to be left-aligned, but lower down* --> sounds like `Alignment=1` – Gyan Sep 10 '19 at 13:01
  • 2
    Yes, I've experimented with all 9 positions, but when trying to specify the margin it has no effect. It seems the _Alignment_ parameter overrides the _MarginV_: `ffmpeg -i "imput.mp4" -lavfi "subtitles=subtitles.srt:force_style='Alignment=1,OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,Fontsize=18,MarginV=25'" -crf 1 -c:a copy "output.mp4"` – friendlygiraffe Sep 10 '19 at 13:05
  • -crf Would please explain it ? – itil memek cantik May 09 '22 at 05:40

4 Answers4

20

I have tested every alignment and made documentation with my design skills.

enter image description here

MBK
  • 2,589
  • 21
  • 25
19

Turns out the trick for doing this is to add Alignment=0. Then you can use MarginV and MarginL freely:

ffmpeg -i "imput.mp4" -lavfi "subtitles=subtitles.srt:force_style='Alignment=0,OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,Fontsize=18,MarginL=5,MarginV=25'" -crf 1 -c:a copy "output.mp4"
friendlygiraffe
  • 871
  • 2
  • 6
  • 18
2

in fact you can also put some margin like "MarginV=20" in order to teweak position of subtitles

ffmpeg2 -y -i "C:\Users\input.mxf" -pix_fmt yuv422p -vcodec mpeg2video -non_linear_quant 1 -flags +ildct+ilme -top 1 -dc 10 -intra_vlc 1 -qmax 6 -lmin "1*QP2LAMBDA" -vtag xd5c -rc_max_vbv_use 1 -rc_min_vbv_use 1 -g 12 -b:v 50000k -minrate 50000k -maxrate 51000k -bufsize 8000k -color_primaries 1 -color_trc 1 -colorspace 1 -vf "subtitles=subtitles_file.mxf_Subtitle.srt:force_style='OutlineColour=&H80000000,BorderStyle=3,Outline=1,Shadow=0,MarginV=20" -acodec copy "output.mxf"

flenoir
  • 37
  • 6
  • 1
    I already tried adding MarginV=25 to my code has no effect:`ffmpeg -i "imput.mp4" -lavfi "subtitles=subtitles.srt:force_style='Alignment=9,OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,Fontsize=18,MarginV=25'" -crf 1 -c:a copy "output.mp4"` also I tried removing Alignment=9, but it doesn't left-align – friendlygiraffe Sep 10 '19 at 12:53
  • can you try using ```-vf``` flag instead of ```-lavfi``` ? – flenoir Sep 11 '19 at 09:08
  • thanks, I tried using `-vf` but it had no affect. It seems *Alignment=9* overrides the *MarginV* property. Unless there is some other way to left-align without using the *Alignment* property – friendlygiraffe Sep 11 '19 at 10:08
  • did you try -vf and without Alignment property ? – flenoir Sep 11 '19 at 10:54
  • Yes, I tried it with setting Alignment=0. -lavfi or -vf makes no difference. See here: https://stackoverflow.com/a/57886939/1954892 – friendlygiraffe Sep 11 '19 at 10:56
  • i can not get alignment=6 to work. seems alignment=0 and marginv makes no differnece here either. – mjs Oct 14 '20 at 20:42
2

I try to small size the text and turn the margin of bottom: Alignment=2, Fontsize = 5, MarginV = 1 It's work for me. like this way:

ffmpeg -i "1.mkv" -lavfi "subtitles=1.srt:force_style='Alignment=2,OutlineColour=&H100000000,BorderStyle=3,Outline=1,Shadow=0,Fontsize= 12,MarginV=35'" -crf 1 -c:a copy  -vcodec h264_nvenc  "output.mkv"

*-vcodec h264_nvenc is cuda accelerator.

bode liang
  • 119
  • 3