# How to Add the Media Editing Skill to Your AI Agent

Category: Video

Use when cropping, resizing to another aspect ratio, trimming, extracting audio, joining clips, putting an audio track on a video, making a GIF or a rapid-cut montage (load it before the edit), and whenever another Skill says to run one of these edits. FFmpeg recipes for editing existing media with the FFmpeg tool — crop an image or video (crop-window and aspect-ratio math, pad, or outpaint when a ratio change would cut content), trim a clip, extract a video's audio, merge (concatenate) video clips with cuts, fades or dissolves, merge audio with video (replace, mute and narrate, add music at a set volume, or mix dialogue with ducked music), turn a video into a looping GIF, and cut fast montages (chaotic random-segment stitches, flash montages interleaving several clips). Gives the exact command to send for each edit.

Raw file: https://spiral.ai/skills/media-editing/SKILL.md

## Tools Media Editing uses

- [FFmpeg Media Editor](https://spiral.ai/tools/spiral/ffmpeg)

## How to add Media Editing to your agent

Pick the way that suits you. Each takes about two minutes.

### Save SKILL.md into your agent's skills

1. **Download the skill**: Claude Code, and other agents that read Agent Skills, load it from this folder when they start.

```bash
mkdir -p ~/.claude/skills/media-editing
curl -fsSL https://spiral.ai/skills/media-editing/SKILL.md -o ~/.claude/skills/media-editing/SKILL.md
curl -fsSL https://spiral.ai/skills/media-editing/montage.md -o ~/.claude/skills/media-editing/montage.md
```

2. **Connect Spiral**: The skill runs its tools through Spiral. Send your agent this message once to set it up.

```
set up https://spiral.ai/SKILL.md
```

### Use the Spiral CLI

1. **Install and sign in**: Installs the Spiral CLI, signs you in and adds its skill to your coding agents.

```bash
npx -y spiral-cli@latest init
```

2. **Read the skill**: Built-in skills are on for every organization: the CLI prints this one with all its files.

```bash
spiral agent-skills get media-editing --json
```

### Read it from the Spiral API

1. **Create an API key**: In the console, under API keys.

2. **Fetch the skill**: The answer holds SKILL.md and every other file of the skill, in path order.

```bash
curl https://api.spiral.ai/v1/skills/media-editing \
  -H "Authorization: Bearer $SPIRAL_API_KEY"
```

Then ask your agent for the task: it loads Media Editing when a request matches the skill's description.

## Instructions (SKILL.md)

# Media Editing

Edits of existing media (crop, trim, extract audio, merge clips, merge audio with video) run as one FFmpeg command on `spiral/ffmpeg`. Read its input schema, estimate the cost, then run it. Never drop part of the request to fit a tool that cannot do it.

## How the command is written

- Write it as on a command line: `ffmpeg -i <input> … <output name>`. The leading `ffmpeg` is optional.
- Inputs: put each https media URL after `-i`, or list the files in `inputs` and name them `{in0}`, `{in1}`, … in the command. Use the exact URLs you were given; never shorten or rebuild one.
- Input options (`-ss`, `-t`, `-loop 1`, `-stream_loop`, `-framerate`) go before their `-i`.
- End with the output file's name. Its extension picks the format: `mp4`, `mov`, `webm`, `gif`, `mp3`, `wav`, `m4a`, `aac`, `flac`, `ogg`, `png`, `jpg`, `webp`. One output file per run.
- Quote filter graphs as in a shell. Arguments that read other files or URLs (`-f`, `movie=`, `textfile=`) are refused; give every input with `-i` instead.
- `max_seconds` caps how long FFmpeg may run (the hold); the charge is the seconds it ran. Raise it from the default only for long re-encodes.
- The run returns one output file URL. Use that URL in the next step; never guess one.

The recipes below use `{in0}`, `{in1}` for the inputs; replace them with https URLs after `-i` when you do not list `inputs`.

## Crop

A crop only cuts pixels away; to extend the frame instead, see "Crop, pad or outpaint" below. A crop always needs a window: a crop with no window returns the image unchanged.

The window is `crop=W:H:X:Y` in pixels of the input, or as expressions of the input size: `iw` and `ih` are its width and height. Without `X:Y`, FFmpeg centers the window.

- An exact pixel crop: `crop=10:10:0:0` (width, height, then the top-left corner). For "crop to 10 by 10 pixels" crop to those pixels; do not convert them to tiny percentages.
- A percentage window (`x_percent`, `y_percent` = its top-left corner, `width_percent`, `height_percent` = its size, not its right or bottom edge, all in % of the image): `crop=iw*<width_percent/100>:ih*<height_percent/100>:iw*<x_percent/100>:ih*<y_percent/100>`.

### Cropping to an aspect ratio

The largest centered crop of a target ratio `T` (width ÷ height) needs no pixel sizes: `crop='min(iw,ih*T)':'min(ih,iw/T)'`, for example 16:9:

```
ffmpeg -i {in0} -vf "crop='min(iw,ih*16/9)':'min(ih,iw*9/16)'" crop.png
```

For a video output, round each side down to an even number, which H.264 needs: `crop='trunc(min(iw,ih*9/16)/2)*2':'trunc(min(ih,iw*16/9)/2)*2'`.

When you need the window as percentages (to tell the user what is cut, or for a crop tool that takes percentages), let `S` be the source ratio and `T` the target ratio, both width ÷ height. `S` is known when you chose the image's size; for any other image read its width and height first (from the tool result that made it, or by probing the file).

- `T ≥ S` (the target is wider): keep the full width and trim the height: `width_percent = 100`, `height_percent = (S / T) × 100`, `x_percent = 0`, `y_percent = (100 − height_percent) ÷ 2`.
- `T < S` (the target is taller): keep the full height and trim the width: `height_percent = 100`, `width_percent = (T / S) × 100`, `y_percent = 0`, `x_percent = (100 − width_percent) ÷ 2`.

Clamp every percentage to 0–100. Square → 16:9 (`S = 1`, `T ≈ 1.778`): `height_percent = 56.25`, `y_percent = 21.875`. 16:9 → 9:16 (`S ≈ 1.778`, `T = 0.5625`): `width_percent ≈ 31.6`, `x_percent ≈ 34.2`:

```
ffmpeg -i {in0} -vf "crop=iw*0.316:ih*1:iw*0.342:ih*0" crop.png
```

The target ratio is the user's explicit ratio, or the destination platform's. The crop is centered and blind to content: when the subject is off-center, a centered crop may clip it, so say so rather than assume.

### Crop, pad or outpaint: flag content loss first

| Route    | What happens                                                      | Tool                                                                                               |
| -------- | ----------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| Crop     | Cuts the edges away; content outside the window is lost.          | `spiral/ffmpeg`, as above                                                                          |
| Pad      | Extends the canvas with a solid border; every pixel is kept.      | `spiral/ffmpeg`, `pad` below                                                                       |
| Outpaint | Extends the canvas and fills the new area with generated scenery. | The image-edit model from `model-recommendations`, with the original attached and the target ratio |

When the target ratio cuts content and the user has not said losing the edges is fine, do not crop straight away: say what a crop would remove and ask the user to choose one of the three routes. Naming the crop tool for a "resize" is not consent to lose content. Crop directly only when the user asked to cut something away, chose crop, or the crop removes nothing. The same applies to resizing to exact pixel dimensions of another ratio (for example a square size for a portrait photo).

Pad to ratio `T`, centered, on the smallest canvas of that ratio that holds the source:

```
ffmpeg -i {in0} -vf "pad='max(iw,ih*16/9)':'max(ih,iw*9/16)':(ow-iw)/2:(oh-ih)/2:color=white" padded.png
```

For a transparent border on PNG output, use `format=rgba,pad=…:color=black@0`.

### Other crop notes

- A video crop is the same filter with a video output: `ffmpeg -i {in0} -vf "crop=ih*9/16:ih" -c:a copy vertical.mp4` (center 9:16 from a landscape clip, audio kept).
- Keep the output format of the source unless the user asked for another (`png` for a PNG, `jpg` for a JPEG).

## Trim

```
ffmpeg -ss 5 -i {in0} -t 10 -c copy clip.mp4
```

`-ss` is the start and `-t` the length, in seconds. `-c copy` cuts at keyframes; when the cut must be frame-exact, re-encode instead: `-c:v libx264 -preset veryfast -crf 20 -c:a aac`.

## Extract audio

```
ffmpeg -i {in0} -vn -c:a libmp3lame -q:a 2 audio.mp3
```

Use `audio.wav` (`-c:a pcm_s16le`) when the next tool needs uncompressed audio. When the source has no audio track the command fails: say so and ask for another source.

## Merge video clips

Clips must share size, frame rate and audio layout before they join. Normalize each input, then concatenate. For two clips, landscape 1920x1080 at 30 fps:

```
ffmpeg -i {in0} -i {in1} -filter_complex "[0:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30[v0];[1:v]scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1,fps=30[v1];[0:a]aresample=44100[a0];[1:a]aresample=44100[a1];[v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -preset veryfast -crf 20 -c:a aac merged.mp4
```

- More clips: one `scale…[vN]` and `aresample…[aN]` chain per input, then `concat=n=<count>`. As many inputs per run as its schema allows (`inputs` maxItems); merge longer lists in batches, then merge the batches.
- Use the size of the planned output (1080x1920 for vertical). Padding keeps a mismatched clip whole, with bars; say so to the user rather than letting a clip look wrong.
- A clip with no audio track breaks `concat` with `a=1`. Give it silence inside the graph (`anullsrc=r=44100:cl=stereo,atrim=0:<clip seconds>[aN]` in place of its `aresample` chain), or join video only (`a=0`, no `[aN]` labels) and add the soundtrack after.
- **Fade or dissolve between clips:** join two normalized clips with `xfade` and their audio with `acrossfade`; the offset is the first clip's length minus the transition:

```
ffmpeg -i {in0} -i {in1} -filter_complex "[0:v][1:v]xfade=transition=fade:duration=1:offset=4[v];[0:a][1:a]acrossfade=d=1[a]" -map "[v]" -map "[a]" -c:v libx264 -preset veryfast -crf 20 -c:a aac merged.mp4
```

Use `transition=dissolve` for a dissolve. Chain one `xfade` per join for more clips, adding each clip's length minus the transitions so far to the next offset.

**A cut after speech** goes after the line ends: read its end from word timings of the voice track, then start the next shot, including any dissolve, about 0.3–0.5 s later. A transition that starts before the measured end shows the next scene while the line is still playing.

## Merge audio with video

**Replace the audio** (also "mute the source and add narration"); stops at the shorter input:

```
ffmpeg -i {in0} -i {in1} -map 0:v:0 -map 1:a:0 -c:v copy -c:a aac -b:a 128k -shortest -movflags +faststart out.mp4
```

**Add music at a set volume** (`volume=` from 0.0 to 2.0):

```
ffmpeg -i {in0} -i {in1} -map 0:v:0 -map 1:a:0 -filter:a "volume=0.3" -c:v copy -c:a aac -b:a 128k -shortest -movflags +faststart out.mp4
```

**Keep the dialogue and mix music under it:**

```
ffmpeg -i {in0} -i {in1} -filter_complex "[1:a]volume=0.2[bg];[0:a][bg]amix=inputs=2:duration=first[aout]" -map 0:v:0 -map "[aout]" -c:v copy -c:a aac -b:a 128k -movflags +faststart out.mp4
```

When `-c:v copy` fails (an unusual codec or container), re-encode the video: `-c:v libx264 -preset veryfast -crf 23 -pix_fmt yuv420p`.

## Video to GIF

GIFs hold 256 colors per frame, so always build a palette from the clip and apply it with dithering (`palettegen` + `paletteuse`); a direct conversion looks washed out and banded. Default to 480 px wide at 15 fps, looping forever:

```
ffmpeg -i {in0} -vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=256:stats_mode=diff[p];[s1][p]paletteuse=dither=bayer:bayer_scale=5" out.gif
```

- A GIF loops forever by default; `spiral/ffmpeg` refuses `-loop` as an output option, so leave it out (an input `-loop 1` before `-i` still loops a still image).
- Size: 480 px at 15 fps for social or messaging; 720 px at 24 fps for high quality; 320 px at 10 fps for a small, fast file; omit `scale` to keep the source size (the file can be very large). Ask only when the user gave no width, frame rate, trim or loop preference that matters.
- Trim first: `-ss <start> -t <seconds>` before `-i`. GIFs grow fast: for a clip longer than about 5 seconds, keep the best 2–5 seconds or lower the width (480 → 320) or frame rate (15 → 10).
- Pixel art: `fps=10,scale=256:256:flags=neighbor` (never `lanczos`, which blurs hard edges), and keep transparency with `palettegen=…:reserve_transparent=on` and `paletteuse=dither=bayer:alpha_threshold=128`.
- `stats_mode`: `diff` (default) favors the moving areas; `full` suits static or slow content; `single` builds the palette from one frame. Dither: `bayer:bayer_scale=5` (default, 0–5), `floyd_steinberg` for photographs, `sierra2` for gradients and skies, `none` for flat color.
- A GIF has no audio: the track is dropped. The source must be a video; animate a still image with a video model first.
- After delivery, offer tweaks: wider, narrower, faster, slower, trimmed.

## Montages and rapid-cut edits

Chaotic stitches (short random-feeling segments from several clips) and flash montages (every clip sliced into equal time chunks and interleaved round-robin): read `montage.md` in this Skill's folder.

## When to use something else

- Captions, titles, motion graphics or a timed multi-scene edit: render a composition (the **hyperframes-video** Skill).
- An edit that needs a model (outpainting, object removal, restyling): the image- or video-edit models in **model-recommendations**.

## Other files

- [montage.md](https://spiral.ai/skills/media-editing/montage.md)

## More skills

- [Character Films](https://spiral.ai/skills/character-films)
- [Frame Chaining](https://spiral.ai/skills/frame-chaining)
- [Gemini Omni Video](https://spiral.ai/skills/gemini-omni-video)
- [HyperFrames Animation](https://spiral.ai/skills/hyperframes-animation)

## Questions about Media Editing

### Media Editing

**What does the Media Editing skill do?**

Use when cropping, resizing to another aspect ratio, trimming, extracting audio, joining clips, putting an audio track on a video, making a GIF or a rapid-cut montage (load it before the edit), and whenever another Skill says to run one of these edits. FFmpeg recipes for editing existing media with the FFmpeg tool — crop an image or video (crop-window and aspect-ratio math, pad, or outpaint when a ratio change would cut content), trim a clip, extract a video's audio, merge (concatenate) video clips with cuts, fades or dissolves, merge audio with video (replace, mute and narrate, add music at a set volume, or mix dialogue with ducked music), turn a video into a looping GIF, and cut fast montages (chaotic random-segment stitches, flash montages interleaving several clips). Gives the exact command to send for each edit.

**Which tools does Media Editing use?**

It runs FFmpeg Media Editor through Spiral, each at the price on its tool page.

**Does the Media Editing skill cost anything?**

The skill is free. The tools it runs are billed pay-as-you-go from your Spiral balance at each tool's stated price, with no plan.

**How does my agent know when to use Media Editing?**

An agent reads each skill's description and loads its instructions when a request matches it.

**How do I add Media Editing to Claude Code?**

Save its files into ~/.claude/skills/media-editing/ with the commands on this page; Claude Code loads it when it starts.

**Can I use Media Editing in other agents?**

Yes. Any agent that reads Agent Skills folders loads the same files, and any other agent reads the skill with `spiral agent-skills get media-editing --json` or the Spiral API.

**Is Media Editing on for my Spiral organization?**

Yes. Built-in skills are on for every organization; an admin can turn Media Editing off on the console's Skills page.

**Where is the Media Editing SKILL.md file?**

At https://spiral.ai/skills/media-editing/SKILL.md, with no key needed. On the console's Skills page, Customize saves a copy you can edit as your organization's own skill.

