> ## Documentation Index
> Fetch the complete documentation index at: https://docs.videobgremover.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Video Composition Guide | Create Professional Video Layouts

> Create professional video compositions with custom backgrounds. Learn layering, positioning, and export formats for multi-layer video editing.

## 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.

> [card] 💻 Local Processing
>
> **FFmpeg-powered**: Runs on your machine, no internet required

> [card] 🆓 No Credits Used
>
> **Free operations**: Composition doesn't consume API credits

> [card] 🎬 Professional Quality
>
> **Production-ready**: Export in H.264, ProRes, WebM, PNG sequences

> [card] 🎯 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](https://docs.videobgremover.com/video-background-removal/overview.md))

**2. FFmpeg Installed**

FFmpeg must be available in your system PATH ([installation guide](https://docs.videobgremover.com/installation.md#ffmpeg-installation))

**3. SDK Installed**

Node.js or Python SDK ([installation guide](https://docs.videobgremover.com/installation.md))

## 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:

```typescript Node.js theme={"dark"}
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())
```

```python Python theme={"dark"}
from videobgremover import (
    Background, 
    Composition, 
    Foreground, 
    EncoderProfile, 
    Anchor, 
    SizeMode
)

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

# 2. Load transparent video (from background removal)
transparent = Foreground.from_webm_vp9('path/to/transparent.webm')

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

# 4. Export final video
comp.to_file('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:

```typescript Node.js theme={"dark"}
// 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)
```

```python Python theme={"dark"}
# Color background
bg = Background.from_color('#00FF00', 1920, 1080, 30)
comp = Composition(bg)
comp.add(transparent).at(Anchor.CENTER)

# Image background
bg = Background.from_image('background.jpg', fps=30)
comp = Composition(bg)
comp.add(transparent).at(Anchor.CENTER)
```

### Multi-Layer Composition

Layer multiple videos with different positioning:

```typescript Node.js theme={"dark"}
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)
```

```python Python theme={"dark"}
comp = 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, dx=-50, dy=50) \
    .size(SizeMode.CANVAS_PERCENT, percent=25) \
    .opacity(0.8)
```

### Timed Sequences

Control when layers appear and disappear:

```typescript Node.js theme={"dark"}
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)
```

```python Python theme={"dark"}
comp = 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?

> [card] [🎨 Create Backgrounds](https://docs.videobgremover.com/video-composition/backgrounds.md)
>
> Learn about color, image, and video backgrounds

> [card] [📐 Position Layers](https://docs.videobgremover.com/video-composition/positioning.md)
>
> Master precise positioning and sizing

> [card] [⏰ Control Timing](https://docs.videobgremover.com/video-composition/timing.md)
>
> Create timed sequences and animations

> [card] [🎬 Export Videos](https://docs.videobgremover.com/video-composition/export-formats.md)
>
> Choose the right export format for your needs


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.