Communitygithub.com

color-grade

生成用於 DaVinci Resolve 和 Adobe Premiere Pro 色彩校正的 .cube 3D LUT。分析畫面或片段,擬合校正並輸出即用型 LUT。可偵測 Log 與顯示參考素材、比對不同鏡頭,並在瀏覽器中即時預覽調色效果。

color-grade 是什麼?

這是一個專為專業調色工作流程設計的 AI 工具,核心功能是生成 .cube 格式的 3D LUT。它能夠分析影片的單一畫面或整個片段,透過閉環測量與迭代擬合,自動找出色彩、曝光、白平衡等問題,並輸出可直接在 DaVinci Resolve 或 Adobe Premiere Pro 中使用的校正 LUT。此工具支援多個平台,可搭配 Bash、Ruby、Python 以及 ffmpeg 等腳本使用,並提供豐富的預設調色風格(如 Studio Gold、Studio Film)與可設定的節點鏈。其獨特之處在於能夠自動區分 Log 與顯示參考素材,避免誤判;同時提供即時瀏覽器預覽,讓調色師在調整滑桿的同時就能看到 LUT 效果,並能一鍵匯出完整的節點鏈為單一 .cube 檔案,大幅提升後期製作的效率與一致性。

相容平台~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 檔案。它在執行任何操作之前,會先判斷素材是 Log 還是顯示參考,因為這裡的所有目標都假設為顯示參考的 Rec.709。互動式瀏覽器預覽功能可即時生成 LUT,並能導出您正在查看的鏈結。

快速開始

# 生成校正 LUT(預設值定義於 presets.yml)
ruby generate_lut.rb <類型> <輸出路徑> [--strength=0.0-1.0]

# 將多個預設烘焙成單一 .cube LUT
ruby generate_chain_lut.rb <輸出路徑> <預設@強度> ...

# 判斷這是 Log 還是顯示參考的 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 <reference.png> <output.png> --emit match.cube

# 針對單一區域(皮膚、牆壁、服裝...)的色彩統計
ruby analyze_frame.rb <image_path> <x1,y1,x2,y2> [label]
python3 analyze_region.py <image_path> <x1,y1,x2,y2> [label]   # 僅 JSON

# 啟動互動式預覽
python3 -m http.server 8080
# 打開 http://localhost:8080/preview.html

自動調色分析

auto_grade.py 會分析 Rec.709 畫面(經過轉換 LUT 之後),並使用經典色彩科學為每個節點推薦校正值:

節點方法目標
對比度/曝光度亮度直方圖百分位數中位數 ~0.45,動態範圍 ~0.85
白平衡Shades of Gray (Minkowski p=6) + White Patch 混合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 <reference.png> <output.png> --emit match.cube

它會匹配通道平衡、曝光度、黑階和飽和度,並拒絕跨傳輸曲線進行色調匹配:將 Log 與 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 由使用者提供(已加入 gitignore 於 luts/ 目錄中);預先烘焙的校正 LUT 仍保留在 correction_luts/,供僅下載但從未執行工具的使用者使用。

設定驅動的預設

所有 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、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深沉的氛圍對比,gamma 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對比度深沉氛圍對比 (gamma 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(例如 Sony S-Log3 → Rec.709、ARRI LogC → Rec.709)是特定於攝影機的,且通常受商業許可保護。請將它們儲存在 luts/ 目錄中(已加入 gitignore)。

Phantom LUTs (phantomluts.com) — 適用於 Sony 攝影機的 ARRI Alexa709 模擬:

  • 位置:luts/a7s3-arri-g8/A7s3 Phntm Arri LUTs G8/65x/SLog3/Neutral A7s3_65x.cube
  • 變體:Neutral、IceBlue、Jamaica、Tungsten、Utopia(標準版和 Legacy 版)
  • 後期使用 65x,機內/監看使用 33x
  • 專為 S-Log3 + S-Gamut3.Cine 設計;對於 S-Gamut3 素材請啟用 Cine 補償切換開關

Resolve 設定: Colour Science = DaVinci YRGB,Timeline = Rec.709-A (Mac),3D LUT interpolation = Tetrahedral

節點順序 (DaVinci Resolve)

專業序列節點鏈:

  1. 轉換 LUT (攝影機 Log → Rec.709)
  2. 對比度 / 曝光度
  3. 白平衡 / 色溫
  4. 膚色校正
  5. 色彩飽和度
  6. 黑階
  7. (降噪 — 無法透過 LUT 實現)
  8. (暗角 — 無法透過 LUT 實現)
  9. (銳利化 — 無法透過 LUT 實現)

套用 LUT

DaVinci Resolve: 為每個 LUT 新增一個序列節點。在節點上按右鍵 → LUT → 瀏覽至 .cube 檔案。

Adobe Premiere Pro: Lumetri Color → Creative → Look 下拉選單 → 瀏覽至 .cube 檔案。

ffmpeg (批次/預覽):

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

Log 與顯示參考

此儲存庫中的每個 LUT 和每個目標都假設為顯示參考的 Rec.709,套用在攝影機轉換 LUT 之後。如果輸入的是 Log 素材,分析器會看到提升的黑階和平坦的對比度,將其視為缺陷,並針對本應存在的東西進行校正。結果看起來合理,但實際上是錯誤的——這比直接失敗更糟糕——因此每次執行時都會測量並明確陳述這個區別。

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:

訊號Log 看起來像
黑點提升到遠高於零(S-Log3 將黑點設在 0.09 附近)
高光被壓制,沒有任何部分接近 1.0
範圍壓縮在一個窄頻帶內
純度去飽和,轉換前
中點位置中位數在範圍內偏高

三種結果,不是兩種。 一個被嚴重壓平、提升、去飽和的顯示參考調色,從形狀上來說確實與 Log 難以區分,因此有一個明確的 ambiguous(不明確)判定。猜測任何一種方向都會更糟:將其視為 Log 會阻擋一個合法的調色,將其視為顯示參考則會產生一個看似正確但實則錯誤的結果。不明確會詢問您,而您總是能夠回答,但測量永遠無法做到。

中點訊號是可以在任何情況下區分兩者的關鍵:重新縮放顯示參考影像不會改變中位數的相對位置,而 Log 傳輸則會移動它。

針對 Log 或不明確素材的變化。 曝光度和黑階會被保留,因為 0.45 的中位數和 0.02 的黑點描述的是經過調色的影像,而不是 Log 容器。白平衡和膚色色相仍然會執行——色偏就是色偏,皮膚應該顯示為皮膚,無論傳輸曲線為何。--transfer 會覆蓋偵測結果。

閉環調色

與其報告建議讓您手動轉錄,該工具可以透過測量來擬合校正,並提供一個 .cube 檔案來達成目標。選用 --emit 標誌即可啟用閉環模式——在沒有該標誌的情況下,它只會報告,讓您可以查看分析結果而不承諾任何改變。

每次迭代都會將一個候選 LUT 套用到最近的幀,重新掃描,並保留能縮小與理想值差距的調整。這是一種簡單的爬山法——不是神經網路,而是可靠且易於理解的幾何學。

它修正了什麼: 對比度、白平衡、膚色色相、飽和度(適度)、黑階。它沒有修正什麼: 色調分離、偽影、色域限制、超過 1% 區域的特定色相。這些需要人類的判斷力。

技術堆疊

  • Ruby — 生成 LUT(generate_lut.rb、generate_chain_lut.rb、analyze_frame.rb)
  • Python 3 — 分析(auto_grade.py、solve_grade.py、match_grade.py、sample_clip.py、footage_type.py、analyze_region.py)
  • Pandas + NumPy — 向量化色彩操作
  • FFmpeg / FFprobe — 幀提取與編碼
  • Preact + HTM — 瀏覽器預覽 UI

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.

相關技能