Ch. 17 · FFmpeg Filters in Practice

한국어日本語
7 min

Burning In Subtitles: subtitles, ass, overlay

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.

Soft subtitlesHard subtitles (burn-in)
How storedA separate track (text or image)Drawn directly into the video pixels
Turning offPossible in the playerImpossible
Re-encodingNot needed (remux is possible)Required, because a filter is used
CompatibilityThe player or platform must support that subtitle formatVisible in any player
WhenMost archiving and distributionWhen uploading somewhere that can't accept subtitle tracks, or when they must always be shown

The subtitles filter: burning in text 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.

Burn an external subtitle file / burn a subtitle track inside the video / override the style
# 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
  • Windows paths: Inside a filter string, : 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.
  • The font size isn't what you expected: SRT is converted to ASS internally before drawing, and 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.
  • Garbled non-Latin text: If the font has no glyphs for the script (Korean, for example), you get empty boxes. Specify a font that has those glyphs with 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.
Filter order: before or after scale?

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 subtitles (PGS and others) are composited with overlay

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).

Burn the first subtitle stream (image-based) on top of the video
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.mp4

Image 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.

Burn-in (hard sub)Burn-in (hard sub)

Drawing the subtitle text directly into the video pixels. It can't be turned off and requires re-encoding.

Soft subtitleSoft subtitle

Subtitles stored as a separate track. They can be turned on and off in the player.

libasslibass

A library that renders ASS/SSA subtitles. The subtitles and ass filters use it, and it must be included in the FFmpeg build.

PGSPGS subtitles

An image-based subtitle format used on Blu-ray. It is a picture, not text, so it is burned in by compositing with overlay.

Check yourself

What is the right approach for burning Blu-ray PGS subtitles into a video?

Check yourself

Why do we say burning in subtitles "can't be undone"?