There are two ways to add subtitles to a video: burn them into the picture (hard subs) or store them as a separate track (soft subs).
Differences Between Hard Subs and Soft Subs
| Method | Overview | Primary Use Cases |
|---|---|---|
| Hard sub (burn-in) | The text is drawn into the video picture. It becomes part of the video and cannot be removed later | Subtitles that must always show, whatever the player |
| Soft sub (embedding) | The subtitles are a separate track in the file (for example MKV). Viewers can turn them on or off or switch language | Several languages, or subtitles you may still want to edit |
Hard subs need a re-encode, so they take longer, but they show in any player. Soft subs usually need only a copy, so they are fast, but only players that support subtitle tracks show them.
Hard Subs (Burn-in)
Burning SRT Subtitles — subtitles Filter
The subtitles filter draws a subtitle file onto the video with the libass library.
ffmpeg -i input.mp4 -vf subtitles=subtitle.srt output.mp4
Replace
subtitle.srtorsubtitle.asswith the path to your own subtitle file.
To change the font size or position:
ffmpeg -i input.mp4 -vf "subtitles=subtitle.srt:force_style='FontSize=24,Alignment=2'" output.mp4
force_style overrides the style with ASS style fields such as FontSize, PrimaryColour and Alignment.
Burning ASS Subtitles — ass Filter
ASS (Advanced SubStation Alpha) is a subtitle format that can set fonts, colors and animations. The subtitles filter can read ASS files too.
ffmpeg -i input.mp4 -vf ass=subtitle.ass output.mp4
subtitles=subtitle.ass and ass=subtitle.ass both use libass, so the result looks the same. The difference: the ass filter reads only ASS files and has no force_style or charenc option.
Font Specification (ASS)
Set the font with Fontname in the [V4+ Styles] section of the ASS file. If the font is not installed on the system, point the fontsdir option at the folder that contains it:
ffmpeg -i input.mp4 -vf "ass=subtitle.ass:fontsdir=/path/to/fonts" output.mp4
Soft Subs (Embedding)
Embedding a Subtitle Track into MKV
An MKV file can hold several subtitle tracks. This command adds an SRT file as a subtitle track and copies the video and audio as they are:
ffmpeg -i input.mp4 -i subtitle.srt -map 0:v -map 0:a -map 1 -c copy -c:s srt output.mkv
-map 0:v -map 0:a -map 1: selects the video and audio of input.mp4 and the subtitles in subtitle.srt. Without it, if input.mp4 already has a subtitle track, FFmpeg keeps that track and leaves out subtitle.srt-c copy: copies the video and audio without re-encoding-c:s srt: stores the subtitles in SRT format
For subtitles in several languages, list every stream with -map. Without -map, only one subtitle track is kept:
ffmpeg -i input.mp4 -i sub_ja.srt -i sub_en.srt \
-map 0:v -map 0:a -map 1 -map 2 \
-c copy -c:s srt \
-metadata:s:s:0 language=jpn \
-metadata:s:s:1 language=eng \
output.mkv
Copying Subtitle Streams (Existing Tracks)
To convert an MKV file that already has subtitle tracks and keep them, use -c:s copy. Add -map 0 as well: without it, only one audio track and one subtitle track are kept.
ffmpeg -i input.mkv -map 0 -c:v libx264 -c:a aac -c:s copy output.mkv
Converting Subtitles from MKV to MP4
MP4 stores subtitles as mov_text (3GPP Timed Text, also called tx3g). To convert the subtitle tracks when you change an MKV into an MP4:
ffmpeg -i input.mkv -c:v copy -c:a copy -c:s mov_text output.mp4
Keep in mind:
- ASS/SSA styling is lost when you convert to
mov_text - Whether the subtitles show depends on the player
- If the target player has limited subtitle support, use hard subs instead
Checking and Extracting Subtitle Tracks
To list the subtitle tracks in a file, use ffprobe:
ffprobe -v error -show_streams -select_streams s input.mkv
To save the subtitles as a separate file:
ffmpeg -i input.mkv -c:s srt extracted_subtitle.srt
This works only for text subtitles such as SRT and ASS. Image subtitles, such as PGS from Blu-ray or VobSub from DVD, cannot be turned into SRT: FFmpeg stops with Subtitle encoding currently only possible from text to text or bitmap to bitmap.
Summary
| Use Case | Recommended Method | Key Command Options |
|---|---|---|
| Subtitles that always show, in any player | Hard sub | -vf subtitles= or -vf ass= |
| Subtitles viewers can turn on or off | Soft sub (MKV) | Embed with -c:s srt |
| Keep existing tracks as they are | Copy | -c:s copy |
| MKV → MP4 conversion | mov_text | -c:s mov_text |
Related Articles: