# Sawfish – FFmpeg Video API for AI Agents (`zyonelvis/sawfish`) Actor

Pay-per-task FFmpeg API for developers and AI agents. Probe, trim, extract audio, normalize loudness, contact sheets and subtitle burn-in, plus ready recipes for vision LLMs, speech-to-text and 9:16 shorts. Send a URL, get files and JSON back.

- **URL**: https://apify.com/zyonelvis/sawfish.md
- **Developed by:** [Sawfish Labs](https://apify.com/zyonelvis) (community)
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $9.00 / 1,000 recipe: vision prep

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/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

## Sawfish — FFmpeg Video & Audio Task API for Devs & AI Agents

**Sawfish** is a pay-per-event FFmpeg media processing Actor built for **developers, automation workflows, and AI agents**.

Pass a public HTTPS media URL or an Apify Key-Value Store record, select one of **6 atomic FFmpeg operations** or **3 AI-ready chained recipes**, and receive structured JSON in the Dataset plus public Key-Value Store download URLs for generated media files.

### Why use Sawfish?

- **Feed video to vision LLMs:** get a timestamped frame grid + JSON manifest instead of uploading the whole video (`recipe/vision-prep`).
- **Clean audio for speech-to-text:** 16 kHz mono WAV, loudness-normalized, ready for Whisper, Gemini or any STT (`recipe/transcribe-prep`).
- **Automate Shorts / Reels / TikTok clips:** trim + 9:16 crop + -14 LUFS audio in one call (`recipe/shorts-prep`).
- **No FFmpeg server to maintain:** no install, no queue, no idle cost. Call it from n8n, Make, Zapier, your code or an AI agent.
- **Pay only for what works:** failed or timed-out tasks cost only the $0.0005 start fee, and your spending limit is checked before processing.

### How much does it cost?

Typical total per task (start event + operation, files up to 60 s):

| Task | Approx. cost per run | Per 1,000 runs |
|---|---:|---:|
| `probe` | $0.002 | $2.00 |
| `extract-audio` | $0.0065 | $6.50 |
| `contact-sheet` | $0.0075 | $7.50 |
| `trim` | $0.0075 | $7.50 |
| `recipe/vision-prep` | $0.0095 | $9.50 |
| `normalize-audio` | $0.0105 | $10.50 |
| `recipe/transcribe-prep` | $0.0115 | $11.50 |
| `recipe/shorts-prep` | $0.0165 | $16.50 |
| `burn-subtitles` | $0.0185 | $18.50 |

Longer media adds `$0.004` per started minute beyond 60 s on time-based operations. Full event table below.

***

### What Sawfish Does

#### 3 Chained AI Recipes (single run = multi-step pipeline)

| Operation | Pipeline Steps | Output |
|---|---|---|
| `recipe/vision-prep` | Runs `probe`, extracts a timestamped contact sheet using **exact real source PTS** (`select` + `showinfo`, `-fps_mode passthrough`), and returns a structured JSON manifest (`metadata`, `grid`, `frame_timestamps_sec`, `vision_hint`) for multimodal vision models | `.jpg` or `.webp` + JSON manifest |
| `recipe/transcribe-prep` | Extracts audio, downmixes to **mono 16 kHz**, applies 2-pass EBU R128 loudness normalization (**-16 LUFS** default), and exports 16-bit PCM WAV ready for speech-to-text | `.wav` |
| `recipe/shorts-prep` | Trims `[start_sec, end_sec]`, reframes to **9:16 vertical** (`720x1280` or `1080x1920`), and applies 2-pass EBU R128 loudness normalization (**-14 LUFS** default) | `.mp4` |

#### 6 Atomic Operations

| Operation | Description | Output |
|---|---|---|
| `probe` | Technical metadata: container, duration, file size, bitrate, video/audio codecs, resolution, FPS, sample rate, channels | JSON only (Dataset + KVS `OUTPUT`) |
| `extract-audio` | Extracts audio as `mp3` or `wav` (`16000`, `44100`, or `48000` Hz, mono or stereo) | `.mp3` or `.wav` |
| `contact-sheet` | Generates a `cols x rows` grid (`jpg` or `webp`) with optional burned-in exact source PTS timestamps and `frame_timestamps_sec` JSON | `.jpg` or `.webp` |
| `trim` | Cuts `[start_sec, end_sec]` in `fast` (stream copy) or `accurate` (frame-exact re-encode) mode | `.mp4` or `.mp3` |
| `normalize-audio` | 2-pass EBU R128 loudness normalization (`target_lufs`, `true_peak`) keeping container or exporting `mp3`, `wav`, or `mp4` | Original format, `.mp3`, `.wav`, or `.mp4` |
| `burn-subtitles` | Hardcodes `srt` or `ass` captions with configurable font size, hex colors, and vertical position (max **720p** and **60 s**) | `.mp4` |

***

### Usage Examples

#### 1. Apify Console (JSON Input)

Run `recipe/vision-prep` on a public HTTPS video URL:

```json
{
  "operation": "recipe/vision-prep",
  "video_url": "https://example.com/demo.mp4",
  "cols": 4,
  "rows": 3,
  "tile_width": 320,
  "image_format": "jpg"
}
```

Or process a file already stored in your Apify Key-Value Store (`recipe/transcribe-prep`):

```json
{
  "operation": "recipe/transcribe-prep",
  "input_kvs_key": "interview.mp4",
  "target_lufs": -16
}
```

#### 2. Synchronous REST API (`run-sync-get-dataset-items`)

Call Sawfish in a single HTTP request and get the Dataset JSON directly:

```bash
curl -sS -X POST \
  "https://api.apify.com/v2/acts/zyonelvis~sawfish/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "operation": "recipe/vision-prep",
    "video_url": "https://example.com/demo.mp4",
    "cols": 4,
    "rows": 3,
    "image_format": "jpg"
  }'
```

#### 3. AI Agents via Apify MCP Server (`mcp.apify.com`)

Connect any Model Context Protocol (MCP) client to Apify's hosted MCP endpoint with Sawfish loaded as a tool:

```json
{
  "mcpServers": {
    "apify": {
      "type": "http",
      "url": "https://mcp.apify.com/?tools=zyonelvis/sawfish"
    }
  }
}
```

The Apify MCP Server reads `.actor/actor.json` and `.actor/input_schema.json` automatically, exposing all 9 operations with parameter types, bounds, enums, and descriptions so an agent can chain:

1. `probe` to inspect duration, resolution, and audio tracks;
2. `recipe/vision-prep` to inspect a timestamped contact sheet instead of uploading raw video;
3. `recipe/transcribe-prep` to produce clean 16 kHz mono WAV audio for speech-to-text;
4. `trim` or `recipe/shorts-prep` to cut exact segments using the timestamps returned by `vision-prep`.

***

### Sample Dataset Output (`recipe/vision-prep`)

```json
{
  "operation": "recipe/vision-prep",
  "status": "done",
  "elapsed_ms": 185,
  "input_source": "https://example.com/demo.mp4",
  "output_url": "https://api.apify.com/v2/key-value-stores/<STORE_ID>/records/contact_sheet.jpg",
  "output_kvs_key": "contact_sheet.jpg",
  "filename": "contact_sheet.jpg",
  "content_type": "image/jpeg",
  "size_bytes": 48210,
  "metadata": {
    "format_name": "mp4",
    "duration_sec": 20.0,
    "size_bytes": 1248000,
    "bitrate_kbps": 499,
    "has_video": true,
    "has_audio": true,
    "video": { "codec": "h264", "width": 1280, "height": 720, "fps": 24.0 },
    "audio": { "codec": "aac", "sample_rate_hz": 44100, "channels": 2 }
  },
  "details": {
    "grid": { "cols": 4, "rows": 3, "tile_width": 320 },
    "frame_timestamps_sec": [0.0, 1.667, 3.333, 5.0, 6.667, 8.333, 10.0, 11.667, 13.333, 15.0, 16.667, 18.333],
    "vision_hint": "Contact sheet 4x3 with exact source PTS timestamps printed on each tile."
  },
  "charged_events": [
    { "event_name": "actor-start", "count": 1 },
    { "event_name": "recipe-vision-prep", "count": 1 }
  ],
  "charge_limit_reached": false,
  "estimated_price_usd": 0.0095
}
```

***

### Pay-Per-Event (PPE) Pricing

Sawfish charges a minimal `actor-start` event plus the operation event **only when processing succeeds**. Before downloading media or running FFmpeg, Sawfish checks your maximum spending limit (`maxTotalChargeUsd`) and stops early without processing if the operation event would exceed your budget.

| Event Name | When Charged | Unit Price (USD) |
|---|---|---:|
| `actor-start` | Once per run (container initialization) | `$0.0005` |
| `probe` | Successful `probe` | `$0.0015` |
| `extract-audio` | Successful `extract-audio` (first 60 s included) | `$0.0060` |
| `contact-sheet` | Successful `contact-sheet` | `$0.0070` |
| `trim` | Successful `trim` (first 60 s included) | `$0.0070` |
| `normalize-audio` | Successful `normalize-audio` (first 60 s included) | `$0.0100` |
| `burn-subtitles` | Successful `burn-subtitles` (up to 720p, 60 s) | `$0.0180` |
| `recipe-vision-prep` | Successful `recipe/vision-prep` | `$0.0090` |
| `recipe-transcribe-prep` | Successful `recipe/transcribe-prep` (first 60 s included) | `$0.0110` |
| `recipe-shorts-prep` | Successful `recipe/shorts-prep` (first 60 s included) | `$0.0160` |
| `extra-minute` | Each started minute beyond 60 s on `extract-audio`, `trim`, `normalize-audio`, `recipe/transcribe-prep`, and `recipe/shorts-prep` | `$0.0040` |

***

### Limits & Security

- **Input size limits:** max **100 MB** video · max **25 MB** audio
- **Media limits:** max **10 minutes (`600 s`)** duration · max **1080p** height
- **Operation-specific limits:** `burn-subtitles` max **720p** and **60 s** · `recipe/shorts-prep` max **180 s**
- **Execution timeout:** **90 seconds** per FFmpeg command (`-threads 2`)
- **Security hardening:** HTTPS-only external downloads with SSRF, IPv4-mapped IPv6, and DNS-rebinding IP-pinning protection; binary magic-byte verification; `-protocol_whitelist file,pipe`; no shell execution (`shell=False`)

***

### FAQ

**Which inputs are supported?** A public `https://` URL to a video or audio file, or a file you stored in an Apify Key-Value Store (`input_kvs_key`). Private or local network URLs are blocked.

**Where are my output files?** In the run's default Key-Value Store. The Dataset item includes `output_url`, a direct download link.

**Can an AI agent use it?** Yes. Add Sawfish to the Apify MCP Server (`https://mcp.apify.com/?tools=zyonelvis/sawfish`) and the agent sees all 9 operations with their parameters.

**What if my file is too long or too big?** The run fails with a clear error and only the $0.0005 start fee is charged. Trim it first or send a shorter file.

**Missing an operation?** Open an issue on the Actor page and tell us which FFmpeg job you need next.

# Actor input Schema

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

Media task or AI recipe to run. Atomic tasks: `probe` (metadata only), `extract-audio` (MP3/WAV), `contact-sheet` (timestamped frame grid using exact source PTS), `trim` (cut segment), `normalize-audio` (2-pass EBU R128 loudness), `burn-subtitles` (hardcode SRT/ASS, max 720p & 60s). AI recipes: `recipe/vision-prep` (probe + exact-PTS contact sheet + JSON manifest for vision LLMs), `recipe/transcribe-prep` (16 kHz mono -16 LUFS WAV ready for Whisper/STT), `recipe/shorts-prep` (trim + 9:16 vertical crop + -14 LUFS loudness).

## `video_url` (type: `string`):

Public HTTPS URL of the video or audio file to process (max 100 MB video / 25 MB audio; max 10 min / 1080p). Private/internal IPs and non-HTTPS URLs are blocked for security. Leave empty if using `input_kvs_key`.

## `input_kvs_key` (type: `string`):

Key name of the media file stored in an Apify Key-Value Store (for example `sample.mp4` or `audio.wav`). Use this instead of `video_url` when passing uploaded or upstream Actor files.

## `input_kvs_id` (type: `string`):

Optional Key-Value Store ID or name where `input_kvs_key` is stored. If omitted, reads from this run's default Key-Value Store.

## `output_kvs_key` (type: `string`):

Optional filename/key for saving the generated output file in the default Key-Value Store (for example `clip.mp4` or `grid.jpg`). Auto-generated if omitted.

## `cols` (type: `integer`):

Number of columns in the contact sheet grid (1 to 6). Used by `contact-sheet` and `recipe/vision-prep`.

## `rows` (type: `integer`):

Number of rows in the contact sheet grid (1 to 6). Total frames extracted = cols \* rows. Used by `contact-sheet` and `recipe/vision-prep`.

## `tile_width` (type: `integer`):

Width in pixels of each frame tile in the contact sheet (120 to 640). Used by `contact-sheet` and `recipe/vision-prep`.

## `image_format` (type: `string`):

Output image format for the contact sheet (`jpg` or `webp`). Used by `contact-sheet` and `recipe/vision-prep`.

## `timestamps` (type: `boolean`):

Draw each frame's exact source PTS timestamp on the tile image. Always enabled in `recipe/vision-prep`.

## `audio_format` (type: `string`):

Output audio format (`mp3` or `wav`) for `extract-audio`.

## `sample_rate` (type: `integer`):

Output sample rate in Hz for `extract-audio`. Allowed values: `16000`, `44100` or `48000`. Use `16000` for speech-to-text.

## `mono` (type: `boolean`):

Convert audio to single-channel mono when running `extract-audio`.

## `target_lufs` (type: `number`):

Target integrated loudness in LUFS (-24 to -9). Recommended: `-14` for YouTube/Shorts/TikTok, `-16` for podcasts/STT transcription.

## `true_peak` (type: `number`):

Maximum true peak in dBTP (-6 to -0.5) for 2-pass EBU R128 normalization in `normalize-audio`.

## `normalize_output_format` (type: `string`):

Container/format for `normalize-audio` (`keep`, `mp3`, `wav`, or `mp4`).

## `start_sec` (type: `number`):

Start timestamp in seconds (>= 0) for `trim` or `recipe/shorts-prep`.

## `end_sec` (type: `number`):

End timestamp in seconds (> start_sec). Required for `trim`; optional for `recipe/shorts-prep` (defaults to full clip up to 180s).

## `trim_mode` (type: `string`):

`fast` uses stream copy (keyframe-aligned, milliseconds); `accurate` re-encodes for frame-exact cuts.

## `trim_output_format` (type: `string`):

Output format (`mp4` or `mp3`) for `trim`.

## `shorts_resolution` (type: `string`):

Target 9:16 vertical resolution for `recipe/shorts-prep`: `720p` (720x1280) or `1080p` (1080x1920).

## `subtitles_text` (type: `string`):

Full SRT or ASS subtitle text to burn into the video. Required for `burn-subtitles` (MVP limit: max 720p resolution and 60s duration).

## `subtitle_format` (type: `string`):

Format of `subtitles_text` (`srt` or `ass`).

## `font_size` (type: `integer`):

Subtitle font size (12 to 48) for `burn-subtitles`.

## `font_color` (type: `string`):

Subtitle text color in `#RRGGBB` format (default `#FFFFFF`).

## `outline_color` (type: `string`):

Subtitle outline color in `#RRGGBB` format (default `#000000`).

## `position` (type: `string`):

Vertical subtitle placement (`bottom`, `center`, or `top`).

## Actor input object example

```json
{
  "operation": "recipe/vision-prep",
  "cols": 4,
  "rows": 3,
  "tile_width": 320,
  "image_format": "jpg",
  "timestamps": true,
  "audio_format": "mp3",
  "sample_rate": 44100,
  "mono": false,
  "target_lufs": -14,
  "true_peak": -1.5,
  "normalize_output_format": "keep",
  "start_sec": 0,
  "trim_mode": "accurate",
  "trim_output_format": "mp4",
  "shorts_resolution": "720p",
  "subtitle_format": "srt",
  "font_size": 22,
  "font_color": "#FFFFFF",
  "outline_color": "#000000",
  "position": "bottom"
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `files` (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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("zyonelvis/sawfish").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("zyonelvis/sawfish").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 '{}' |
apify call zyonelvis/sawfish --silent --output-dataset

```

## MCP server setup

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

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/whUhmaW7cfKh4acca/builds/iLvUVn5NLZRsOsOz5/openapi.json
