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
textstringText content to render
anchorTextAnchor"bottom-center"Position anchor
marginnumber20Offset from anchor in pixels
xnumberAbsolute X position (overrides anchor)
ynumberAbsolute Y position (overrides anchor)
startTimenumber0When the text appears (seconds)
endTimenumberWhen the text disappears (seconds, omit for permanent)
styleTextStyleFont 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)
fontFilestringPath to .ttf font file
fontFamilystringSystem font family name
boldbooleanfalseBold weight
boxbooleanfalseDraw background box
boxColorstring"black@0.5"Box background color
boxBorderWidthnumber5Box padding in pixels
shadowXnumberDrop shadow X offset
shadowYnumberDrop 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;
}

Released under the MIT License.