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
A relative path such as
subtitles=sub.srtworks as is. For a path with a drive letter, write-vf "subtitles='C\:/videos/sub.srt'": forward slashes,\:before the colon, and the whole path in single quotes.
To change the font size or position:
ffmpeg -i input.mp4 -vf "subtitles=subtitle.srt:force_style='FontSize=24'" output.mp4
force_style overrides the style with ASS style fields such as FontSize, PrimaryColour and Alignment. FontSize=24 sets the text size to 24.
Alignment uses the legacy SSA numbering: 2 is bottom center (default), 6 is top center, 10 is middle center. Example: force_style='Alignment=6'.
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 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
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 \
-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 -map 0:v -map 0:a? -map 0:s? -c:v copy -c:a copy -c:s mov_text output.mp4
Keep in mind:
- Without
-map, only one subtitle track is converted. With plain-map 0, the command fails when the MKV has attached fonts - Color, position and animation are lost when you convert ASS/SSA to
mov_text(bold and italic stay)
Checking and Extracting Subtitle Tracks
To list the subtitle tracks in a file, use ffprobe:
ffprobe -v error -select_streams s -show_entries stream=index,codec_name:stream_tags=language -of csv=p=0 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.
Related Articles:
FAQ
Subtitles are garbled
An SRT file that is not UTF-8 (for example Shift_JIS) stops FFmpeg with Invalid UTF-8 in decoded subtitles text. Add :charenc=CP932 to the subtitles filter (for example subtitles=sub.srt:charenc=CP932) or re-save the file as UTF-8.