FFmpeg operations as LLM-callable tools — clip, merge, extract audio, add subtitles, transcode.
Project description
ff-kit
FFmpeg operations as LLM-callable tools.
Stop hand-writing FFmpeg subprocess calls and JSON tool schemas.
ff-kitgives you 5 production-ready media operations, dual-format LLM schemas (OpenAI + Anthropic), and an MCP server — all in onepip install.
Real-World Use Cases
"My agent pipeline needs to process uploaded videos" — Give your agent openai_tools() or anthropic_tools() and let it decide how to clip, transcode, or extract audio. The dispatch() function handles execution.
"I need to batch-extract 16kHz WAV for ASR" — One line: extract_audio("video.mp4", "out.wav", codec="pcm_s16le", sample_rate=16000, channels=1)
"I want FFmpeg tools in Claude Desktop / Cursor" — Add the MCP server config (3 lines of JSON) and Claude can edit your videos directly.
"I'm tired of writing the same FFmpeg commands" — Use the CLI: ffkit clip input.mp4 output.mp4 --start 00:01:00 --duration 30
60-Second Quick Start
# Install (requires FFmpeg on PATH)
pip install ff-toolkit
# Verify it works — no API keys needed
ffkit probe some_video.mp4
# Or run the full demo with a generated test video
python -m ff_kit.examples.local
Python API
from ff_kit import clip, extract_audio, merge, transcode
# Trim seconds 60-90
clip("raw.mp4", "highlight.mp4", start="00:01:00", duration="30")
# Extract 16kHz mono audio for Whisper/Paraformer
extract_audio("raw.mp4", "speech.wav", codec="pcm_s16le", sample_rate=16000, channels=1)
# Concatenate intro + main + outro
merge(["intro.mp4", "main.mp4", "outro.mp4"], "final.mp4")
# Compress to 720p WebM for web delivery
transcode("raw.mp4", "web.webm", video_codec="libvpx-vp9", resolution="1280x720", crf=30)
CLI
ffkit clip raw.mp4 highlight.mp4 --start 00:01:00 --duration 30
ffkit extract-audio raw.mp4 speech.wav --codec pcm_s16le --sample-rate 16000 --channels 1
ffkit merge intro.mp4 main.mp4 outro.mp4 -o final.mp4
ffkit transcode raw.mp4 web.webm --video-codec libvpx-vp9 --resolution 1280x720 --crf 30
ffkit probe video.mp4
With OpenAI (3 lines to integrate)
from ff_kit.schemas.openai import openai_tools
from ff_kit.dispatch import dispatch
# 1. Pass tools to the model
response = client.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=openai_tools(), # ← that's it
)
# 2. Execute whatever the model calls
tc = response.choices[0].message.tool_calls[0]
result = dispatch(tc.function.name, json.loads(tc.function.arguments))
With Anthropic (3 lines to integrate)
from ff_kit.schemas.anthropic import anthropic_tools
from ff_kit.dispatch import dispatch
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=anthropic_tools(), # ← that's it
messages=messages,
)
for block in response.content:
if block.type == "tool_use":
result = dispatch(block.name, block.input)
As an MCP Server (Claude Desktop / Cursor)
Add to your config (claude_desktop_config.json or Cursor settings):
{
"mcpServers": {
"ff-kit": {
"command": "ffkit-mcp",
"args": []
}
}
}
That's it. Claude can now clip, merge, extract audio, add subtitles, and transcode your files.
Operations
| Tool | What it does | Example |
|---|---|---|
ffkit_clip |
Trim a segment by start + end/duration | Cut highlight reel from raw footage |
ffkit_merge |
Concatenate multiple files | Join intro + content + outro |
ffkit_extract_audio |
Extract audio, optionally re-encode | Get 16kHz WAV for speech recognition |
ffkit_add_subtitles |
Burn or embed subtitles (.srt/.ass/.vtt) | Hard-sub a translated SRT into video |
ffkit_transcode |
Convert format, codec, resolution, bitrate | Compress 4K MP4 to 720p WebM for web |
How It Works
Your Agent ff-kit FFmpeg
│ │ │
├─ openai_tools() ──────────┤ │
│ or anthropic_tools() │ │
│ │ │
├─ LLM returns tool call ──►│ │
│ │ │
├─ dispatch(name, args) ───►├─ validates & builds cmd ────►│
│ │ │
│◄── FFmpegResult ─────────┤◄── subprocess result ────────┤
│ │ │
Project Structure
ff-kit/
├── src/ff_kit/
│ ├── __init__.py # Public API: clip, merge, extract_audio, ...
│ ├── cli.py # CLI entry point (ffkit command)
│ ├── executor.py # FFmpeg subprocess runner + probe
│ ├── dispatch.py # Tool name → function router
│ ├── core/ # One module per operation
│ │ ├── clip.py
│ │ ├── merge.py
│ │ ├── extract_audio.py
│ │ ├── add_subtitles.py
│ │ └── transcode.py
│ ├── schemas/ # LLM tool definitions
│ │ ├── openai.py # OpenAI function-calling format
│ │ └── anthropic.py # Anthropic tool-use format
│ └── mcp/ # MCP server (stdio JSON-RPC)
│ └── server.py
├── examples/
│ ├── local_example.py # ← Run this first! No API key needed
│ ├── openai_example.py
│ ├── anthropic_example.py
│ └── agent_loop_example.py
└── tests/ # 30 tests, all mocked (no FFmpeg needed)
Development
git clone https://github.com/inthepond/ff-kit.git
cd ff-kit
pip install -e ".[dev]"
pytest -v # 30 tests, runs in <1s
FAQ
Q: Do I need FFmpeg installed?
Yes, for actual media operations. Tests are fully mocked and don't need FFmpeg. Install it from ffmpeg.org/download or brew install ffmpeg / apt install ffmpeg.
Q: Can I add custom operations?
Yes — add a function in core/, register it in dispatch.py's _REGISTRY, and add schema entries in schemas/openai.py and schemas/anthropic.py. See any existing operation as a template.
Q: Why not just use LangChain / CrewAI tools? Those frameworks are great, but they're heavy dependencies. ff-kit is zero-dependency (beyond Python stdlib) and works with any LLM provider. You can use it inside LangChain if you want, or standalone.
Q: What about streaming / progress callbacks? Not in v0.1. FFmpeg progress parsing is planned for v0.2.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ff_toolkit-0.1.0.tar.gz.
File metadata
- Download URL: ff_toolkit-0.1.0.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
406117acae7bbd40182df6b378cb6ff8f473f6f81e2eba3fe52e8d04baa89b57
|
|
| MD5 |
5590b72d2a2e0e62e2292175087694ff
|
|
| BLAKE2b-256 |
7633be21f0c6f6266c2126c3ba1123adacc190a59973fa29c6018206bd022e72
|
Provenance
The following attestation bundles were made for ff_toolkit-0.1.0.tar.gz:
Publisher:
publish.yml on inthepond/ff-kit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ff_toolkit-0.1.0.tar.gz -
Subject digest:
406117acae7bbd40182df6b378cb6ff8f473f6f81e2eba3fe52e8d04baa89b57 - Sigstore transparency entry: 1260645037
- Sigstore integration time:
-
Permalink:
inthepond/ff-kit@dc2d48962d3be248d56c85f2174fec7b341dd8f0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/inthepond
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dc2d48962d3be248d56c85f2174fec7b341dd8f0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ff_toolkit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ff_toolkit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69e130fc5b7b998b665f3e793e0cbed3a5025ed0f312eb066bbbc118e5c7f164
|
|
| MD5 |
d2781e5f7d441799f83b06358b4ec4fb
|
|
| BLAKE2b-256 |
76ed84a413619bb79a6d7ff00fc6fe2d3707cf6594ab77181a1f9709cbff3828
|
Provenance
The following attestation bundles were made for ff_toolkit-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on inthepond/ff-kit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ff_toolkit-0.1.0-py3-none-any.whl -
Subject digest:
69e130fc5b7b998b665f3e793e0cbed3a5025ed0f312eb066bbbc118e5c7f164 - Sigstore transparency entry: 1260645066
- Sigstore integration time:
-
Permalink:
inthepond/ff-kit@dc2d48962d3be248d56c85f2174fec7b341dd8f0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/inthepond
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@dc2d48962d3be248d56c85f2174fec7b341dd8f0 -
Trigger Event:
release
-
Statement type: