Purpose
Cut one source video into a set of named clip files at exact time windows. Each clip is re-encoded (not stream-copied) with libx264, so cuts land frame-accurately on the requested in/out points — important when the clips will be dropped into an edit. This is the mechanical cutting step: deciding which windows to cut is the caller's job (e.g. build-brand-clip-library decides windows by watching the video, then calls this atom).
Inputs
source(required) — path to the source video file.clips(required) — path to a JSON array of clip specs. Each spec hasnameplus eitherendorduration.start/endaccept seconds (number) or a timecode string (SS,MM:SS,HH:MM:SS, optional.ms):[ {"name": "hook-laptop-close", "start": 0, "end": 2.6}, {"name": "mac-mini-glow", "start": "00:03", "duration": 5}, {"name": "endcard", "start": 90.0, "end": "01:34.4"} ]output_dir(required) — destination folder for the clip files.crf(optional, default 18) — x264 quality; lower is higher quality.overwrite(optional, default false) — re-cut clips even if the output file already exists (re-runs are otherwise idempotent).
Workflow
- Verify
ffmpegis on PATH (which ffmpeg) and the source video exists. - Run the cutter:
python3 skills/atoms/editing/trim-video-clips/scripts/trim_clips.py \ --source /path/to/source.mp4 \ --clips /path/to/clips.json \ --output-dir /path/to/clips/ \ [--crf 18] [--overwrite] - The script, per clip: slugifies
name→<slug>.mp4, resolves the time window, and runsffmpeg -y -ss <start> -i <source> -t <duration> -c:v libx264 -crf <crf> -preset fast -pix_fmt yuv420p -c:a aac -b:a 192k <out>. - It writes
manifest.jsontooutput_dirlisting every clip, its window, status, and any warnings/errors.
Output
- One
<slug>.mp4per clip spec inoutput_dir. output_dir/manifest.json— run metadata:skill_name,run_id,input_path,output_files, per-clip records (name,file,start,duration,status),status,warnings,errors.
Quality Checks
- One clip file exists per valid spec; each is non-zero size.
- Clip durations match the requested windows (verify with
ffprobe). - Clips are playable and re-encoded (h264/yuv420p), so they cut cleanly into an edit.
manifest.jsonexists and everyoutput_filespath resolves on disk.
Failure Modes
- Source missing / unreadable — the script exits with a clear error before cutting.
- Bad clip spec (no
end/duration, non-positive duration, unparseable time) — that clip is skipped and recorded inmanifest.jsonerrors; other clips still cut. ffmpegnot installed — install viabrew install ffmpeg.- Window past end of video — ffmpeg produces a shorter clip; check durations against
ffprobe. - Source has no audio stream — clips are produced without audio; this is expected, not an error.