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

<CardGroup cols={2}>
  <Card title="💻 Local Processing" icon="desktop">
    **FFmpeg-powered**: Runs on your machine, no internet required
  </Card>

  <Card title="🆓 No Credits Used" icon="coins">
    **Free operations**: Composition doesn't consume API credits
  </Card>

  <Card title="🎬 Professional Quality" icon="film">
    **Production-ready**: Export in H.264, ProRes, WebM, PNG sequences
  </Card>

  <Card title="🎯 Precise Control" icon="crosshairs">
    **Pixel-perfect**: Position, scale, and time everything exactly
  </Card>
</CardGroup>

## Prerequisites

Before you can create compositions, you need:

<Steps>
  <Step title="Transparent Videos">
    Videos with removed backgrounds (from [background removal](/video-background-removal/overview))
  </Step>

  <Step title="FFmpeg Installed">
    FFmpeg must be available in your system PATH ([installation guide](/installation#ffmpeg-installation))
  </Step>

  <Step title="SDK Installed">
    Node.js or Python SDK ([installation guide](/installation))
  </Step>
</Steps>

## How It Works

<Steps>
  <Step title="Create Background">
    Choose from colors, images, or video backgrounds
  </Step>

  <Step title="Add Layers">
    Layer your transparent videos with precise positioning
  </Step>

  <Step title="Apply Effects">
    Control opacity, rotation, timing, and scaling
  </Step>

  <Step title="Export">
    Render locally using FFmpeg in your preferred format
  </Step>
</Steps>

## Quick Example

Here's a complete composition workflow:

<CodeGroup>
  ```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())
  ```
</CodeGroup>

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

<CodeGroup>
  ```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)
  ```
</CodeGroup>

### Multi-Layer Composition

Layer multiple videos with different positioning:

<CodeGroup>
  ```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)
  ```
</CodeGroup>

### Timed Sequences

Control when layers appear and disappear:

<CodeGroup>
  ```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)
  ```
</CodeGroup>

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

<CardGroup cols={2}>
  <Card title="🎨 Create Backgrounds" icon="palette" href="/video-composition/backgrounds">
    Learn about color, image, and video backgrounds
  </Card>

  <Card title="📐 Position Layers" icon="move" href="/video-composition/positioning">
    Master precise positioning and sizing
  </Card>

  <Card title="⏰ Control Timing" icon="clock" href="/video-composition/timing">
    Create timed sequences and animations
  </Card>

  <Card title="🎬 Export Videos" icon="film" href="/video-composition/export-formats">
    Choose the right export format for your needs
  </Card>
</CardGroup>
