5

I found this page (I can't comment or answer there so here's a new question):

Render srt subtitles to video?

with this line which works fine:

ffmpeg -i input.mp4 -filter:v subtitles=subtitle.srt -c:a copy -c:v libx264 -crf 22 -preset veryfast output.mp4

I need the following and can't get it done:

  • subtitles lines start from the TOP of the canvas
  • subtitles have bigger character size and thicker stroke
  • subtitles area has a semi-transparent dark background

mencoder might be another viable manner to do it.

1 Answer 1

5

Aegisub

Use ASS subtitles. Style them in Aegisub. You can style each letter or word individually, or apply the desired styling to all subtitles. See the documentation for detailed instructions.

enter image description here

Example ASS file:

[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
YCbCr Matrix: None

[Aegisub Project Garbage]
Last Style Storage: Default

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,48,&H00FFFFFF,&H000000FF,&H00000000,&H80000000,0,0,0,0,100,100,0,0,1,6,0,8,10,10,20,1

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,Top of canvas. Bigger font size. Thicker stroke.

Without Aegisub

You can apply styling via the subtitles filter force_style option in ffmpeg. This should work with any format that the subtitles filter accepts.

ffmpeg -i input -vf "subtitles=subs.srt:force_style='Alignment=6,Fontsize=48,Outline=8'" output

Refer to the example ASS file for accepted force_style options, but it will not allow you to style each letter or word individually as you can in Aegisub.

Note that ScaleX and ScaleY values when used in force_style are a factor, not a percentage, so the accurate values would be 1,1 (not 100,100) in that case.

Transparent background

This can be tricky due to some limitations of libass, but it is possible. See How to set background to subtitle in ffmpeg?

10
  • Thanks @LordNeckbeard!!! I was using Aegisub 3.2.2 on Ubuntu Linux to create these subtitles without exceeding the 15 cps reading speed. I'll dig into its docs. From this page on styles and the Highlights one, at first glance, it seems to me as I can not render the video with hard coded subtitles using Aegisub alone, can I? For now I kept using the SubRip .srt format and applied your hint on ffmpeg, great!
    – JazzTp
    Jun 7, 2018 at 0:54
  • It's 720p and I used this line: ffmpeg -i input.mp4 -vf "subtitles=subs.srt:force_style='Alignment=6,Fontsize=22,Outline=2'" -c:a copy -c:v libx264 -crf 22 -preset slower output_Alignment_6_Fontsize_22_Outline_2___slower.mp4 (Separate comment because otherwise it was too long, the platform didn't allow it. I guess I should "accept" you answer but can't see how to do it, yet.)
    – JazzTp
    Jun 7, 2018 at 1:00
  • could you please point me to exhaustive docs on how to use the force_style option? I can only find examples here and there on the web, e.g. no alignment options explained (tried 7 out of curiosity and it's top-right). Again THANK YOU A LOT! (I tried to upvote your answer, the platform says it gets recorded but not visible to the public because I don't have enough reputation... maybe that's also why I don't find any button or link to "accept" your answer, I hope you won't mind, sorry.)
    – JazzTp
    Jun 7, 2018 at 1:13
  • @JazzTp I'm not sure if you can use Aegisub alone to hardsub, and laziness prevents me from looking it up. I've only used it to create subtitle files. Alignment is described under Line Alignment (refer to \a and \an tags). force_style seems to use the legacy positioning (\a) which makes less sense than the more current "number pad" positioning system (\an). Only documentation on -force_style is under the subtitles filter docs which I linked to in the answer, but the ASS Tags page will help.
    – llogan
    Jun 7, 2018 at 1:42
  • Thank you again @LordNeckbeard everything clear (impressive possibilities with the Advanced Substation Alpha format).
    – JazzTp
    Jun 8, 2018 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.