CGJU
CGJU
May 22, 2026 · 4 min read

Subtitle Format Introduction

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 Format

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 Format

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 Format

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.

Other Formats

  • SSA: Predecessor of ASS, similar functionality
  • IDX/SUB: Graphic subtitles, commonly used for DVDs
  • PGS: Blu-ray graphic subtitles
  • SCC: Closed caption format

Hard Subtitle Addition Methods

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.

Adding SRT Subtitles

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

Adding ASS Subtitles

ASS subtitles can preserve style information, use the ass filter:

ffmpeg -i input.mp4 -vf ass=subtitle.ass output.mp4

Setting Subtitle Styles

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

Common Style Parameters

  • FontName: Font name
  • FontSize: Font size
  • PrimaryColour: Primary color (text color)
  • OutlineColour: Outline color
  • BackColour: Background color
  • Outline: Outline width
  • Shadow: Shadow depth
  • Bold: Bold (-1=on, 0=off)
  • Italic: Italic

Note: The color format is &HAABBGGRR (Alpha, Blue, Green, Red), which is the reverse of the common RGB order.

Adjusting Subtitle Position

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 Subtitle Addition Methods

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.

Adding SRT Soft Subtitles to MP4

ffmpeg -i input.mp4 -i subtitle.srt -c copy -c:s mov_text output.mp4

Adding Soft Subtitles to MKV

MKV has the best support for soft subtitles and can be copied directly:

ffmpeg -i input.mkv -i subtitle.srt -c copy output.mkv

Adding Multi-Language Subtitles

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

Setting Default Subtitle Track

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

Subtitle Extraction

Sometimes you need to extract subtitles from video files for editing or format conversion. FFmpeg can easily accomplish this task.

Extracting SRT Subtitles from MKV

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

Extracting ASS Subtitles from MKV

If the subtitles are already in ASS format, extract directly:

ffmpeg -i input.mkv -map 0:s:0 -c copy output.ass

Extracting All Subtitle Tracks

ffmpeg -i input.mkv -map 0:s -c copy output_%d.srt

Extracting Subtitles from MP4

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

Subtitle Format Conversion

Different application scenarios require different subtitle formats. FFmpeg can convert between various subtitle formats.

SRT to ASS

ffmpeg -i input.srt output.ass

SRT to VTT

ffmpeg -i input.srt output.vtt

ASS to SRT

Converting ASS subtitles to SRT will lose style information:

ffmpeg -i input.ass output.srt

VTT to SRT

ffmpeg -i input.vtt output.srt

Font Style Settings Detailed Explanation

When using FFmpeg to add hard subtitles, style settings are very important. Below is a detailed introduction to commonly used style parameters.

Color Value Format

The color format used by FFmpeg subtitle filters is &HAABBGGRR, where:

  • AA: Alpha transparency (00=fully transparent, FF=fully opaque)
  • BB: Blue component
  • GG: Green component
  • RR: Red component

Note that the order is Blue-Green-Red (BGR), not the common Red-Green-Blue (RGB).

Common Color Examples

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

Complete Style Example

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

Common FFmpeg Subtitle Commands Summary

Hard Subtitle Related

  • Add SRT hard subtitles: ffmpeg -i input.mp4 -vf subtitles=sub.srt output.mp4
  • Add ASS hard subtitles: ffmpeg -i input.mp4 -vf ass=sub.ass output.mp4
  • Specify font: ffmpeg -i input.mp4 -vf "subtitles=sub.srt:force_style='FontName=SimHei'" output.mp4
  • Adjust subtitle size: ffmpeg -i input.mp4 -vf "subtitles=sub.srt:force_style='FontSize=30'" output.mp4

Soft Subtitle Related

  • Add SRT soft subtitles (MKV): ffmpeg -i input.mkv -i sub.srt -c copy output.mkv
  • Add SRT soft subtitles (MP4): ffmpeg -i input.mp4 -i sub.srt -c copy -c:s mov_text output.mp4
  • Extract subtitles: ffmpeg -i input.mkv -map 0:s:0 output.srt
  • Extract all subtitles: ffmpeg -i input.mkv -map 0:s -c copy sub_%d.srt

Format Conversion Related

  • SRT to ASS: ffmpeg -i input.srt output.ass
  • SRT to VTT: ffmpeg -i input.srt output.vtt
  • ASS to SRT: ffmpeg -i input.ass output.srt

Common Problems and Solutions

1. Subtitle Display Garbled Characters

Usually 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

2. Font Not Found

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

3. Subtitles and Audio Out of Sync

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

Summary

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.

Related Recommendations

More great articles and useful tools

Need to Convert Video Format?

Use our free online video converter tool, supports multiple format conversion, no download required

Try It Now ➡