Skip to main content

What is Video Composition?

Video composition lets you layer transparent videos with custom backgrounds, effects, and positioning to create professional-looking videos. This happens locally on your machine using FFmpeg - no API calls or credits required.

๐Ÿ’ป Local Processing

FFmpeg-powered: Runs on your machine, no internet required

๐Ÿ†“ No Credits Used

Free operations: Composition doesnโ€™t consume API credits

๐ŸŽฌ Professional Quality

Production-ready: Export in H.264, ProRes, WebM, PNG sequences

๐ŸŽฏ Precise Control

Pixel-perfect: Position, scale, and time everything exactly

Prerequisites

Before you can create compositions, you need:
1

Transparent Videos

Videos with removed backgrounds (from background removal)
2

FFmpeg Installed

FFmpeg must be available in your system PATH (installation guide)
3

SDK Installed

Node.js or Python SDK (installation guide)

How It Works

1

Create Background

Choose from colors, images, or video backgrounds
2

Add Layers

Layer your transparent videos with precise positioning
3

Apply Effects

Control opacity, rotation, timing, and scaling
4

Export

Render locally using FFmpeg in your preferred format

Quick Example

Hereโ€™s a complete composition workflow:
import { 
  Background, 
  Composition, 
  Foreground, 
  EncoderProfile, 
  Anchor, 
  SizeMode 
} from '@videobgremover/sdk'

// 1. Create custom background
const background = Background.fromColor('#FF0000', 1920, 1080, 30)

// 2. Load transparent video (from background removal)
const transparent = Foreground.fromUrl('path/to/transparent.webm', {
  format: 'webm_vp9'
})

// 3. Create composition
const comp = new Composition(background)
comp.add(transparent, 'main_video')
  .at(Anchor.CENTER)
  .size(SizeMode.CONTAIN)
  .opacity(0.9)

// 4. Export final video
await comp.toFile('final_video.mp4', EncoderProfile.h264())

Key Concepts

Backgrounds

Create the foundation for your composition:
  • Color backgrounds: Solid colors using hex codes
  • Image backgrounds: Static images (automatically looped)
  • Video backgrounds: Dynamic video backgrounds
  • Empty backgrounds: Transparent canvas for overlays

Layers

Stack multiple transparent videos:
  • Positioning: Use anchors (CENTER, TOP_LEFT, etc.) with pixel offsets
  • Sizing: Fit, cover, exact pixels, or percentage of canvas
  • Effects: Opacity, rotation, cropping
  • Timing: Control when layers appear and disappear

Export Formats

Render your final video:
  • H.264 MP4: Universal compatibility, good compression
  • VP9 WebM: Web-optimized, excellent compression
  • ProRes MOV: Professional editing, highest quality
  • PNG Sequence: Frame-by-frame work, maximum quality

Composition Types

Simple Replacement

Replace video background with a solid color or image:
// Color background
const bg = Background.fromColor('#00FF00', 1920, 1080, 30)
const comp = new Composition(bg)
comp.add(transparent).at(Anchor.CENTER)

// Image background
const bg = Background.fromImage('background.jpg', 30)
const comp = new Composition(bg)
comp.add(transparent).at(Anchor.CENTER)

Multi-Layer Composition

Layer multiple videos with different positioning:
const comp = new Composition(background)

// Main video (full screen)
comp.add(video1, 'main')
  .at(Anchor.CENTER)
  .size(SizeMode.CONTAIN)

// Picture-in-picture (small, top-right)
comp.add(video2, 'pip')
  .at(Anchor.TOP_RIGHT, -50, 50)
  .size(SizeMode.CANVAS_PERCENT, { percent: 25 })
  .opacity(0.8)

Timed Sequences

Control when layers appear and disappear:
const comp = new Composition(background)

// Video appears at 2 seconds, lasts 5 seconds
comp.add(video1, 'intro')
  .start(2.0)
  .duration(5.0)
  .at(Anchor.CENTER)

// Video appears at 8 seconds, ends at 15 seconds  
comp.add(video2, 'outro')
  .start(8.0)
  .end(15.0)
  .at(Anchor.TOP_RIGHT)

Requirements

  • FFmpeg: Must be installed and available in PATH
  • Transparent videos: From background removal or other sources
  • System resources: Composition happens locally on your machine

Whatโ€™s Next?