---
name: ffmpeg
label: FFmpeg
description: Run ffmpeg and ffprobe commands for audio/video processing. Converts formats, extracts audio/video streams, trims, merges, adjusts volume, changes resolution, extracts frames, and more. Auto-installs ffmpeg if not available. Use when the user needs any audio or video manipulation.
version: 1
language: typescript
inputs:
  command:
    type: enum
    values: ffmpeg,ffprobe
    description: "ffmpeg: process audio/video. ffprobe: inspect file metadata (duration, codecs, streams, etc.)"
  args:
    type: string
    description: "Command-line arguments as a single string. Do NOT include the ffmpeg/ffprobe binary name — only the arguments. Example: '-i input.mp4 -vn -codec:a libmp3lame -b:a 320k output.mp3'"
---

# FFmpeg

General-purpose audio/video processing via ffmpeg and ffprobe.

## Prerequisites

This tool requires `ffmpeg` and `ffprobe`. It will automatically install them if not available:

```bash
sudo apt-get update && sudo apt-get install -y ffmpeg
```

All sudo commands run without a password prompt in this environment.

## Usage

### ffprobe — Inspect files

Get duration, codecs, streams, bitrate, and other metadata:

```
command: ffprobe
args: -v quiet -print_format json -show_format -show_streams input.mp4
```

### ffmpeg — Process files

Always include `-y` to overwrite output files without prompting.

**Convert video to MP4:**
```
command: ffmpeg
args: -i input.avi -codec:v libx264 -codec:a aac output.mp4 -y
```

**Extract audio from video:**
```
command: ffmpeg
args: -i video.mp4 -vn -codec:a libmp3lame -b:a 320k audio.mp3 -y
```

**Trim a clip:**
```
command: ffmpeg
args: -i input.mp4 -ss 00:01:30 -to 00:03:00 -codec copy clip.mp4 -y
```

**Change resolution:**
```
command: ffmpeg
args: -i input.mp4 -vf scale=1280:720 -codec:a copy output.mp4 -y
```

**Extract a frame as image:**
```
command: ffmpeg
args: -i video.mp4 -ss 00:00:10 -frames:v 1 frame.png -y
```

**Merge audio and video:**
```
command: ffmpeg
args: -i video.mp4 -i audio.mp3 -codec:v copy -codec:a aac -shortest merged.mp4 -y
```

**Convert audio format:**
```
command: ffmpeg
args: -i input.flac -codec:a libmp3lame -b:a 320k output.mp3 -y
```

## Notes

- Use absolute paths for input and output files.
- Always add `-y` to ffmpeg args to avoid interactive prompts.
- For long operations, progress is streamed in real time.
- stderr output from ffmpeg is captured and returned on failure.
- The tool has a 10-minute timeout.
