ffmpeg-mixing
Skill341 starsChanged 10 months agoApache-2.0View on GitHub
Mix, trim, and concatenate video clips with ffmpeg without audio/video desync. Use when stitching generated clips into an original video, inserting scenes at timestamps, or any ffmpeg filter_complex work involving trim/concat with a continuous audio track.
In this repository3 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdcCursor rule
- varg-video-generationSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 55
separate audio handling: use atrim on audio stream independently
- Very specific: line 56
setpts reset: always use setpts=PTS-STARTPTS after trim to reset timestamps
- Distinctive: line 57
scale before trim: when mixing different resolutions, scale first then trim
- Distinctive: line 58
video duration = audio duration: ensure total video segments match audio segment length
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
ffmpeg video mixing
Lessons for mixing video clips with ffmpeg while keeping audio and video in sync.
problem: audio/video desync when mixing clips
what went wrong
using -ss X -t Y to pre-trim input, then applying relative trim filters caused timing drift:
# BAD: relative timestamps after pre-trim
ffmpeg -ss 64 -t 36 -i original.mp4 ...
-filter_complex "
[0:v]split=5[orig1][orig2]...;
[orig1]trim=0:4,setpts=PTS-STARTPTS[o1];
[orig2]trim=4:11,setpts=PTS-STARTPTS[o2];
..."this produced wrong duration (38s instead of 36s) with audio desync.
solution: use absolute timestamps from full input
trim directly from full original using absolute timestamps:
# GOOD: absolute timestamps from full file
ffmpeg -i original.mp4 -i scene1.mp4 -i scene2.mp4 ...
-filter_complex "
[0:v]trim=64:68,setpts=PTS-STARTPTS[o1];
[1:v]scale=1280:720,trim=4:6,setpts=PTS-STARTPTS[s1];
[0:v]trim=70:75,setpts=PTS-STARTPTS[o2];
...
[o1][s1][o2]...concat=n=N:v=1:a=0[outv];
[0:a]atrim=64:100,asetpts=PTS-STARTPTS[outa]
"
-map "[outv]" -map "[outa]"key points
- absolute timestamps: trim from full input file, not pre-trimmed
- separate audio handling: use
atrimon audio stream independently - setpts reset: always use
setpts=PTS-STARTPTSafter trim to reset timestamps - scale before trim: when mixing different resolutions, scale first then trim
- video duration = audio duration: ensure total video segments match audio segment length
example: inserting clips into original
to insert generated clips at specific timestamps while keeping continuous audio:
ffmpeg -y \
-i original.mp4 \
-i generated-scene.mp4 \
-filter_complex "
[0:v]trim=START1:END1,setpts=PTS-STARTPTS[o1];
[1:v]scale=1280:720,trim=0:DURATION,setpts=PTS-STARTPTS[s1];
[0:v]trim=START2:END2,setpts=PTS-STARTPTS[o2];
[o1][s1][o2]concat=n=3:v=1:a=0[outv];
[0:a]atrim=AUDIO_START:AUDIO_END,asetpts=PTS-STARTPTS[outa]
" \
-map "[outv]" -map "[outa]" \
-c:v libx264 -preset fast -crf 18 \
-c:a aac -b:a 192k \
output.mp4timestamps must add up: (END1-START1) + DURATION + (END2-START2) = AUDIO_END - AUDIO_START
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

