Communitygithub.com

Color Grade AI

生成 .cube 格式的 3D LUT,用于 DaVinci Resolve 和 Adobe Premiere Pro 中的色彩校正。分析帧或剪辑,通过测量拟合校正,并输出可直接使用的 LUT。可检测对数与显示参考素材,匹配不同镜头,并在浏览器中实时预览调色效果。

Color Grade AI 是什么?

Color Grade AI 是一款专注于为视频后期制作生成精准 3D LUT(.cube 格式)的色彩校正工具,适用于 DaVinci Resolve、Adobe Premiere Pro 等专业软件,也支持通过 ffmpeg 批量应用。该工具的核心优势在于其“闭环测量与拟合”机制:通过自动分析画面(如直方图、白平衡、肤色、饱和度、黑电平),迭代应用候选校正参数并重新测量效果,直至残差最小化,最终输出可直接用于调色节点的 LUT 文件。它能够智能识别素材是对数(Log)还是显示参考(Display-Referred)格式,并据此调整校正策略,避免对 Log 素材进行错误调整。工具包含一套预设调整(如夜间偏暖修复、电影暗调等),并允许用户通过 YAML 配置文件自定义新的 LUT 类型和节点链。其核心工作流包括:自动分级(auto_grade.py)输出分析报告和 LUT;镜头匹配(match_grade.py)让一个镜头向另一个镜头的色彩风格靠拢;交互式 HTML 预览页面支持实时拖放画面并调整参数,所见即所得地生成和导出 LUT。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/JulioBorges/video-editor-pipeline/tree/HEAD/skills/color-grade-ai

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Color Grade AI 是做什么的?

生成针对性的 .cube 3D LUT,用于色彩校正。

将其指向一帧或一段剪辑,它会测量出问题所在,通过应用候选校正参数并重新测量来拟合校正,最终交给你一个 .cube 文件。在开始任何操作之前,它会先判断素材是对数还是显示参考格式,因为这里的所有目标都假设是显示参考 Rec.709。交互式浏览器预览功能可实时生成 LUT,并导出你正在查看的链。

快速开始

# 生成校正 LUT(预设定义在 presets.yml 中)
ruby generate_lut.rb <类型> <输出路径> [--strength=0.0-1.0]

# 将多个预设烘焙成一个 .cube LUT
ruby generate_chain_lut.rb <输出路径> <预设名@强度> ...

# 这是对数还是显示参考 Rec.709?
python3 footage_type.py <frame.png>

# 分析一帧,并可选择拟合和输出校正
python3 auto_grade.py <frame.png> [--emit fix.cube] [--transfer log|display]

# 拟合校正,不输出分析报告
python3 solve_grade.py <frame.png> --emit fix.cube

# 为整个剪辑(而非单帧)拟合一个校正
python3 sample_clip.py <clip.mov> --emit fix.cube [--frames 12]

# 将一个镜头匹配到另一个镜头,并输出 LUT
python3 match_grade.py <参考图像.png> <待校正图像.png> --emit match.cube

# 一个区域(皮肤、墙面、服装...)的色彩统计信息
ruby analyze_frame.rb <图像路径> <x1,y1,x2,y2> [标签]
python3 analyze_region.py <图像路径> <x1,y1,x2,y2> [标签]   # 仅输出 JSON

# 启动交互式预览
python3 -m http.server 8080
# 打开 http://localhost:8080/preview.html

自动分级分析

auto_grade.py 分析一帧 Rec.709 画面(转换 LUT 之后),并使用经典色彩科学为每个节点推荐校正值:

节点方法目标
对比度/曝光度亮度直方图百分位数中位数 ~0.45,动态范围 ~0.85
白平衡灰度变幻法 (Minkowski p=6) + 白补丁混合RGB 增益接近 1.0
肤色YCbCr 肤色中心点检测,I-line 校正色相 ~20° (肤色)
饱和度Hasler-Susstrunk 色彩饱和度度量无目标 — 仅在 25-95 范围外操作
黑电平底部 5% 亮度分析 + 噪底黑点 < 0.02
# 完整工作流
ffmpeg -y -ss 19 -i video.mp4 -vframes 1 -vf "scale=1280:-1" -update 1 frame_raw.png
ffmpeg -y -i frame_raw.png -vf "lut3d='conversion.cube':interp=tetrahedral" -update 1 frame_709.png
python3 auto_grade.py frame_709.png

匹配分级

match_grade.py 拟合一个校色,使一帧向另一帧靠拢,并输出 .cube 文件。与 solve_grade.py 采用相同的闭环方法——应用、重新测量、保留能缩小差距的参数——但目标是一张参考图像,而不是一组固定的理想值。

python3 match_grade.py <参考图像.png> <待校正图像.png> --emit match.cube

它匹配通道平衡、曝光度、黑电平和饱和度,并且拒绝跨传输函数进行色调匹配:将对数素材匹配到 Rec.709 是缺少转换 LUT 的问题,而不是调色问题。

交互式预览 (preview.html)

基于浏览器的节点链预览器,使用 Preact + HTM (~4KB)。校正 LUT 是根据 presets.json 以请求的精确强度实时生成的,而不是获取预烘焙的——因此滑块插值参数,执行与 CLI 相同的操作,所见即所得,与 generate_lut.rb 输出的一致。

特点:

  • 拖放任意帧(原始 S-Log3 或已转换)
  • 节点 1:转换 LUT — 添加你自己的 .cube 文件(不包含在该仓库中)
  • 节点 2-6:校正链 — 下拉选择预设 + 强度滑块
  • 导出 .cube — 将整个可见链烘焙成一个文件,可直接拖入 Resolve,这样预览就不再是你需要单独重现的东西
  • 创意预设 — 一键式策划效果(Studio Dance、Studio Clean、Studio Ambient、Studio Gold、Studio Film)
  • S-Gamut3 → Cine 补偿切换开关,用于色域不匹配
  • 绕过/重置所有节点
  • URL 参数 — 深度链接到特定状态:?image=frame.png&lut=path/to.cube&preset=studio_gold

预览以 17 格渲染(~30ms,能跟上滑块速度),以 33 格导出。转换 LUT 由用户提供(在 luts/ 目录下通过 .gitignore 忽略);correction_luts/ 中预烘焙的校正 LUT 保留给仅下载使用、从不运行工具的用户。

配置驱动预设

所有 LUT 类型都在 presets.yml 中定义。每个预设都是一个有序处理步骤的流水线。添加新的 LUT 类型只需添加一个 YAML 条目——无需修改 Ruby 代码。

可用的步骤类型:exposure(曝光)、highlight_protect(高光保护)、black_crush(黑色压黑)、hue_desat(色相去饱和)、skin_correction(肤色校正)、shadow_sat_boost(阴影饱和度提升)、skin_highlight(皮肤高光)、skin_rolloff(皮肤滚落)、global_highlight_desat(全局高光去饱和)、rgb_rebalance(RGB 重新平衡)、global_sat(全局饱和度)。

可用的 LUT 类型

校正 LUT(转换后应用)

类型修复内容
night_warm_fix针对曝光不足的暖色/红色场景的一体化方案。~1 档提升 + 肤色色相偏移 + 黑色压黑。
night_purple_fix针对曝光不足的紫色/洋红舞台灯光的一体化方案。RGB 重新平衡 + 提升 + 去饱和 + 肤色修复。
yellow_fix舞台灯光导致的暖琥珀色/黄色色调。色相 H=10-60,55% 去饱和。
red_skin_fix暖色实用光源导致的红色/潮红皮肤。色相偏移至肤色,仅针对皮肤。
pink_cast_fix舞台灯光导致的粉色/洋红色调。温和的 RGB 重新平衡 + 洋红去饱和。
overexposure_fix全局 ~1 档降低,带高光滚落。
underexposure_fix全局 ~1.2 档提升,带阴影恢复。
black_crush将低于 12% 的模糊/提升的黑场压至纯黑。
skin_highlight_fix针对亮度高于 70% 的区域进行仅作用于皮肤的微妙高光滚落。
golden_warm通过 RGB 重新平衡 (R:1.20, G:1.00, B:0.80) 实现强烈的金色暖色调偏移。用于丰富的暖色电影级效果。
cinema_dark深沉的情绪化对比度,伽马 1.45,阴影提升 0.02,以及膝部压缩 (0.72-0.90)。

节点链构建块

类型节点功能
studio_punch对比度为采光良好的室内场景提供微妙的对比度增强
film_contrast对比度更强的胶片感对比度,阴影更深
flat_lift对比度提升阴影,呈现更柔和、更开阔的效果
warm_shift色温通过 RGB 重新平衡实现微妙的暖色调偏移
cool_shift色温通过 RGB 重新平衡实现微妙的冷色调偏移
led_green_fix色温修复 LED/荧光灯导致的绿色色调
sat_boost饱和度全局 +15% 饱和度提升
golden_warm色温强烈的金色暖色调偏移 (R:1.20, G:1.00, B:0.80)
sat_reduce饱和度全局 -15% 饱和度降低
sgamut3_to_cine色域S-Gamut3 → Cine 补偿(去饱和 ~12%)
cinema_dark对比度深沉的情绪化对比度(伽马 1.45,阴影提升,膝部压缩)
black_lift黑电平提升黑场,呈现复古/褪色效果

创意预设(节点链组合)

预设效果链
Studio Clean自然明亮studio_punch(50%) + sat_boost(50%)
Studio Balanced暖色自然studio_punch(80%) + warm_shift(30%) + sat_boost(50%) + black_crush(15%)
Studio Dance暖色电影感studio_punch(100%) + warm_shift(40%) + sat_boost(60%) + black_crush(25%)
Studio Ambient无填充光studio_punch(80%) + warm_shift(100%) + sat_boost(100%) + black_crush(20%)
Studio Gold暖色电影感cinema_dark(80%) + golden_warm(75%) + sat_boost(100%) + black_crush(10%)
Studio Film情绪化电影感film_contrast(60%) + warm_shift(20%) + sat_reduce(30%) + black_crush(40%)

烘焙链式 LUT

generate_chain_lut.rb 将多个不同强度的预设烘焙成一个 .cube 文件。这让你可以在 Resolve 中将一个创意预设作为一个节点应用,而不需要多个节点。

# 将 Studio Balanced 烘焙成一个 LUT
ruby generate_chain_lut.rb correction_luts/studio_balanced_baked.cube \
  [email protected] [email protected] [email protected] [email protected]

# 烘焙 Studio Dance
ruby generate_chain_lut.rb correction_luts/studio_dance_baked.cube \
  [email protected] [email protected] [email protected] [email protected]

所有创意预设的预烘焙 LUT 已提交至 correction_luts/ 目录。

你也可以将转换 LUT 和创意链烘焙成一个 .cube 文件,以便在 Resolve 中实现单节点调色:

# 将转换 + 创意烘焙成一个单通道 LUT
ruby generate_chain_lut.rb final_grade.cube \
  --conversion=luts/SLog3_to_Rec709.cube \
  [email protected] [email protected] [email protected] [email protected]

视频导出工作流

使用 ffmpeg 一次性应用转换 + 校正 LUT 并编码为 H.265。

# 提取一帧样本用于分析
ffmpeg -y -ss 19 -i input.mp4 -vframes 1 -vf "scale=1280:-1" -update 1 frame_raw.png

# 对帧应用转换 LUT 用于预览
ffmpeg -y -i frame_raw.png -vf "lut3d='conversion.cube':interp=tetrahedral" -update 1 frame_709.png

# 完整编码:转换 + 校正 → H.265 4K
# 50Mbps 母版(用于重新编辑):
ffmpeg -i input.mp4 \
  -vf "lut3d='conversion.cube':interp=tetrahedral,lut3d='correction.cube':interp=tetrahedral,format=nv12" \
  -c:v hevc_videotoolbox -b:v 50M -spatial_aq 1 \
  -c:a aac -b:a 192k -tag:v hvc1 output_master.mp4

# 15Mbps 网络优化版(用于 Instagram/网络):
ffmpeg -i input.mp4 \
  -vf "lut3d='conversion.cube':interp=tetrahedral,lut3d='correction.cube':interp=tetrahedral,format=nv12" \
  -c:v hevc_videotoolbox -b:v 15M -spatial_aq 1 \
  -c:a aac -b:a 128k -tag:v hvc1 output_web.mp4

注意:

  • hevc_videotoolbox 使用 Apple Silicon 硬件编码(M1/M2/M3)
  • format=nv12 转换为 YUV420p 以确保兼容性
  • -tag:v hvc1 确保 QuickTime/浏览器播放兼容性
  • spatial_aq 1 启用自适应量化以获得更好画质

转换 LUT(不在仓库中)

转换 LUT(例如索尼 S-Log3 → Rec.709、ARRI LogC → Rec.709)是针对特定相机的,通常需要商业许可。将它们存放在 luts/ 目录下(已在 .gitignore 中忽略)。

Phantom LUTs(phantomluts.com)—— 索尼相机的 ARRI Alexa709 模拟:

  • 位置:luts/a7s3-arri-g8/A7s3 Phntm Arri LUTs G8/65x/SLog3/Neutral A7s3_65x.cube
  • 变体:Neutral、IceBlue、Jamaica、Tungsten、Utopia(标准版 + 旧版)
  • 后期处理使用 65x,机内/监看使用 33x
  • 设计用于 S-Log3 + S-Gamut3.Cine;对于 S-Gamut3 素材,启用 Cine 补偿切换

Resolve 设置: 色彩科学 = DaVinci YRGB,时间线 = Rec.709-A (Mac),3D LUT 插值 = Tetrahedral

节点顺序(DaVinci Resolve)

专业的串行节点链:

  1. 转换 LUT(相机对数 → Rec.709)
  2. 对比度 / 曝光度
  3. 白平衡 / 色温
  4. 肤色校正
  5. 色彩饱和度
  6. 黑电平
  7. (降噪——无法通过 LUT 实现)
  8. (暗角——无法通过 LUT 实现)
  9. (锐化——无法通过 LUT 实现)

应用 LUT

DaVinci Resolve: 每个 LUT 添加一个串行节点。右键单击节点 → LUT → 浏览到 .cube 文件。

Adobe Premiere Pro: Lumetri Color → 创意 → Look 下拉菜单 → 浏览到 .cube 文件。

ffmpeg(批处理/预览):

ffmpeg -i input.mp4 -vf "lut3d='conversion.cube':interp=tetrahedral,lut3d='correction.cube':interp=tetrahedral" output.mp4

对数 vs 显示参考

此仓库中的每个 LUT 和每个目标都假设是显示参考 Rec.709,在相机转换 LUT 之后应用。如果输入对数素材,分析器会看到提升的黑场和平坦的对比度,将其视为缺陷,并为本应存在的东西拟合一个校正。结果看起来合理但实际上错误,这比失败更糟糕——因此每次运行时都会测量并明确说明这种区别。

python3 footage_type.py frame.png            # 只需询问它是什么
python3 auto_grade.py frame.png --transfer log
python3 solve_grade.py frame.png --transfer display --emit fix.cube

检测读取的是编码的形状,而非元数据,因为当帧到达工具时,它通常是一个 PNG:

信号对数看起来像
黑点远高于零(S-Log3 将黑点放在 0.09 附近)
高光被抑制,没有任何部分接近 1.0
范围压缩到狭窄的波段内
纯度去饱和,转换前
中点位置中位数在范围内偏高

三种结果,不是两种。 一个严重扁平化、提升、去饱和的显示参考画面,从形状上看确实与对数无法区分,因此有一个明确的 ambiguous(模糊)判定。猜哪一边都会更糟:称其为对数会阻止一个合法的调色,称其为显示会产生一个自信但错误的调色。模糊时询问你,你总能回答,而测量永远不能。

中点的信号是区分两者的关键:缩放显示参考图像会保持中位数的相对位置不变,而对数传输则会移动它。

对对数或模糊素材会改变什么。 曝光度和黑电平会被抑制,因为 0.45 的中位数和 0.02 的黑点描述的是一个已调色的图像,而不是一个对数容器。白平衡和肤色色相仍然运行——色偏就是色偏,皮肤应该始终显示为皮肤,无论传输曲线如何。--transfer 参数会完全覆盖检测结果。

闭环调色

该工具不是提供供你手动转录的建议,而是可以通过测量拟合校正并直接交给你 LUT:

# 输入帧,输出校正 LUT
python3 auto_grade.py frame.png --emit fix.cube

# 和上面一样,但不输出分析报告
python3 solve_grade.py frame.png --emit fix.cube

# 针对整个剪辑(而非单个任意帧)进行拟合
python3 sample_clip.py clip.mov --emit fix.cube --frames 12

如何选择强度。 求解器应用一个候选校正,重新测量帧,并保留实际最小化剩余误差的值。早期版本使用手动调整的常数 (deviation * 10) 进行猜测,完全没有反馈。

帧分析

analyze_frame.rb(彩色文本)和 python3 analyze_region.py(JSON)提供单个特定区域的色彩统计数据。选择你需要的任何区域——皮肤、墙面、服装、背景——工具会报告该区域的色相、饱和度、亮度、RGB 值以及与被识别皮肤中心的接近程度。

# 分析演员脸上的皮肤区域
ruby analyze_frame.rb frame_709.png 400,300,450,360 "face"

# 分析背景中的墙面
python3 analyze_region.py frame_709.png 100,200,300,400 "wall"

对于肤色分析,它会测量到已发布肤色中心点的色相-亮度距离,以便你知道特定皮肤区域是保持于该中心、偏移到黄色/红色,还是升到不正常的高亮度。该工具对这些测量值不做任何判断——它仅报告它们,并让下游调整或你决定该怎么做。

安装

# 克隆仓库
git clone https://github.com/yourusername/color-grade
cd color-grade

# Python 依赖
pip install -r requirements.txt

# Ruby(系统安装即可)
# mac 上自带 Ruby
numpy
PIL
scipy

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

content-repurposing

Fans one long-form pillar asset (video, podcast episode, or article) out into 10+ platform-native atomic pieces with a derivation map - clips, quote cards, threads, LinkedIn posts, newsletter and blog sections - each recast in the target platform's register and sequenced over the week. Use when someone says "turn this video into clips", "repurpose this podcast episode", "get more mileage out of this article", or "build a distribution plan from one piece of content". Do NOT use to re-express one finished post as the native equivalent of the same asset on each channel - use cross-platform-reformatter instead; do NOT use to mechanically crop, caption, and export a finished video for social feeds - use social-video-formatter instead; do NOT use to design the ongoing pillar-and-cadence publishing system itself - use creator-content-calendar instead.

thumbnail-concept

Produces three distinct high-CTR YouTube thumbnail concepts per video - each a full spec with focal point, precise facial-expression direction, text overlay copy, color and background direction, and two paired title variants. Use when someone says "I need a thumbnail idea", "why is my CTR low", "help me pick a thumbnail and title", or is planning a video before filming and wants the click package designed first. Do NOT use for the spoken and visual opening seconds of the video itself - use video-hook-writer instead; do NOT use to write the full video - use youtube-script-writer instead; do NOT use for cropping, captioning, or exporting finished video files - use social-video-formatter instead.

video-hook-writer

Writes the spoken line plus visual frame combination for the first 3 seconds of a short-form video, delivering labeled variants built from six proven hook formulas and matched to TikTok, Reels, or Shorts. Use when someone says "write a hook for this video", "my Shorts die in the first seconds", "give me openers for this TikTok", or "how should this Reel start". Do NOT use for the first line of a written post, thread, or caption - use social-hook-generator instead; do NOT use to build the full thread after the opener - use tweet-thread-builder instead; do NOT use for the 30-second intro of a long-form YouTube video - use youtube-script-writer instead; do NOT use to design the clickable image for a video - use thumbnail-concept instead.

youtube-script-writer

Writes retention-engineered long-form YouTube scripts on a hook/body/payoff architecture - a first-30-seconds hook that survives the retention cliff, a beat-sheet body with mini-hooks and bridges, timed pattern interrupts, and a payoff that over-delivers - with B-roll and editing cues marked inline. Use when someone says "script my next video", "my retention graph dies at the start", "tighten this draft", or "outline a video on X". Do NOT use for the 3-second opener of TikTok, Reels, or Shorts - use video-hook-writer instead; do NOT use for spoken voiceover synced to on-screen tutorial actions - use narration-script instead; do NOT use for a sales demo built on a buyer's discovery notes - use demo-script instead; do NOT use to design the thumbnail and title - use thumbnail-concept instead.

相关技能