# 视频转 GIF

**这是什么**：把视频片段转成 GIF 动图。

**什么时候用**：想做表情包/动图预览时用。

## 接口地址
- POST `/v1/ffmpeg/jobs`
- GET `/v1/ffmpeg/jobs/{id}`

> 本页已按统一 API 改写：创建用 `POST /v1/ffmpeg/jobs`（`operation` 指定操作），轮询用 `GET /v1/ffmpeg/jobs/{id}`。文件上传仍使用 `POST /v1/ffmpeg/upload`。

轮询 `GET /v1/ffmpeg/jobs/{id}`，直到 `status` 为 `completed` 或 `failed`；失败的任务也是 HTTP 200，带 `error`。

## 请求参数
| 参数 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| input_url | string | 是 | 输入媒体 URL，须为受信白名单域名（平台 CDN 或受信来源 CDN）；可先用 upload 上传获取，或直接用已在受信 CDN 上的素材 URL |
| fps | integer | — | 帧率 [5,25]，默认 12 |
| width | integer | — | 宽度像素 [160,720]，等比缩放，默认 480 |
| start | number | — | 起始秒，默认 0 |
| duration | number | — | 截取时长（秒），默认全长 |
| webhook_url | string | — | 完成回调地址（可选） |

请求体里除 `operation` 外的字段是本操作的参数；输入槽位用 snake_case（`input_url`、`input_urls`、`image_url`、`audio_url`、`audio_urls`、`subtitle_url`、`webhook_url`），旧的 camelCase 名仍被接受。

## 请求示例
```bash
curl https://api.novapi.ai/v1/ffmpeg/jobs \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "operation": "to_gif",
  "input_url": "https://cdn.novapi.ai/veo31/1788164205419_de868f9d69d445baaf577d42e87a236f.mp4",
  "fps": 12,
  "width": 480,
  "start": 2,
  "duration": 5
}'
```

```python
import os, requests

r = requests.post(
    "https://api.novapi.ai/v1/ffmpeg/jobs",
    headers={"Authorization": "Bearer " + os.environ["API_KEY"]},
    json={
        "operation": "to_gif",
        "input_url": "https://cdn.novapi.ai/veo31/1788164205419_de868f9d69d445baaf577d42e87a236f.mp4",
        "fps": 12,
        "width": 480,
        "start": 2,
        "duration": 5,
    },
)
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": "to_gif",
    "input_url": "https://cdn.novapi.ai/veo31/1788164205419_de868f9d69d445baaf577d42e87a236f.mp4",
    "fps": 12,
    "width": 480,
    "start": 2,
    "duration": 5
  }),
});
console.log(await resp.json()); // poll GET /v1/ffmpeg/jobs/{id} until status is completed
```

## 响应示例
```json
{
  "id": "<job-id>",
  "object": "ffmpeg.job",
  "operation": "to_gif",
  "status": "queued",
  "progress": 0,
  "cost": 0
}
```

```json
{
  "id": "<job-id>",
  "object": "ffmpeg.job",
  "operation": "to_gif",
  "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"
```
