FFmpeg Common Commands Cheat Sheet
Collection of the most practical FFmpeg commands, covering format conversion, clipping, compression, subtitles, streaming and other common scenarios.
Read More →Master various FFmpeg subtitle processing techniques from beginner to advanced
There are many subtitle file formats, each with different characteristics and application scenarios. Before using FFmpeg to process subtitles, let's first understand common subtitle formats.
SRT (SubRip Text) is the most popular and simplest subtitle format, supported by almost all players. It is a plain text format containing sequence numbers, timelines, and subtitle content.
1
00:00:01,000 --> 00:00:04,000
这是第一句字幕
2
00:00:05,000 --> 00:00:08,000
这是第二句字幕
Advantages: Simple format, good compatibility, easy to edit. Disadvantages: Does not support style settings.
ASS (Advanced SubStation Alpha) is the most powerful subtitle format, supporting rich style settings including fonts, colors, positions, animation effects, and more.
[Script Info]
Title: 示例字幕
ScriptType: v4.00+
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour
Style: Default, Arial, 24, &H00FFFFFF
[Events]
Format: Layer, Start, End, Style, Text
Dialogue: 0, 0:00:01.00, 0:00:04.00, Default, 这是第一句字幕
Advantages: Rich styles, supports special effects, highly customizable. Disadvantages: Complex format, not supported by some devices.
VTT (WebVTT) is a subtitle format designed specifically for web pages, natively supported by HTML5's video tag. The format is similar to SRT but has some extended features.
WEBVTT
00:00:01.000 --> 00:00:04.000
这是第一句字幕
00:00:05.000 --> 00:00:08.000
这是第二句字幕
Advantages: Native web support, lightweight. Disadvantages: Browser support varies, limited style functionality.
Hard subtitles (Hardsub) render subtitles directly into the video image, making them part of the video and cannot be turned off. The advantage is good compatibility — any player can display them; the disadvantage is that they cannot be removed and require re-encoding.
Use the subtitles filter to add SRT subtitles:
ffmpeg -i input.mp4 -vf subtitles=sub.srt output.mp4
If the subtitle file name contains special characters or paths, escaping is required:
ffmpeg -i input.mp4 -vf "subtitles='sub\ title.srt'" output.mp4
ASS subtitles can preserve style information, use the ass filter:
ffmpeg -i input.mp4 -vf ass=subtitle.ass output.mp4
For SRT subtitles, you can set subtitle styles through the force_style parameter:
ffmpeg -i input.mp4 -vf "subtitles=sub.srt:force_style='FontName=Arial,FontSize=24,PrimaryColour=&H00FFFFFF&,OutlineColour=&H00000000&,Outline=2'" output.mp4
FontName: Font nameFontSize: Font sizePrimaryColour: Primary color (text color)OutlineColour: Outline colorBackColour: Background colorOutline: Outline widthShadow: Shadow depthBold: Bold (-1=on, 0=off)Italic: ItalicNote: The color format is &HAABBGGRR (Alpha, Blue, Green, Red), which is the reverse of the common RGB order.
You can adjust subtitle position through the Alignment parameter:
ffmpeg -i input.mp4 -vf "subtitles=sub.srt:force_style='Alignment=6,MarginV=50'" output.mp4
Alignment values range from 1-9, corresponding to numpad positions (6=right-middle, 2=bottom-center, 8=top-center).
Soft subtitles (Softsub) embed subtitles as independent tracks in the video file, which can be toggled on/off and switched during playback. The advantage is flexibility and no impact on video quality; the disadvantage is that player support is required.
ffmpeg -i input.mp4 -i subtitle.srt -c copy -c:s mov_text output.mp4
MKV has the best support for soft subtitles and can be copied directly:
ffmpeg -i input.mkv -i subtitle.srt -c copy output.mkv
ffmpeg -i input.mp4 -i zh.srt -i en.srt -i jp.srt \
-c copy -c:s mov_text \
-metadata:s:s:0 language=chi -metadata:s:s:0 title="中文" \
-metadata:s:s:1 language=eng -metadata:s:s:1 title="English" \
-metadata:s:s:2 language=jpn -metadata:s:s:2 title="日本語" \
output.mp4
ffmpeg -i input.mp4 -i zh.srt -i en.srt \
-c copy -c:s mov_text \
-disposition:s:0 default \
-disposition:s:1 none \
output.mp4
Sometimes you need to extract subtitles from video files for editing or format conversion. FFmpeg can easily accomplish this task.
First, check the subtitle track information in the video:
ffmpeg -i input.mkv
Find the subtitle track number (usually 0:s:0, 0:s:1, etc.), then extract:
ffmpeg -i input.mkv -map 0:s:0 output.srt
If the subtitles are already in ASS format, extract directly:
ffmpeg -i input.mkv -map 0:s:0 -c copy output.ass
ffmpeg -i input.mkv -map 0:s -c copy output_%d.srt
Subtitles in MP4 are usually in mov_text format and need to be converted to SRT:
ffmpeg -i input.mp4 -map 0:s:0 output.srt
Different application scenarios require different subtitle formats. FFmpeg can convert between various subtitle formats.
ffmpeg -i input.srt output.ass
ffmpeg -i input.srt output.vtt
Converting ASS subtitles to SRT will lose style information:
ffmpeg -i input.ass output.srt
ffmpeg -i input.vtt output.srt
When using FFmpeg to add hard subtitles, style settings are very important. Below is a detailed introduction to commonly used style parameters.
The color format used by FFmpeg subtitle filters is &HAABBGGRR, where:
AA: Alpha transparency (00=fully transparent, FF=fully opaque)BB: Blue componentGG: Green componentRR: Red componentNote that the order is Blue-Green-Red (BGR), not the common Red-Green-Blue (RGB).
| Color | Color Value | Description |
|---|---|---|
| White | &H00FFFFFF& | Default text color |
| Black | &H00000000& | Outline/shadow color |
| Red | &H000000FF& | Emphasized text |
| Yellow | &H0000FFFF& | Classic subtitle color |
| Semi-transparent black background | &H80000000& | 50% transparency black background |
ffmpeg -i input.mp4 -vf "subtitles=sub.srt:force_style='
FontName=Microsoft YaHei,
FontSize=24,
PrimaryColour=&H00FFFFFF&,
OutlineColour=&H00000000&,
BackColour=&H80000000&,
Bold=-1,
Italic=0,
Outline=2,
Shadow=1,
Alignment=2,
MarginV=40
'" output.mp4
ffmpeg -i input.mp4 -vf subtitles=sub.srt output.mp4ffmpeg -i input.mp4 -vf ass=sub.ass output.mp4ffmpeg -i input.mp4 -vf "subtitles=sub.srt:force_style='FontName=SimHei'" output.mp4ffmpeg -i input.mp4 -vf "subtitles=sub.srt:force_style='FontSize=30'" output.mp4ffmpeg -i input.mkv -i sub.srt -c copy output.mkvffmpeg -i input.mp4 -i sub.srt -c copy -c:s mov_text output.mp4ffmpeg -i input.mkv -map 0:s:0 output.srtffmpeg -i input.mkv -map 0:s -c copy sub_%d.srtffmpeg -i input.srt output.assffmpeg -i input.srt output.vttffmpeg -i input.ass output.srtUsually a subtitle file encoding issue. Ensure the subtitle file is UTF-8 encoded, or specify the character set:
ffmpeg -i input.mp4 -vf "subtitles=sub.srt:charenc=GBK" output.mp4
Ensure the specified font is installed on the system. On Linux systems, you can place font files in the ~/.fonts directory, or set the font path:
FFLIBFREETYPE_FONTPATH=/path/to/fonts ffmpeg -i input.mp4 -vf subtitles=sub.srt output.mp4
You can use the itsoffset parameter to adjust the subtitle time offset:
ffmpeg -i input.mp4 -itsoffset 0.5 -i sub.srt -c:v copy -c:a copy -c:s mov_text output.mp4
FFmpeg provides powerful subtitle processing capabilities, whether adding hard subtitles, soft subtitles, or extracting and converting subtitle formats, it can be easily accomplished. Mastering these commands can greatly improve video processing efficiency.
For users not familiar with the command line, various graphical interface subtitle processing tools are also available. But FFmpeg's flexibility and powerful features remain the first choice for professional users.
More great articles and useful tools
Collection of the most practical FFmpeg commands, covering format conversion, clipping, compression, subtitles, streaming and other common scenarios.
Read More →Comprehensive analysis of video format features, supported codecs, browser compatibility, file size comparison and applicable scenarios.
Read More →Detailed introduction to 4 FFmpeg methods for merging TS files, comparing the advantages and disadvantages of each method and applicable scenarios.
Read More →Use our free online video converter tool, supports multiple format conversion, no download required
Try It Now ➡