# Timeline Audio Mux

**What**：Place multiple audio clips into a video at their own time offsets — positioning and muxing the whole track in one call.

**When**：Use to anchor N audio clips (e.g. multiple voice lines or sound effects) at different moments of a video. mux only places a single track from 0s; here each clip carries its own offset in seconds.

## Endpoints
- POST `/v1/ffmpeg/jobs`
- GET `/v1/ffmpeg/jobs/{id}`

> This page uses the unified API: create with `POST /v1/ffmpeg/jobs` (`operation` names the operation), poll with `GET /v1/ffmpeg/jobs/{id}`. File upload still uses `POST /v1/ffmpeg/upload`.

Poll `GET /v1/ffmpeg/jobs/{id}` until `status` is `completed` or `failed`; a failed job is still HTTP 200 with `error`.

## Request params
| Param | Type | Required | Description |
| --- | --- | --- | --- |
| input_url | string | Yes | Input media URL on a trusted allowlist domain (platform CDN or a trusted-source CDN); upload first to obtain one, or use an asset URL already on a trusted CDN |
| audio_urls | string[] | Yes | Audio URL array, 1-100, all on allowlist domains |
| offsets | number[] | Yes | Start offset (sec) per audio; length must equal audioUrls, non-negative and non-decreasing |
| mode | string | — | replace drops the original track (default) / add mixes with it (auto-falls back to replace when the video has no audio track) |
| keepVideoLength | boolean | — | Whether output equals the video length: true (default) pads silence if short, trims if long; false leaves it unconstrained |
| webhook_url | string | — | Completion webhook URL (optional) |

Fields other than `operation` are the operation parameters; input slots use snake_case (`input_url`, `input_urls`, `image_url`, `audio_url`, `audio_urls`, `subtitle_url`, `webhook_url`); the old camelCase names are still accepted.

## Request example
```bash
curl https://api.novapi.ai/v1/ffmpeg/jobs \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "operation": "mux_timeline",
  "input_url": "https://cdn.novapi.ai/veo31/1788164205419_de868f9d69d445baaf577d42e87a236f.mp4",
  "audio_urls": [
    "https://cdn.novapi.ai/tmp/l1.mp3",
    "https://cdn.novapi.ai/tmp/l2.mp3"
  ],
  "offsets": [
    0,
    4.2
  ],
  "mode": "replace",
  "keepVideoLength": true
}'
```

```python
import os, requests

r = requests.post(
    "https://api.novapi.ai/v1/ffmpeg/jobs",
    headers={"Authorization": "Bearer " + os.environ["API_KEY"]},
    json={
        "operation": "mux_timeline",
        "input_url": "https://cdn.novapi.ai/veo31/1788164205419_de868f9d69d445baaf577d42e87a236f.mp4",
        "audio_urls": [
            "https://cdn.novapi.ai/tmp/l1.mp3",
            "https://cdn.novapi.ai/tmp/l2.mp3",
        ],
        "offsets": [
            0,
            4.2,
        ],
        "mode": "replace",
        "keepVideoLength": True,
    },
)
print(r.json())  # poll GET /v1/ffmpeg/jobs/{id} until status is completed
```

```ts
const resp = await fetch("https://api.novapi.ai/v1/ffmpeg/jobs", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "operation": "mux_timeline",
    "input_url": "https://cdn.novapi.ai/veo31/1788164205419_de868f9d69d445baaf577d42e87a236f.mp4",
    "audio_urls": [
      "https://cdn.novapi.ai/tmp/l1.mp3",
      "https://cdn.novapi.ai/tmp/l2.mp3"
    ],
    "offsets": [
      0,
      4.2
    ],
    "mode": "replace",
    "keepVideoLength": true
  }),
});
console.log(await resp.json()); // poll GET /v1/ffmpeg/jobs/{id} until status is completed
```

## Response example
```json
{
  "id": "<job-id>",
  "object": "ffmpeg.job",
  "operation": "mux_timeline",
  "status": "queued",
  "progress": 0,
  "cost": 0
}
```

```json
{
  "id": "<job-id>",
  "object": "ffmpeg.job",
  "operation": "mux_timeline",
  "status": "completed",
  "progress": 100,
  "result_url": "https://...",
  "cost": <points>
}
```

```bash
curl https://api.novapi.ai/v1/ffmpeg/jobs/<job-id> \
  -H "Authorization: Bearer $API_KEY"
```
