---
name: ffmpeg-beat-sync-montage
description: Trim AI video clips past slow 0.40s I2V ease-in frames, snap cuts to exact musical BPM bar durations at constant 24fps CFR, unify mixed models with subtle 35mm temporal film grain, and mux stereo soundtracks at -14 LUFS with Safari-safe yuv420p +faststart. Use when assembling beat-synced trailers, music videos, or fast AI montages with FFmpeg.
---

# FFmpeg Beat-Sync Montage & Concat Playbook

## 1. BPM-to-Seconds Cut Math
Calculate exact cut lengths before trimming any clip:
- `beat_sec = 60 / BPM` (Example at `120 BPM`: `1 beat = 0.50s`, `2 beats = 1.00s`, `4 beats / 1 bar = 2.00s`, `8 beats = 4.00s`)
- Always skip the first `0.35s–0.50s` (`-ss 0.40`) on Image-to-Video clips so every cut enters *in motion* rather than easing out of a frozen frame.

## 2. Normalize Every Cut to Identical CFR, Geometry & SAR (Prevents Concat Glitches)
Never run `-c copy` concat on mixed-model AI clips (`Kling`, `Runway`, `Gemini Omni Flash`, `Wan`) because mismatched SAR, frame rate, or timebases cause frozen frames or audio drift. Re-encode normalized intermediate cuts at near-lossless `-crf 15`:

```bash
ffmpeg -y -ss "$START_OFFSET" -i "$SRC_CLIP" -t "$BEAT_DURATION" \
  -vf "scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080,fps=24,setsar=1" \
  -c:v libx264 -crf 15 -pix_fmt yuv420p -an "$CUT_OUT"
```
*(For 9:16 vertical Reels/TikTok, swap `1920:1080` cleanly to `1080:1920`.)*

## 3. Join Beat-Locked Cuts + Shared 35mm Temporal Grain + -14 LUFS Audio Master
Build `concat.txt` with absolute paths (`file '/abs/path/cut_01.mp4'`), then render one unified delivery master:

```bash
ffmpeg -y -f concat -safe 0 -i concat.txt -i soundtrack_48k.wav \
  -vf "noise=alls=6:allf=t+u" \
  -af "aresample=48000,loudnorm=I=-14:TP=-1.0:LRA=11" \
  -c:v libx264 -crf 18 -pix_fmt yuv420p -movflags +faststart \
  -c:a aac -b:a 192k -ar 48000 -shortest \
  beat_synced_master.mp4
```

## 4. Mandatory ffprobe Verification Gate
Always verify pixel format, constant frame rate, audio clock, and exact runtime before reporting done:

```bash
ffprobe -v error -show_entries format=duration \
  -show_entries stream=codec_name,pix_fmt,r_frame_rate,sample_rate \
  -of compact=p=0 beat_synced_master.mp4
```
Expected checks: `codec_name=h264`, `pix_fmt=yuv420p`, `r_frame_rate=24/1`, `codec_name=aac`, `sample_rate=48000`.
