The difference between soft subtitles and hard subtitles (burn-in), how to use the subtitles filter and escape paths, and how to composite image subtitles (PGS) with overlay.
Subtitles can be attached to a video in two ways. Soft subtitles are stored as a separate track in the file, so they can be turned on and off in the player (Containers and subtitle tracks), while hard subtitles (burn-in) draw the text into the video pixels so it can't be turned off. This lesson is about hard subtitles.
The subtitles filter draws subtitles using the libass library. It accepts text subtitles such as SRT and ASS. Your FFmpeg build must include libass; without it you get an error saying the filter can't be found. If you only deal with ASS subtitles, there is also an ass filter.
# External SRT
ffmpeg -i input.mp4 -vf "subtitles=sub.srt" -c:v libx264 -crf 20 -c:a copy out.mp4
# The first subtitle track inside the input file (si = subtitle index)
ffmpeg -i input.mkv -vf "subtitles=input.mkv:si=0" -c:v libx264 -crf 20 -c:a copy out.mp4
# Override font size, outline, and so on (using ASS style names)
ffmpeg -i input.mp4 -vf "subtitles=sub.srt:force_style='FontSize=24,Outline=2'" -c:v libx264 -crf 20 -c:a copy out.mp4: and \ are special characters, so using C:\videos\sub.srt as-is causes an error. The easiest fix is to put the subtitle file in your working folder and use just the file name. If you really need a path, use slashes and escaping like C\:/videos/sub.srt.FontSize is known to be applied relative to ASS's reference resolution rather than to screen pixels. Instead of fixing a number and trusting it, adjust while looking at the result.force_style='FontName=…', and if needed, tell it the font folder with fontsdir=. If the SRT file's character encoding isn't UTF-8, tell it with the charenc= option.Subtitles are drawn at the resolution at the point where they sit in the filter chain. If you put them before scale, they are drawn at the original resolution and then shrunk along with the video, so the text can get blurry; if you put them after scale, they are drawn at the final resolution and look sharp. The order scale,…,subtitles=… is usually the safe one. If the timing of an external subtitle file is off from the video, fix it first with the Subtitle Sync & FPS Drift Fixer before burning in. Once burned in, you can't undo it.
Image-based subtitles such as Blu-ray PGS are pictures, not text, so the subtitles filter can't read them. In this case you use the overlay filter, which lays the subtitle stream on top of the video, via -filter_complex (Filtergraph).
ffmpeg -i input.mkv \
-filter_complex "[0:v][0:s:0]overlay[v]" \
-map "[v]" -map 0:a -c:v libx264 -crf 20 -c:a copy out.mp4Image subtitles are made for the original resolution, so if you shrink or enlarge the video first, their position and size can end up off. In that case, use the order of overlaying the subtitles first and then scaling the result. If the subtitle position looks strange, suspect this order first.
Drawing the subtitle text directly into the video pixels. It can't be turned off and requires re-encoding.
Subtitles stored as a separate track. They can be turned on and off in the player.
A library that renders ASS/SSA subtitles. The subtitles and ass filters use it, and it must be included in the FFmpeg build.
An image-based subtitle format used on Blu-ray. It is a picture, not text, so it is burned in by compositing with overlay.
What is the right approach for burning Blu-ray PGS subtitles into a video?
Why do we say burning in subtitles "can't be undone"?