# Ffmpeg Post Production

> Verified FFmpeg recipes for post-production: trimming, concatenation, reframing to vertical or square, fades and crossfades, two-pass loudness normalization (loudnorm), burning in or muxing captions (SRT/ASS), web and social encoding (H.264/AAC with faststart), and thumbnails. Use this skill when finishing a rendered or recorded video for delivery, or whenever an agent is about to write an ffmpeg command. Activate when: ffmpeg, trim video, cut clip, concat videos, join videos, loudnorm, normalize audio, LUFS, burn subtitles, hardcode captions, SRT, ASS, encode for web, faststart, H.264, crf, thumbnail, 9:16 crop, reframe video.

- Skill: `latestaiagents/ffmpeg-post-production` (Agent Skill)
- Install (CLI): `npx get-skill add latestaiagents/ffmpeg-post-production`
- Raw SKILL.md: https://api.skillmd.com/api/skills/latestaiagents/ffmpeg-post-production/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: latestaiagents (https://skillmd.com/u/latestaiagents)
- Updated: 2026-11-14
- Page: https://skillmd.com/skills/latestaiagents/ffmpeg-post-production

---


# FFmpeg Post-Production

**Finish and deliver video with commands that are checked against the FFmpeg docs, not remembered from a forum.**

## When to Use

- Trimming, joining, or reframing renders and screen recordings
- Normalizing audio loudness before publishing
- Adding captions (soft track or burned in)
- Producing web/social deliverables and thumbnails from a master

## When NOT to Use

- Creating motion graphics from scratch: use Remotion or HyperFrames (see `video-production-pipeline`)
- Generating captions from speech: see `captions-and-transcription` (this skill only applies them)

## Workflow

### Step 1: Inspect Before You Touch

```bash
ffprobe -v error -show_entries format=duration:stream=index,codec_type,codec_name,width,height,r_frame_rate,sample_rate \
  -of default=noprint_wrappers=1 input.mp4
```

Check the filters you plan to use exist in this build. Caption burn-in needs a build configured with `--enable-libass`; some packaged builds omit it.

```bash
ffmpeg -hide_banner -filters | grep -E ' (subtitles|ass|loudnorm|thumbnail|xfade) '
```

Always write to a **new** output file. Never overwrite the source; keep the master untouched.

### Step 2: Trim

```bash
# Frame-accurate: re-encode. -ss before -i seeks fast; with transcoding, accurate seek is the default.
ffmpeg -ss 00:00:02 -to 00:00:05 -i input.mp4 -c:v libx264 -crf 18 -preset medium -c:a aac clip.mp4

# Fast, no quality loss, but cuts land on keyframes (the clip may start early or run long).
ffmpeg -ss 2 -i input.mp4 -t 3 -c copy clip_copy.mp4
```

`-to` and `-t` are mutually exclusive; `-t` wins if both are given. Use stream copy only when keyframe-accurate cuts are acceptable.

### Step 3: Concatenate

Concat demuxer, for files with identical streams (same codecs, resolution, time base):

```bash
printf "file 'intro.mp4'\nfile 'main.mp4'\nfile 'outro.mp4'\n" > list.txt
ffmpeg -f concat -safe 0 -i list.txt -c copy joined.mp4
```

`-safe 0` allows absolute or unusual paths in the list; omit it when all paths are simple relative names. If the inputs differ (different encoders or sizes), re-encode them to a common format first, or use a crossfade (Step 5).

### Step 4: Reframe for Vertical or Square

```bash
# Fit (letterbox/pillarbox) 16:9 into 1080x1920 with padding
ffmpeg -i input.mp4 -vf "scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2,setsar=1" \
  -c:v libx264 -crf 20 -c:a copy vertical_fit.mp4

# Fill (centre crop) 16:9 into 1080x1920
ffmpeg -i input.mp4 -vf "scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,setsar=1" \
  -c:v libx264 -crf 20 -c:a copy vertical_fill.mp4
```

A centre crop removes most of a 16:9 frame. Prefer re-rendering a native 9:16 composition when the video has text or UI (see `motion-design-principles`).

### Step 5: Fades and Crossfades

```bash
# Fade in/out over 0.5 s on an 8 s clip (st = start time of the fade)
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=0.5,fade=t=out:st=7.5:d=0.5" \
  -af "afade=t=in:st=0:d=0.5,afade=t=out:st=7.5:d=0.5" -c:v libx264 -crf 20 -c:a aac faded.mp4

# Crossfade two clips (a.mp4 is 3 s long; offset = 3 - 0.5)
ffmpeg -i a.mp4 -i b.mp4 -filter_complex \
  "[0:v][1:v]xfade=transition=fade:duration=0.5:offset=2.5,format=yuv420p[v];[0:a][1:a]acrossfade=d=0.5[a]" \
  -map "[v]" -map "[a]" -c:v libx264 -crf 20 -c:a aac crossfaded.mp4
```

`xfade` needs inputs with the same resolution and frame rate.

### Step 6: Normalize Loudness (Two-Pass loudnorm)

`loudnorm` implements EBU R128-style normalization. The FFmpeg docs describe single-pass (for live) and double-pass (for files) modes; use two passes for files.

**Pick the target first.** EBU R 128 (broadcast) normalizes to **−23 LUFS** integrated with a maximum true peak of **−1 dBTP**. Online platforms and clients may publish their own delivery specs; use theirs when given. If there is no spec, choose one house target and apply it to every video. The commands below use `I=-16:TP=-1.5:LRA=11` as example values only.

Pass 1, measure:

```bash
ffmpeg -hide_banner -i input.mp4 -af loudnorm=I=-16:TP=-1.5:LRA=11:print_format=json -f null -
```

Copy `input_i`, `input_tp`, `input_lra`, `input_thresh`, and `target_offset` from the JSON at the end of the output.

Pass 2, apply with the measured values:

```bash
ffmpeg -i input.mp4 -af "loudnorm=I=-16:TP=-1.5:LRA=11:measured_I=-21.78:measured_TP=-16.08:measured_LRA=0.10:measured_thresh=-31.78:offset=0.01:linear=true:print_format=summary" \
  -ar 48000 -c:v copy -c:a aac -b:a 192k normalized.mp4
```

Notes from the docs: in dynamic mode the filter upsamples to 192 kHz to detect true peaks, so set the output rate with `-ar`. `linear=true` only stays linear if the measured values are supplied and the target is reachable; otherwise it falls back to dynamic.

Verify:

```bash
ffmpeg -hide_banner -nostats -i normalized.mp4 -af ebur128=peak=true -f null - 2>&1 | grep -A12 Summary
```

### Step 7: Captions (Soft or Burned In)

Soft captions (viewer can toggle; keeps text searchable):

```bash
ffmpeg -i video.mp4 -i captions.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng soft_captions.mp4
```

Burned-in captions (always visible; needed where a platform ignores caption tracks). Requires libass:

```bash
ffmpeg -i video.mp4 -vf "subtitles=captions.srt:force_style='FontName=Inter,FontSize=24,Outline=2'" \
  -c:v libx264 -crf 18 -c:a copy burned.mp4

# Styled ASS file (positions, colours, karaoke) authored elsewhere
ffmpeg -i video.mp4 -vf "ass=captions.ass" -c:v libx264 -crf 18 -c:a copy burned_ass.mp4
```

- `force_style` takes ASS style `KEY=VALUE` pairs separated by commas.
- `fontsdir=` points libass at bundled fonts so the render does not depend on system fonts.
- If you change the aspect ratio of an ASS-authored video, set `original_size` so fonts scale correctly.
- For Arabic, Hebrew, Devanagari, Thai, and other complex scripts, set `shaping=complex` (needs libass with HarfBuzz).
- Where possible, upload the SRT/VTT to the platform as well; burned-in text cannot be resized or translated by the viewer.

### Step 8: Encode Deliverables

Web/social H.264 master-to-deliverable recipe:

```bash
ffmpeg -i master.mov -c:v libx264 -preset slow -crf 20 -pix_fmt yuv420p \
  -c:a aac -b:a 160k -ar 48000 -movflags +faststart deliverable.mp4
```

| Flag | Why |
|------|-----|
| `-crf` | Constant quality. Range 0–51, lower is better; 23 is the default and ~18–28 is the commonly cited sane range. Tune by eye. |
| `-preset` | Speed vs compression: `ultrafast` … `medium` (default) … `veryslow`. Slower = smaller file at the same CRF. |
| `-pix_fmt yuv420p` | 4:2:0 chroma, required by many players; YouTube's recommended settings specify 4:2:0. |
| `-movflags +faststart` | Moves the moov atom to the front so playback can start before download completes. YouTube recommends "Fast Start". |
| `-ar 48000` | YouTube's recommended audio sample rate is 48 kHz. |

Keep the frame rate the same as the source (no `-r` unless you mean to convert).

Optional open format for the web:

```bash
ffmpeg -i master.mov -c:v libvpx-vp9 -crf 32 -b:v 0 -c:a libopus deliverable.webm
```

### Step 9: Thumbnails and Posters

```bash
# Let FFmpeg pick a representative frame from each batch (default batch n=100)
ffmpeg -i video.mp4 -vf "thumbnail,scale=1280:-2" -frames:v 1 thumb.png

# Exact frame at 3 s
ffmpeg -ss 3 -i video.mp4 -frames:v 1 -q:v 2 poster.jpg
```

Automatic picks are a starting point. A designed thumbnail (title text, clear subject) usually beats a random frame.

## Command Safety Checklist

- [ ] Output path differs from every input path
- [ ] `-y` only when you intend to overwrite a previous *output*
- [ ] Filters verified present in this build (`ffmpeg -filters`)
- [ ] Durations and stream counts checked with `ffprobe` after each step
- [ ] Final file watched in a browser before delivery

## Best Practices

1. Keep a lossless or high-quality master; encode every deliverable from it
2. Re-encode for frame-accurate cuts; stream-copy only when keyframe cuts are acceptable
3. Use two-pass `loudnorm` with an explicit, agreed target; verify with `ebur128`
4. Ship captions as a sidecar file even when you also burn them in
5. Always add `-pix_fmt yuv420p` and `-movflags +faststart` for web MP4s
6. Quote filter graphs; one wrong comma changes the graph
7. Check exit codes in scripts; FFmpeg can write a partial file on failure

## References

- FFmpeg main options (`-ss`, `-to`, `-t`): https://ffmpeg.org/ffmpeg.html
- FFmpeg filters (`loudnorm`, `subtitles`, `ass`, `thumbnail`, `xfade`, `ebur128`): https://ffmpeg.org/ffmpeg-filters.html
- FFmpeg formats (concat demuxer, mov/mp4 `faststart`): https://ffmpeg.org/ffmpeg-formats.html
- FFmpeg codecs (libx264 options): https://ffmpeg.org/ffmpeg-codecs.html
- FFmpeg H.264 encoding guide (CRF range, presets): https://trac.ffmpeg.org/wiki/Encode/H.264
- EBU R 128 loudness recommendation: https://tech.ebu.ch/docs/r/r128.pdf
- YouTube recommended upload encoding settings: https://support.google.com/youtube/answer/1722171

