Skip to content

Overlay ​

Composite images or videos over a base video — watermarks, picture-in-picture, chroma key, and more.

Quick example ​

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

await ffmpeg.overlay()
  .base("video.mp4")
  .watermark({ input: "logo.png", position: "top-right", opacity: 0.8 })
  .output("watermarked.mp4")
  .execute();

API ​

.base(path) ​

Base video to overlay onto. Required.

.watermark(options) ​

Add a static image overlay (logo, bug, watermark).

ParameterTypeDefaultDescription
inputstring—Path to the watermark image
positionOverlayPosition"top-right"Where to place the watermark
opacitynumber1.0Opacity 0–1
marginnumber10Margin from edges in pixels
scalenumber—Scale factor relative to video width

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

.pip(options) ​

Picture-in-picture: place a video over the base.

ParameterTypeDefaultDescription
inputstring—PiP video path
positionOverlayPosition"bottom-right"Where to place the PiP
scalenumber0.25PiP size as fraction of base width
marginnumber10Margin from edges

.chromaKey(options) ​

Remove a solid-color background (green screen / chroma key).

ParameterTypeDefaultDescription
inputstring—Foreground video with chroma key background
colorstring"green"Key color (hex or name)
similaritynumber0.1Color similarity threshold 0–1
blendnumber0.0Edge blending 0–1

.output(path) ​

Output file path. Required.

Examples ​

Logo watermark ​

typescript
await ffmpeg.overlay()
  .base("video.mp4")
  .watermark({
    input: "logo.png",
    position: "bottom-right",
    opacity: 0.7,
    margin: 20,
  })
  .output("branded.mp4")
  .execute();

Picture-in-picture ​

typescript
await ffmpeg.overlay()
  .base("presentation.mp4")
  .pip({
    input: "webcam.mp4",
    position: "bottom-right",
    scale: 0.2,
    margin: 16,
  })
  .output("pip.mp4")
  .execute();

Green screen composite ​

typescript
await ffmpeg.overlay()
  .base("background.mp4")
  .chromaKey({
    input: "presenter-greenscreen.mp4",
    color: "#00ff00",
    similarity: 0.15,
    blend: 0.05,
  })
  .output("composite.mp4")
  .execute();

Result type ​

typescript
interface OverlayResult {
  outputPath: string;
  width: number;
  height: number;
  duration: number;
  size: number;
  probeResult: ProbeResult;
}
  • Text — burn text overlays
  • Transform — scale and crop the base video