Communitygithub.com

color-grading

Color Engineering & Cinematic Grading for video projects. Use it whenever new footage enters an edit pipeline (FFmpeg pipelines, HyperFrames sources), and whenever the picture looks flat, grey, washed out, too dark or off-colour. It covers the colour-management audit (matrix, range, tags, HDR), scene analysis (histogram, waveform, parade, vectorscope, WB / CCT, skin, noise), adaptive technical correction, 9 creative presets with intensity (talking heads, corporate, film looks, travel / landscape), skin-tone protection, secondaries, 3D LUT engine (.cube import / blend / compose / compare), Visual Color Brand Kit, shot matching, QC contact sheets and verified Rec.709 export.

What is color-grading?

color-grading is a Claude Code agent skill that color Engineering & Cinematic Grading for video projects. Use it whenever new footage enters an edit pipeline (FFmpeg pipelines, HyperFrames sources), and whenever the picture looks flat, grey, washed out, too dark or off-colour. It covers the colour-management audit (matrix, range, tags, HDR), scene analysis (histogram, waveform, parade, vectorscope, WB / CCT, skin, noise), adaptive technical correction, 9 creative presets with intensity (talking heads, corporate, film looks, travel / landscape), skin-tone protection, secondaries, 3D LUT engine (.cube import / blend / compose / compare), Visual Color Brand Kit, shot matching, QC contact sheets and verified Rec.709 export.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/karchebnyi/video-skills/tree/HEAD/color-grading

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

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, .cube read / write / blend / compose / sampling.
  • presets/*.json, each with soft / balanced / rich intensities:
    • 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-skills on Windows (C:\video-skills when the profile path is not ASCII), ~/.local/share/video-skills elsewhere:
    • color-kits/<name>.json — Visual Color Brand Kits made by kit (--kit NAME finds them by name);
    • cache/color/ — scene analysis, keyed by file, size, mtime, range and decode (override with CG_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+ with zscale, lut3d, waveform and vectorscope must 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

  1. 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, so audit reports 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.
  2. 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).
  3. Technical correction (one per scene, so there is no flicker), in this order:
    1. White balance on two axes: temperature gently (the light's warmth is part of the scene), green/magenta firmly.
    2. Levels from the source: black and white pulled part-way to the targets, slope at most 1.25, never a full stretch.
    3. 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_key range is moved, and only to its edge.
    4. Neutral contrast and an asymptotic shoulder.
    5. Soft gamut: bright saturated colours compress towards their own luma instead of clipping.
  4. 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.
  5. One LUT per scene. Technical, creative and an optional brand LUT are composed into a single 33³ .cube, so the render applies one lut3d, not a chain.
  6. Render chain (apply):
    zscale (the source's own matrix / range / primaries) → gbr full → gbrpf32le → lut3d (tetrahedral) → zscale 709 limited → yuv420p
    
    Tags: -colorspace bt709 -color_primaries bt709 -color_trc bt709 -color_range tv. Re-encode stages must use setparams=... so the tags survive. verify checks the tags and ΔE against the graded reference after the final encode (target ΔE < 2).
  7. 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-lut is 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 (lut then apply, or the vf_grade(src, lut) chain inside your own ffmpeg call), composite graphics in a later stage, keep 709 tags on every re-encode, and run verify on 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's assets/; graphics are composited on top, never graded.

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

Related Skills