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