> ## 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 Background Removal Examples

> Ready-to-use code examples for video background removal. Complete Node.js, Python, and cURL examples with step-by-step workflows and best practices.

## Basic Examples

### Simple Background Replacement

Remove background and overlay on a colored background.

<CodeGroup>
  ```typescript Node.js theme={"dark"}
  // 1. Remove background from video
  import { VideoBGRemoverClient, Video, Background, Composition, EncoderProfile, Anchor, SizeMode } from '@videobgremover/sdk'

  const client = new VideoBGRemoverClient('your_api_key')
  const video = Video.open('input.mp4')
  const transparent = await video.removeBackground(client)

  // 2. Add to colored background
  const background = Background.fromColor('#FF6B35', 1920, 1080, 30)
  const comp = new Composition(background)
  comp.add(transparent, 'main').at(Anchor.CENTER).size(SizeMode.CONTAIN)

  // 3. Export
  await comp.toFile('output.mp4', EncoderProfile.h264())
  console.log('✅ Background replaced!')
  ```

  ```python Python theme={"dark"}
  # 1. Remove background from video
  from videobgremover import VideoBGRemoverClient, Video, Background, Composition, EncoderProfile, Anchor, SizeMode

  client = VideoBGRemoverClient('your_api_key')
  video = Video.open('input.mp4')
  transparent = video.remove_background(client)

  # 2. Add to colored background
  background = Background.from_color('#FF6B35', 1920, 1080, 30)
  comp = Composition(background)
  comp.add(transparent, 'main').at(Anchor.CENTER).size(SizeMode.CONTAIN)

  # 3. Export
  comp.to_file('output.mp4', EncoderProfile.h264())
  print('✅ Background replaced!')
  ```
</CodeGroup>

## AI UGC Ads

### AI Avatar on Video Background

Create professional UGC ads with AI avatars positioned bottom-right.

<CodeGroup>
  ```typescript Node.js theme={"dark"}
  import {
    VideoBGRemoverClient, Video, Background, Composition,
    EncoderProfile, Anchor, SizeMode, RemoveBGOptions, Prefer
  } from '@videobgremover/sdk'

  async function createAIUGCAd() {
    // 1. Remove background from AI actor
    const client = new VideoBGRemoverClient('your_api_key')
    const aiActor = Video.open('ai_actor_video.mp4')

    const options = new RemoveBGOptions(Prefer.WEBM_VP9)
    const transparentActor = await aiActor.removeBackground(client, options)

    // 2. Create video background
    const background = Background.fromVideo('product_showcase.mp4')
    const comp = new Composition(background)

    // 3. Position AI avatar bottom-right (35% of canvas)
    comp.add(transparentActor, 'ai_avatar')
      .at(Anchor.BOTTOM_RIGHT, -50, -50)  // 50px from edges
      .size(SizeMode.CANVAS_PERCENT, { percent: 35 })
      .opacity(0.95)  // Slight transparency for polish

    // 4. Export for ads
    await comp.toFile('ai_ugc_ad.mp4', EncoderProfile.h264({
      crf: 20,
      preset: 'medium'
    }))

    console.log('✅ AI UGC ad created: ai_ugc_ad.mp4')
  }

  createAIUGCAd()
  ```

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

  def create_ai_ugc_ad():
      # 1. Remove background from AI actor
      client = VideoBGRemoverClient('your_api_key')
      ai_actor = Video.open('ai_actor_video.mp4')

      options = RemoveBGOptions(prefer=Prefer.WEBM_VP9)
      transparent_actor = ai_actor.remove_background(client, options)

      # 2. Create video background
      background = Background.from_video('product_showcase.mp4')
      comp = Composition(background)

      # 3. Position AI avatar bottom-right (35% of canvas)
      comp.add(transparent_actor, 'ai_avatar') \
          .at(Anchor.BOTTOM_RIGHT, dx=-50, dy=-50) \
          .size(SizeMode.CANVAS_PERCENT, percent=35) \
          .opacity(0.95)

      # 4. Export for ads
      comp.to_file('ai_ugc_ad.mp4', EncoderProfile.h264(crf=20, preset='medium'))

      print('✅ AI UGC ad created: ai_ugc_ad.mp4')

  create_ai_ugc_ad()
  ```
</CodeGroup>

## Dynamic Social Media Content

### Interactive Positioning with Transparency Effects

Create engaging social media content with moving elements and transparency changes.

<CodeGroup>
  ```typescript Node.js theme={"dark"}
  async function createDynamicSocialContent() {
    // 1. Process content video
    const client = new VideoBGRemoverClient('your_api_key')
    const contentVideo = Video.open('dynamic_content.mp4')
    const transparent = await contentVideo.removeBackground(client)

    // 2. Create vertical background video (9:16 for social)
    const background = Background.fromVideo('trending_background.mp4')
    const comp = new Composition(background)

    // 3. Dynamic positioning sequence
    // 0-3s: Bottom-right with transparency
    comp.add(transparent.subclip(0, 3), 'phase1')
      .start(0).duration(3)
      .at(Anchor.BOTTOM_RIGHT, -30, -30)
      .size(SizeMode.CANVAS_PERCENT, { percent: 40 })
      .alpha(true)
      .opacity(0.8)

    // 3-6s: Top-left without transparency
    comp.add(transparent.subclip(3, 6), 'phase2')
      .start(3).duration(3)
      .at(Anchor.TOP_LEFT, 30, 30)
      .size(SizeMode.CANVAS_PERCENT, { percent: 35 })
      .alpha(false)
      .opacity(1.0)

    // 6-9s: Center with partial transparency
    comp.add(transparent.subclip(6, 9), 'phase3')
      .start(6).duration(3)
      .at(Anchor.CENTER)
      .size(SizeMode.CANVAS_PERCENT, { percent: 50 })
      .alpha(true)
      .opacity(0.6)

    // 9-12s: Bottom-left with full transparency
    comp.add(transparent.subclip(9, 12), 'phase4')
      .start(9).duration(3)
      .at(Anchor.BOTTOM_LEFT, 30, -30)
      .size(SizeMode.CANVAS_PERCENT, { percent: 45 })
      .alpha(true)
      .opacity(0.9)

    // 4. Export for social media
    await comp.toFile('dynamic_social_content.mp4', EncoderProfile.h264({
      crf: 25,
      preset: 'fast'
    }))

    console.log('✅ Dynamic social content created')
  }

  createDynamicSocialContent()
  ```

  ```python Python theme={"dark"}
  def create_dynamic_social_content():
      # 1. Process content video
      client = VideoBGRemoverClient('your_api_key')
      content_video = Video.open('dynamic_content.mp4')
      transparent = content_video.remove_background(client)

      # 2. Create vertical background video
      background = Background.from_video('trending_background.mp4')
      comp = Composition(background)

      # 3. Dynamic positioning sequence
      # 0-3s: Bottom-right with transparency
      comp.add(transparent.subclip(0, 3), 'phase1') \
          .start(0).duration(3) \
          .at(Anchor.BOTTOM_RIGHT, dx=-30, dy=-30) \
          .size(SizeMode.CANVAS_PERCENT, percent=40) \
          .alpha(enabled=True) \
          .opacity(0.8)

      # 3-6s: Top-left without transparency
      comp.add(transparent.subclip(3, 6), 'phase2') \
          .start(3).duration(3) \
          .at(Anchor.TOP_LEFT, dx=30, dy=30) \
          .size(SizeMode.CANVAS_PERCENT, percent=35) \
          .alpha(enabled=False) \
          .opacity(1.0)

      # 6-9s: Center with partial transparency
      comp.add(transparent.subclip(6, 9), 'phase3') \
          .start(6).duration(3) \
          .at(Anchor.CENTER) \
          .size(SizeMode.CANVAS_PERCENT, percent=50) \
          .alpha(enabled=True) \
          .opacity(0.6)

      # 9-12s: Bottom-left with full transparency
      comp.add(transparent.subclip(9, 12), 'phase4') \
          .start(9).duration(3) \
          .at(Anchor.BOTTOM_LEFT, dx=30, dy=-30) \
          .size(SizeMode.CANVAS_PERCENT, percent=45) \
          .alpha(enabled=True) \
          .opacity(0.9)

      # 4. Export for social media
      comp.to_file('dynamic_social_content.mp4', EncoderProfile.h264(
          crf=25, preset='fast'
      ))

      print('✅ Dynamic social content created')

  create_dynamic_social_content()
  ```
</CodeGroup>

## Next Steps

<CardGroup cols={3}>
  <Card title="📖 API Reference" icon="code" href="/api-reference/introduction">
    Complete API documentation for all classes and methods
  </Card>

  <Card title="🎬 Background Removal Guide" icon="scissors" href="/video-background-removal/guide">
    Detailed guide to background removal options and formats
  </Card>

  <Card title="🎨 Video Composition Guide" icon="layers" href="/video-composition/overview">
    Learn advanced composition techniques and effects
  </Card>
</CardGroup>
