Color Grading
Goal: a rich, deep, natural picture with correct tonal balance and kept detail, consistent across scenes, without over-processing.
Where things are
scripts/color_grade.py— CLI and adaptive logic: audit, analyze, lut, sheet, apply, verify, compare, kit, match.scripts/cg_core.py— colour math: decode of each source with its own matrix / range / primaries (16-bit), OKLab, tone curve with toe and shoulder, technical / creative / skin-protection steps, soft gamut,.cuberead / write / blend / compose / sampling.presets/*.json, each withsoft/balanced/richintensities:premium_podcast(default for a talking person),clean_corporate,natural_studio;cinematic_film,luxury_editorial,teal_orange,analog_film(optional grain);social_media_pop(Reels / Shorts);travel_landscape(default for scenery and travel: sky, water, snow, sand; people in frame keep skin protection).
models/face_landmarker.task— MediaPipe face model (Apache 2.0), loaded from memory, so non-ASCII paths are fine.- User data, outside the skill folder. Root:
VIDEO_SKILLS_HOME, else%LOCALAPPDATA%\video-skillson Windows (C:\video-skillswhen the profile path is not ASCII),~/.local/share/video-skillselsewhere:color-kits/<name>.json— Visual Color Brand Kits made bykit(--kit NAMEfinds them by name);cache/color/— scene analysis, keyed by file, size, mtime, range and decode (override withCG_CACHE), so changes to text, plates or audio never re-analyse.
Python
Use the skills' own environment, made by setup/setup.ps1 (or setup.sh) of the repository (Python 3.11: numpy, scipy, opencv, mediapipe, colour-science, pillow):
- Windows:
<root>\py311\Scripts\python.exe, e.g.%LOCALAPPDATA%\video-skills\py311\Scripts\python.exe; - macOS / Linux:
<root>/py311/bin/python. If it is missing, tell the person to run the setup script. Always run with-X utf8. FFmpeg 7+ withzscale,lut3d,waveformandvectorscopemust be on PATH.
Commands
CG=<skills>/color-grading/scripts/color_grade.py
$PY -X utf8 $CG audit SRC [--pipeline-frame FILE --at T --src-at T --lut X.cube]
$PY -X utf8 $CG analyze SRC [--t0 --t1 --n 8]
$PY -X utf8 $CG lut SRC OUT.cube [--preset premium_podcast] [--intensity soft|balanced|rich|0.7] [--kit NAME] [--brand-lut B.cube --brand-k 0.5]
$PY -X utf8 $CG sheet SRC [SRC ...] OUTDIR [--preset P] [--frames 2] [--kit NAME]
$PY -X utf8 $CG apply SRC OUT.mp4 --lut X.cube [--t0 --t1] [--grain 0.06]
$PY -X utf8 $CG verify FINAL.mp4 --ref SRC --lut X.cube --at T --src-at T
$PY -X utf8 $CG compare SRC --at T OUT.jpg A.cube B.cube ... [--k 0.8]
$PY -X utf8 $CG kit REF.jpg|REF.mp4 ... --out NAME
$PY -X utf8 $CG match SRC SRC ... [--preset P]
How it works
- Audit first. Before any look, prove where the picture loses saturation or contrast:
- read the source's matrix, range and primaries from its tags; untagged files follow the usual rules (HD → BT.709, SD → BT.601;
yuvj*→ full range). Phone footage is often full range and old SD files use BT.601: decoding them as 709 limited stretches contrast and shifts colour, soauditreports what was found or assumed; - compare the correct decode of the source with the pipeline's intermediates and with the final file;
- never boost saturation or contrast to cover a colour-management error; never retag metadata without checking the pixels.
- read the source's matrix, range and primaries from its tags; untagged files follow the usual rules (HD → BT.709, SD → BT.601;
- Analysis. 8 frames per scene, decoded to full-range RGB at 16 bit. Measures Y percentiles, shadow and highlight clipping, contrast, OKLab chroma, WB from near-neutral pixels (CCT and Duv), green/magenta cast, noise in flat shadows, lighting change across the scene, and skin from the MediaPipe face mesh (oval minus eyes, brows and lips; median L, C and hue).
- Technical correction (one per scene, so there is no flicker), in this order:
- White balance on two axes: temperature gently (the light's warmth is part of the scene), green/magenta firmly.
- Levels from the source: black and white pulled part-way to the targets, slope at most 1.25, never a full stretch.
- Exposure in linear light. With a face: solved iteratively so the face lands on the same brightness in every scene (shot matching); when the frame is darkened, shadows are protected. Without a face: the scene keeps its own key — snow, sand and bright skies stay bright, dusk stays dark; only a frame outside the preset's
scene_keyrange is moved, and only to its edge. - Neutral contrast and an asymptotic shoulder.
- Soft gamut: bright saturated colours compress towards their own luma instead of clipping.
- Creative grade in OKLab: contrast around the scene's own mid-grey with toe protection; shadows and highlights; saturation plus vibrance; luma-vs-sat, sat-vs-sat; hue-vs-sat, hue-vs-hue, hue-vs-lum; split toning. Intensity scales every move.
- Skin protection: inside the skin hue window measured from the face, chroma may grow at most
max_gain; hue and luma moves of the look fade out; a hue outside the natural 32–75° range (OKLab) is pulled half-way back.
- Skin protection: inside the skin hue window measured from the face, chroma may grow at most
- One LUT per scene. Technical, creative and an optional brand LUT are composed into a single 33³
.cube, so the render applies onelut3d, not a chain. - Render chain (
apply):
Tags:zscale (the source's own matrix / range / primaries) → gbr full → gbrpf32le → lut3d (tetrahedral) → zscale 709 limited → yuv420p-colorspace bt709 -color_primaries bt709 -color_trc bt709 -color_range tv. Re-encode stages must usesetparams=...so the tags survive.verifychecks the tags and ΔE against the graded reference after the final encode (target ΔE < 2). - QC sheet. Each source gets one: Original / Technical / Soft / Balanced / Rich; waveform, RGB parade, vectorscope and histogram for Original and Balanced; the source's problems and the grade's check (added clipping, crushed shadows, oversaturation, skin before / after), plus
report.json.
Rules
- Grade the source footage before any graphics: logos, plates, titles, subtitles and brand colours are composited on top and never graded.
- Never change how people look: no blurring of the room, no smoothing or whitening of skin, which keeps its own pigmentation. Retouch is not part of this skill.
- Do not stretch every histogram to full range. Respect the lighting and the mood of the scene.
- HLG or PQ sources (HDR phones) and log footage (D-Log, S-Log, V-Log) need a technical conversion to SDR Rec.709 first, as a separate ffmpeg pass (the manufacturer's LUT or a tonemap) whose result is then graded.
--brand-lutis applied after the grade, so it is not the place for a log-to-709 LUT. This skill grades SDR Rec.709. - No paid services or external APIs.
- Always show the contact sheets to the person (as images in chat) and let them pick the preset and intensity before a full render.
Pipeline integration
- FFmpeg pipelines: grade each source clip in the first stage with one LUT per clip (
lutthenapply, or thevf_grade(src, lut)chain inside your own ffmpeg call), composite graphics in a later stage, keep 709 tags on every re-encode, and runverifyon the final file. - HyperFrames: grade each source clip with
apply(or bake a LUT and apply it in ffmpeg) before it goes into the composition'sassets/; graphics are composited on top, never graded.