How to Add Font size in subtitles in ffmpeg video filter
Asked Answered
M

3

27

I'm using this command to crop,scale, and then add subtitles as overlay

ffmpeg -i input.avi  -vf "[in]crop=in_w:in_h-20:0:0 [crop]; [crop]scale=320:240 [scale];[scale]subtitles=srt.srt" -aspect 16:9 -vcodec libx264  -crf 23 oq.mp4

how can we set font size/color of subtitle ?

Mariehamn answered 26/1, 2014 at 12:29 Comment(0)
I
60

There are two methods to use subtitles: hardsubs and softsubs.

Hardsubs

The subtitles video filter can be used to hardsub, or burn-in, the subtitles. This requires re-encoding and the subtitles become part of the video itself.

force_style option

To customize the subtitles you can use the force_style option in the subtitles filter. Example using subtitles file subs.srt and making font size of 24 with red font color.

ffmpeg -i video.mp4 -vf "subtitles=subs.srt:force_style='Fontsize=24,PrimaryColour=&H0000ff&'" -c:a copy output.mp4
  • force_style uses the SubStation Alpha (ASS) style fields.

  • PrimaryColour is in hexadecimal in Blue Green Red order. Note that this is the opposite order of HTML color codes. Color codes must always start with &H and end with &.

Aegisub

Alternatively, you can use Aegisub to create and stylize your subtitles. Save as SubStation Alpha (ASS) format as it can support font size, font color, shadows, outlines, scaling, angle, etc.


Softsubs

These are additional streams within the file. The player simply renders them upon playback. More flexible than hardsubbing because:

  • You do not need to re-encode the video.
  • You can have multiple subtitles (various languages) and switch between them.
  • You can toggle them on/off during playback.
  • They can be resized with any player worth using.

Of course sometimes hardsubs are needed if the device or player is unable to utilize softsubs.

To mux subtitles into a video file using stream copy mode:

ffmpeg -i input.mkv -i subtitles.ass -codec copy -map 0 -map 1 output.mkv

Nothing is re-encoded, so the whole process will be quick and the quality and formats will be preserved.

Using SubStation Alpha (ASS) subtitles will allow you to format the subtitles however you like. These can be created/converted with Aegisub.


Also see

Iconoscope answered 26/1, 2014 at 22:1 Comment(3)
The question how to change the font size was not answered, please provide syntactically correct exampleJumna
@RolandSeuhs The answer states that it is not possible with SRT (as far as I know). As for ASS, the actual ASS file dictates the font size; as you can see in the example file.Iconoscope
This works, but be sure that you have created the FC_CONFIG_DIR, FONTCONFIG_FILE and FONTCONFIG_PATH environment variables and the file fonts.conf exists, otherwise it won't work.Gob
A
13

From the documentation you can use a srt subtitle file and change the size of the font by putting ASS style format KEY=VALUE pairs separated by ,. So,

ffmpeg -i input.mp4 -vf subtitles=sub.srt:force_style='FontName=DejaVu Serif,FontSize=24' -vcodec libx264 -acodec copy -q:v 0 -q:a 0 output.mp4

will put the subtitles with DejaVu font and size 24 while keeps the quality of the video. I've tried myself and it worked.

Almeria answered 6/1, 2016 at 22:32 Comment(2)
This command worked thanks, but only if I enclosed the parameter to -vf with double quotes.Pseudonym
This hardcode sub command works, but like @GabrielDevillers says, only with double quotes around -vf parameter.Momism
N
-1

FFmpeg is good sometimes, but some videos can becoms blurry. I recoomend to compare with VLC player.

media>Convert/Save

I find the default settings for Profile Video for iPad HD/iPhone/PSP is very good. Or I can reduce the Biterates from 700kb/s to 350kb/s to make smaller.

Newlin answered 6/5, 2020 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.