# ffmpeg API — convert, compress, trim, GIF, thumbnail (`synthetic.ia/ffmpeg-api`) Actor

Run ffmpeg over HTTP: POST a media URL to /convert, /compress, /trim, /gif, /thumbnail or /extract-audio and get the result back. Pay per operation, no infrastructure.

- **URL**: https://apify.com/synthetic.ia/ffmpeg-api.md
- **Developed by:** [Synthetic](https://apify.com/synthetic.ia) (community)
- **Categories:** Developer tools, Videos
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $20.00 / 1,000 media operations

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## ffmpeg API — media processing over HTTP

Run **ffmpeg in the cloud without any infrastructure**. Send a media URL to an endpoint and get the processed file back. Convert, compress, trim, make GIFs, grab thumbnails or extract audio — all pay-per-operation, no server to manage, no ffmpeg to install.

- ⚡ **HTTP API (Standby)**: `POST /<operation>` with a JSON body, get a JSON reply with a link to the result
- 🔒 **Safe by design**: you send URLs and parameters, never raw shell commands
- 💵 **Pay per operation**, from **$0.02**
- 🤖 Callable from any language, from n8n/Make/Zapier, or from an AI agent

### Endpoints

Base URL (Standby): `https://synthetic-ia--ffmpeg-api.apify.actor` with header `Authorization: Bearer <APIFY_TOKEN>`.

| Endpoint | Body | Does |
|---|---|---|
| `POST /convert` | `{ url, format: mp4\|webm\|mkv\|mov }` | Transcode to another container/codec |
| `POST /compress` | `{ url, crf?: 18-40, preset?: ultrafast..slow }` | Re-encode smaller (H.264) |
| `POST /trim` | `{ url, start?, duration? }` | Cut a clip (seconds or HH:MM:SS) |
| `POST /gif` | `{ url, start?, duration?: 0.5-15, fps?: 4-30, width?: 120-1080 }` | High-quality GIF from a clip |
| `POST /thumbnail` | `{ url, time?, width?: 120-1920 }` | Still JPG at a moment |
| `POST /extract-audio` | `{ url, format: mp3\|aac\|m4a\|wav\|ogg\|flac }` | Pull the audio track |
| `POST /advanced` | `{ inputs:[url,…], filterComplex?, map?, outputFormat, videoCodec?, audioCodec?, crf?, preset?, videoBitrate?, audioBitrate?, fps?, size?, pixFmt? }` | **Full ffmpeg**: any filtergraph + codecs, safely validated |
| `POST /async` | `{ operation, …params }` → `{ runId }` | Start a long job; then `GET /status/<runId>` |
| `GET /status/<runId>` | — | Poll an async job; returns the result when done |

`GET /` returns this list as JSON.

#### Full power — `/advanced`

Expose (almost) everything ffmpeg can do through a validated interface: pass up to 4 inputs and a `filterComplex` graph (overlays, concat, scaling, color, speed, watermarks, hstack/vstack…), pick codecs/format/bitrate/fps/size. For safety, file-access filters (`movie`, `subtitles`, …) and extra inputs are rejected — you can't read the server's files.

```bash
curl -X POST "https://synthetic-ia--ffmpeg-api.apify.actor/advanced" \
  -H "Authorization: Bearer $APIFY_TOKEN" -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/clip.mp4","filterComplex":"[0:v]scale=720:-1,hue=s=0[v]","map":["[v]"],"outputFormat":"mp4","crf":24}'
```

#### Long jobs — `/async`

Heavy transcodes can exceed the 4-minute synchronous window. Start them async and poll:

```bash
RID=$(curl -s -X POST ".../async" -H "Authorization: Bearer $APIFY_TOKEN" -d '{"operation":"convert","url":"…","format":"webm"}' | jq -r .runId)
curl ".../status/$RID" -H "Authorization: Bearer $APIFY_TOKEN"   # → { "status": "SUCCEEDED", "result": { "url": "…" } }
```

#### Response

```json
{ "ok": true, "operation": "gif", "url": "https://api.apify.com/v2/key-value-stores/.../records/output/gif-....gif", "contentType": "image/gif", "sizeBytes": 812345, "tookMs": 1840 }
```

### Example

```bash
curl -X POST "https://synthetic-ia--ffmpeg-api.apify.actor/gif" \
  -H "Authorization: Bearer $APIFY_TOKEN" -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/clip.mp4","start":"0:03","duration":4,"width":480}'
```

Prefer a one-off run? Start the Actor normally with input `{ "operation": "compress", "url": "https://…", "crf": 30 }`.

### Limits

- Input **max 250 MB**, http(s) URLs only.
- Synchronous response under **4 minutes** — great for clips, thumbnails, GIFs, conversions. For very long transcodes, run it as a normal (async) Actor run.
- No GPU (Apify is CPU-only), so no hardware encoding; H.264/VP9 software encoding is used.

### Pricing

**Per successful operation**, from **$0.02** on higher plans (platform usage included). You only pay when an operation succeeds.

### FAQ

**Can I send raw ffmpeg commands?** No — for security you use the endpoints above with parameters. This covers the common operations safely. Need another operation exposed? Open an issue.

**Where does the output go?** To the run's key-value store; the response gives you a direct URL to download it.

# Changelog

This Actor's version history is a separate document: https://apify.com/synthetic.ia/ffmpeg-api/changelog.md

# Actor input Schema

## `operation` (type: `string`):

What to do with the input media.

## `url` (type: `string`):

Direct http(s) URL to the input video/audio (max 250 MB).

## `format` (type: `string`):

For convert (mp4|webm|mkv|mov) or extract-audio (mp3|aac|m4a|wav|ogg|flac).

## `crf` (type: `integer`):

Compress: 18 (high quality/larger) to 40 (low/smaller). Default 28.

## `start` (type: `string`):

Trim/GIF: start, seconds or HH:MM:SS.

## `duration` (type: `number`):

Trim/GIF: length in seconds.

## `time` (type: `string`):

Thumbnail: which moment to capture (seconds or HH:MM:SS).

## `width` (type: `integer`):

GIF/thumbnail output width; height auto.

## `fps` (type: `integer`):

GIF frames per second (4-30).

## `filterComplex` (type: `string`):

Advanced only: an ffmpeg -filter\_complex string. File-access filters (movie, subtitles, etc.) are blocked.

## `outputFormat` (type: `string`):

Advanced only: mp4|webm|mkv|mov|gif|mp3|m4a|wav|ogg|flac|png|jpg|webp.

## `videoCodec` (type: `string`):

Advanced only: libx264|libx265|libvpx-vp9|mpeg4|copy…

## `audioCodec` (type: `string`):

Advanced only: aac|libmp3lame|libopus|copy…

## Actor input object example

```json
{
  "operation": "thumbnail",
  "url": "https://download.samplelib.com/mp4/sample-5s.mp4",
  "format": "mp4",
  "crf": 28,
  "start": "0",
  "duration": 4,
  "time": "1",
  "width": 640,
  "fps": 12,
  "outputFormat": "mp4"
}
```

# Actor output Schema

## `result` (type: `string`):

The processed file and its URL.

## `runs` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "format": "mp4",
    "crf": 28,
    "start": "0",
    "duration": 4,
    "time": "1",
    "width": 640,
    "fps": 12,
    "outputFormat": "mp4"
};

// Run the Actor and wait for it to finish
const run = await client.actor("synthetic.ia/ffmpeg-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "format": "mp4",
    "crf": 28,
    "start": "0",
    "duration": 4,
    "time": "1",
    "width": 640,
    "fps": 12,
    "outputFormat": "mp4",
}

# Run the Actor and wait for it to finish
run = client.actor("synthetic.ia/ffmpeg-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "format": "mp4",
  "crf": 28,
  "start": "0",
  "duration": 4,
  "time": "1",
  "width": 640,
  "fps": 12,
  "outputFormat": "mp4"
}' |
apify call synthetic.ia/ffmpeg-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,synthetic.ia/ffmpeg-api"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/HtofNOaF72YrBBxbk/builds/txt5EFEsHqY69EGL8/openapi.json
