Skip to content

Text ​

Burn text overlays into video using FFmpeg's drawtext filter.

Quick example ​

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

await ffmpeg.text()
  .input("video.mp4")
  .addText({
    text: "Hello World",
    anchor: "bottom-center",
    margin: 40,
    style: { fontSize: 48, fontColor: "white", box: true, boxColor: "black@0.5" },
    startTime: 1,
    endTime: 5,
  })
  .output("titled.mp4")
  .execute();

API ​

.input(path) ​

Input video file. Required.

.addText(options) ​

Add a text overlay. Can be called multiple times for multiple overlays.

ParameterTypeDefaultDescription
textstring—Text content to render
anchorTextAnchor"bottom-center"Position anchor
marginnumber20Offset from anchor in pixels
xnumber—Absolute X position (overrides anchor)
ynumber—Absolute Y position (overrides anchor)
startTimenumber0When the text appears (seconds)
endTimenumber—When the text disappears (seconds, omit for permanent)
styleTextStyle—Font and appearance options

TextAnchor: "top-left" | "top-center" | "top-right" | "center" | "bottom-left" | "bottom-center" | "bottom-right"

TextStyle:

FieldTypeDefaultDescription
fontSizenumber24Font size in points
fontColorstring"white"Font color (name or hex)
fontFilestring—Path to .ttf font file
fontFamilystring—System font family name
boldbooleanfalseBold weight
boxbooleanfalseDraw background box
boxColorstring"black@0.5"Box background color
boxBorderWidthnumber5Box padding in pixels
shadowXnumber—Drop shadow X offset
shadowYnumber—Drop shadow Y offset
shadowColorstring"black"Drop shadow color

.output(path) ​

Output file path. Required.

Examples ​

Timed caption ​

typescript
await ffmpeg.text()
  .input("video.mp4")
  .addText({
    text: "Chapter 1: Introduction",
    anchor: "top-left",
    margin: 30,
    startTime: 0,
    endTime: 3,
    style: { fontSize: 36, fontColor: "white", shadowX: 2, shadowY: 2 },
  })
  .output("captioned.mp4")
  .execute();

Multiple text overlays ​

typescript
await ffmpeg.text()
  .input("video.mp4")
  .addText({
    text: "LIVE",
    anchor: "top-right",
    margin: 20,
    style: { fontSize: 24, fontColor: "red", bold: true },
  })
  .addText({
    text: "Speaker Name",
    anchor: "bottom-left",
    margin: 30,
    style: { fontSize: 32, fontColor: "white", box: true, boxColor: "black@0.6" },
  })
  .output("broadcast.mp4")
  .execute();

Result type ​

typescript
interface TextResult {
  outputPath: string;
  width: number;
  height: number;
  duration: number;
  size: number;
  probeResult: ProbeResult;
}