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

# Aspect Ratio Control

> Control how assets scale when dimensions don't match the timeline. The fit parameter handles the mismatch (crop, letterbox, stretch), while position and offset control placement.

<a href="https://colab.research.google.com/github/video-db/videodb-cookbook/blob/main/editor/feature/fit_position_aspect_ratios.ipynb" target="_blank">
  <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" noZoom />
</a>

## Fit Modes

The fit parameter determines how an asset scales to match the timeline resolution.

### `Fit.crop` (default)

* Scales asset to fill viewport while maintaining aspect ratio
* Edges are cropped if aspect ratios differ

This is the default because it creates clean, full-frame compositions without black bars. The tradeoff is you might lose some content at the edges, but everything stays proportional and the frame stays filled.

<video controls width="100%">
  <source src="https://play.videodb.io/v1/2afa9530-7cc2-4ffe-8da5-2970411b2770.m3u8" type="application/x-mpegURL" />
</video>

### `Fit.contain`

* Scales asset to fit entirely within viewport while maintaining aspect ratio
* May add letterboxing (black bars) if aspect ratios differ

Use this when you need to guarantee that all of your content is visible, even if it means having black bars on the sides or top and bottom. Nothing gets cropped, but you sacrifice the full-frame look.

<video controls width="100%">
  <source src="https://play.videodb.io/v1/c7859b85-a155-410a-887f-d40e708eba88.m3u8" type="application/x-mpegURL" />
</video>

### `Fit.cover`

* Stretches asset to fill viewport, ignoring aspect ratio
* May cause distortion

This mode stretches the content to fill the frame regardless of proportions. You’ll rarely need this unless you specifically want the stretched effect, or you’re working with content that already matches your timeline’s aspect ratio exactly.

<video controls width="100%">
  <source src="https://play.videodb.io/v1/1d702af5-bc02-4a8e-8b06-cbdedf182fd2.m3u8" type="application/x-mpegURL" />
</video>

### `Fit.none`

* Preserves original pixel dimensions
* No scaling applied

This keeps your asset at its exact original size, which is useful for things like logos, overlays, or picture-in-picture effects where you want pixel-perfect control. The content appears at its native resolution regardless of timeline size.

<video controls width="100%">
  <source src="https://play.videodb.io/v1/b2b82fd7-bb8f-471b-b8c9-b6e74801a63a.m3u8" type="application/x-mpegURL" />
</video>

### Code Example

<CodeGroup>
  ```python Python theme={null}
  from videodb.editor import Fit

  clip = Clip(
      asset=VideoAsset(id=video.id),
      duration=10,
      fit=Fit.crop  # or Fit.contain, Fit.cover, Fit.none
  )
  ```

  ```javascript Node.js theme={null}
  import { Fit, Clip, VideoAsset } from 'videodb';

  const clip = new Clip({
      asset: new VideoAsset(video.id),
      duration: 10,
      fit: Fit.crop  // or Fit.contain, Fit.cover, Fit.none
  });
  ```
</CodeGroup>

Note: You can also use fit=None (Python None) which is equivalent to `Fit.none`.

## Position

The position parameter places the asset in one of 9 preset zones on the viewport. Think of your screen divided into a 3x3 grid - you can anchor your content to any of these zones, from corners to edges to dead center.

```
Position.top_left      Position.top        Position.top_right
Position.left          Position.center     Position.right
Position.bottom_left   Position.bottom     Position.bottom_right
```

**Example with `Position.left`**

<video controls width="100%">
  <source src="https://play.videodb.io/v1/1b627e7a-c60c-4c58-822a-ac088f1aaa49.m3u8" type="application/x-mpegURL" />
</video>

### Code Example

<CodeGroup>
  ```python Python theme={null}
  from videodb.editor import Position

  clip = Clip(
      asset=VideoAsset(id=video.id),
      duration=10,
      position=Position.top_left,
      fit=None
  )
  ```

  ```javascript Node.js theme={null}
  import { Position, Clip, VideoAsset } from 'videodb';

  const clip = new Clip({
      asset: new VideoAsset(video.id),
      duration: 10,
      position: Position.topLeft,
      fit: null
  });
  ```
</CodeGroup>

## Offset

The offset parameter provides fine-grained position control using relative coordinates. Sometimes the 9 preset zones aren’t quite right - maybe you want something centered but nudged slightly to the left, or positioned with a specific margin. That’s where offset comes in, letting you tweak positions with precision.

**Example `Offset(x=-0.25)`**

<video controls width="100%">
  <source src="https://play.videodb.io/v1/13f88e6d-7bfb-481f-9403-2676d8e17280.m3u8" type="application/x-mpegURL" />
</video>

### Code Example

<CodeGroup>
  ```python Python theme={null}
  from videodb.editor import Offset

  clip = Clip(
      asset=VideoAsset(id=video.id),
      duration=10,
      position=Position.center,
      offset=Offset(x=0.15, y=0.1)  # x: horizontal, y: vertical
  )
  ```

  ```javascript Node.js theme={null}
  import { Offset, Clip, VideoAsset, Position } from 'videodb';

  const clip = new Clip({
      asset: new VideoAsset(video.id),
      duration: 10,
      position: Position.center,
      offset: new Offset({ x: 0.15, y: 0.1 })  // x: horizontal, y: vertical
  });
  ```
</CodeGroup>

Coordinate System:

* `x` : Horizontal shift (`-1.0` to `1.0`)
  * Positive values move right
  * Negative values move left
* `y` : Vertical shift (`-1.0` to `1.0`)
  * Positive values move down
  * Negative values move up
* Values are relative to viewport dimensions

Example: `offset=Offset(x=0.1, y=0)` on a 1080px wide viewport moves the clip 108px to the right.

## Parameter Reference

| Parameter | Type     | Description                                                            |
| :-------- | :------- | :--------------------------------------------------------------------- |
| fit       | Fit      | Scaling behavior: `Fit.crop`, `Fit.contain`, `Fit.cover`, `Fit.none`   |
| position  | Position | Anchor point: `Position.top_left`, `Position.center`, etc. (9 options) |
| offset    | Offset   | Fine-tuning position with `x`/`y` coordinates                          |

<CodeGroup>
  ```python Python theme={null}
  from videodb.editor import Clip, VideoAsset, Fit, Position, Offset

  clip = Clip(
      asset=VideoAsset(id=video.id),
      duration=10,
      fit=Fit.crop,
      position=Position.right,
      offset=Offset(x=-0.1, y=0)
  )
  ```

  ```javascript Node.js theme={null}
  import { Clip, VideoAsset, Fit, Position, Offset } from 'videodb';

  const clip = new Clip({
      asset: new VideoAsset(video.id),
      duration: 10,
      fit: Fit.crop,
      position: Position.right,
      offset: new Offset({ x: -0.1, y: 0 })
  });
  ```
</CodeGroup>

## What You Can Build

<CardGroup cols={2}>
  <Card title="TikTok Lyric Videos" icon="music" href="/examples-and-tutorials/content-factory/tiktok-lyric-video">
    Create vertical 9:16 videos optimized for TikTok and Reels
  </Card>

  <Card title="Brand Elements" icon="image" href="/examples-and-tutorials/programmatic-editing/brand-elements">
    Position logos and overlays precisely using fit and offset
  </Card>

  <Card title="Faceless Video Creator" icon="film" href="/examples-and-tutorials/content-factory/faceless-video-creator">
    Control aspect ratios for multi-platform content
  </Card>
</CardGroup>

***

## Next Steps

<Card title="Fit, Position & Aspect Ratios" href="https://colab.research.google.com/github/video-db/videodb-cookbook/blob/main/editor/feature/fit_position_aspect_ratios.ipynb" icon="book-open">
  Hands-on experimentation with all fit modes, 9-zone positioning, and aspect ratio handling.
</Card>
