Skip to content

Subtitle ​

Embed or burn subtitles into video. Supports both soft subtitles (selectable in the media player) and hard-burned subtitles (baked into the video stream).

Quick example ​

typescript
import { ffmpeg } from "ffmpeg-kit";

// Soft subtitles (selectable in player)
await ffmpeg.subtitle()
  .input("video.mp4")
  .softSub({ path: "subs.srt", language: "en" })
  .output("with-subs.mkv")
  .execute();

API ​

.input(path) ​

Input video file. Required.

.softSub(options) ​

Embed subtitle track as a selectable stream (MKV or MP4 container).

ParameterTypeDefaultDescription
pathstring—Path to subtitle file (.srt, .ass, .vtt)
languagestring"und"ISO 639-1 language code ("en", "fr", etc.)
titlestring—Track title shown in player
defaultbooleanfalseSet as default subtitle track
forcedbooleanfalseMark as forced (always shown)

Container support

Soft subtitles require MKV (.mkv) or MP4 (.mp4) output. MP4 supports only mov_text subtitle codec. Use MKV for ASS/SSA format preservation.

.hardBurn(options) ​

Burn subtitles permanently into the video stream.

ParameterTypeDefaultDescription
pathstring—Path to subtitle file
fontDirstring—Directory to search for fonts (for ASS)
charEncodingstring"UTF-8"Character encoding of the subtitle file

.output(path) ​

Output file path. Required.

Examples ​

Embed SRT as soft subtitles ​

typescript
await ffmpeg.subtitle()
  .input("video.mp4")
  .softSub({
    path: "english.srt",
    language: "en",
    title: "English",
    default: true,
  })
  .output("with-subs.mkv")
  .execute();

Hard-burned ASS subtitles ​

typescript
await ffmpeg.subtitle()
  .input("video.mp4")
  .hardBurn({
    path: "styled.ass",
    fontDir: "./fonts",
  })
  .output("burned.mp4")
  .execute();

Multiple subtitle tracks ​

typescript
await ffmpeg.subtitle()
  .input("video.mp4")
  .softSub({ path: "en.srt", language: "en", default: true })
  .softSub({ path: "fr.srt", language: "fr" })
  .softSub({ path: "de.srt", language: "de" })
  .output("multilang.mkv")
  .execute();

Result type ​

typescript
interface SubtitleResult {
  outputPath: string;
  duration: number;
  size: number;
  subtitleTracks: number;
  probeResult: ProbeResult;
}
  • Text — burn dynamic text overlays using drawtext
  • Export — re-encode video while adding subtitles