# Encode video with AV1

Use AV1 codec for smaller files at the same quality

AV1 produces files 30-50% smaller than h264 at comparable quality. The tradeoff is slower encoding -- which is where parallel chunked encoding helps.

"Streamline" (a video hosting platform like Vimeo) wants to cut bandwidth costs without degrading quality.

## API

<CodeGroup labels={["CLI", "TypeScript", "Python", "curl"]}>
```bash
ittybit video \
  -i https://streamline-app.com/uploads/talk.mov \
  --codec av1 \
  --format mp4 \
  --quality high
```

```typescript
const task = {
  input: 'https://streamline-app.com/uploads/talk.mov',
  kind: 'video',
  options: {
    codec: 'av1',
    format: 'mp4',
    quality: 'high',
  },
};

const res = await fetch('https://api.ittybit.com/jobs', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.ITTYBIT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(task),
});
const data = await res.json();
```

```python

task = {
    "input": "https://streamline-app.com/uploads/talk.mov",
    "kind": "video",
    "options": {
        "codec": "av1",
        "format": "mp4",
        "quality": "high",
    },
}

res = requests.post(
    "https://api.ittybit.com/jobs",
    headers={"Authorization": f"Bearer {api_key}"},
    json=task,
)
data = res.json()
```

```bash
TASK='{
  "input": "https://streamline-app.com/uploads/talk.mov",
  "kind": "video",
  "options": {
    "codec": "av1",
    "format": "mp4",
    "quality": "high"
  }
}'

curl -X POST https://api.ittybit.com/jobs \
  -H "Authorization: Bearer $ITTYBIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$TASK"
```

</CodeGroup>

## CLI

```bash
ittybit video \
  -i talk.mov \
  -o talk-av1.mp4 \
  --codec av1 \
  --quality high
```

## Codec comparison

| Codec  | Container | Browser support | File size    | Encode speed |
| ------ | --------- | --------------- | ------------ | ------------ |
| `h264` | mp4       | Everything      | Baseline     | Fast         |
| `h265` | mp4       | Safari, Edge    | ~30% smaller | Medium       |
| `vp9`  | webm      | Chrome, Firefox | ~30% smaller | Medium       |
| `av1`  | mp4, webm | Modern browsers | ~40% smaller | Slow\*       |

\*AV1 encoding is slow sequentially. Ittybit splits the video into chunks and encodes them in parallel -- on managed cloud, this is up to 200x faster than sequential.

## With fallback

Encode both h264 (universal) and AV1 (smaller). Serve AV1 to browsers that support it:

```bash
ittybit video \
  -i talk.mov \
  -o talk-h264.mp4 \
  --codec h264 \
  --quality high

ittybit video \
  -i talk.mov \
  -o talk-av1.mp4 \
  --codec av1 \
  --quality high
```