davinci-resolve について
davinci-resolveは、DaVinci Resolve Scripting APIを使った自動化スキルです。動画編集者や制作ワークフロー向けに、PythonまたはLuaでプロジェクト、タイムライン、メディア、カラーグレーディング、レンダー、Fusionコンポジションを操作します。
主な機能
- 01プロジェクトとメディアプールの管理
- 02タイムラインの作成と編集
- 03LUTとカラーグレーディングの自動化
- 04レンダージョブの設定と一括実行
- 05Fusionコンポジションのスクリプト操作
- 06タイムラインのインポートとエクスポート
活用シーン
- 01複数プロジェクトのタイムラインを一括レンダー
- 02ビデオトラック上のクリップにLUTを適用
- 03Resolveを制作パイプラインに組み込む
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ terminalskills/ skills --skill davinci-resolveインストール後、Claude Code で/davinci-resolveを入力して読み込まれたか確認します。
同梱ファイル_scores.json
詳細
DaVinci Resolve
概要
カラーグレーディング、Fusion VFX、Fairlight オーディオを内蔵したプロ向け NLE、DaVinci Resolve を自動化します。このスキルでは、プロジェクト、タイムライン、メディアプール、カラーグレード、レンダージョブ、Fusion コンポジションをプログラムで操作するための Resolve Scripting API(Python および Lua)を扱います。バッチワークフローの構築、繰り返し行う編集の自動化、レンダーキューの管理、制作パイプラインへの Resolve の統合が可能です。
手順
ステップ 1:Scripting API のセットアップ
Resolve が起動している必要があります。Workspace > Scripts メニューまたは Console から実行するスクリプトには、セットアップは不要です。ターミナルから起動するスクリプトの場合は、Resolve の Preferences > System > General > 「External scripting using」で(Local)を有効にし、以下の変数を設定してください(値は Blackmagic の README に記載されています)。
# Linux (use /home/resolve instead of /opt/resolve on some ISO installs)
export RESOLVE_SCRIPT_API="/opt/resolve/Developer/Scripting"
export RESOLVE_SCRIPT_LIB="/opt/resolve/libs/Fusion/fusionscript.so"
export PYTHONPATH="$PYTHONPATH:$RESOLVE_SCRIPT_API/Modules/"
# macOS: API=/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting
# LIB=/Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so
# Windows: API=%PROGRAMDATA%\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting
# LIB=C:\Program Files\Blackmagic Design\DaVinci Resolve\fusionscript.dll
import DaVinciResolveScript as dvr
resolve = dvr.scriptapp("Resolve")
pm = resolve.GetProjectManager()
project = pm.GetCurrentProject()
mediaPool = project.GetMediaPool()
timeline = project.GetCurrentTimeline()
~/.local/share/DaVinciResolve/Fusion/Scripts/Utility(Linux。macOS および Windows の場合のパスは README に記載されています)に配置したユーザースクリプトは、Workspace > Scripts に表示されます。Resolve が起動していない場合、または外部スクリプティングが無効の場合、scriptapp は None を返します。Studio 専用の呼び出し(AI 機能の一部)は、無料版では False を返します。
ステップ 2:プロジェクトとメディアプール
# Project management
pm = resolve.GetProjectManager()
pm.CreateProject("New Project") # returns None if the name already exists
project = pm.GetCurrentProject()
project.SetSetting("timelineResolutionWidth", "3840")
project.SetSetting("timelineResolutionHeight", "2160")
project.SetSetting("timelineFrameRate", "24")
# Media Pool — create bins and import
mediaPool = project.GetMediaPool()
rootFolder = mediaPool.GetRootFolder()
dailies_bin = mediaPool.AddSubFolder(rootFolder, "Dailies")
mediaPool.SetCurrentFolder(dailies_bin)
clips = mediaPool.ImportMedia([
"/mnt/footage/harbour/scene01_take01.mov",
"/mnt/footage/harbour/scene01_take02.mov",
])
# Set clip metadata (ImportMedia returns a list of MediaPoolItems)
clip = clips[0]
clip.SetClipProperty("Comments", "Best take")
clip.SetClipColor("Green")
ステップ 3:タイムライン操作
# Create and populate timelines
timeline = mediaPool.CreateEmptyTimeline("Assembly Edit v1") # becomes the current timeline
mediaPool.AppendToTimeline([clips[0], clips[1]])
# or in one call: mediaPool.CreateTimelineFromClips("Assembly Edit v1", clips)
# Append subclip with in/out points
mediaPool.AppendToTimeline([{
"mediaPoolItem": clips[0],
"startFrame": 0,
"endFrame": 120, # First 5 seconds at 24fps
}])
# Inspect timeline
items = timeline.GetItemListInTrack("video", 1)
for item in items:
print(f" Frame {item.GetStart()}-{item.GetEnd()}: {item.GetName()}")
# Markers
timeline.AddMarker(1000, "Blue", "Review Point", "Check color here", 1, "reviewTag") # frameId, color, name, note, duration, customData
markers = timeline.GetMarkers()
ステップ 4:カラーグレーディングの自動化
SetLUT はクリップではなくノードグラフに属し、SetCDL は文字列を受け取ります。ノードインデックスは 1 始まりです。
resolve.OpenPage("color")
items = timeline.GetItemListInTrack("video", 1)
for item in items:
graph = item.GetNodeGraph()
graph.SetLUT(1, "/mnt/luts/FilmLook.cube")
item.SetCDL({
"NodeIndex": "1",
"Slope": "1.1 1.0 0.95",
"Offset": "0.0 0.0 0.02",
"Power": "1.0 1.0 1.05",
"Saturation": "1.1",
})
# Copy the current grade of one clip onto the others
source = items[0]
source.CopyGrades(items[1:])
graph.ApplyGradeFromDRX(path, gradeMode) は、書き出した静止画を適用します(gradeMode 0 = キーフレームなし)。ApplyGradeFromTimelineClip はありません。
ステップ 5:レンダーキューと一括書き出し
最初にプリセットを読み込み、次に設定を上書きしてから、キューに追加します。AddRenderJob() はジョブ ID の文字列を返します。
project.LoadRenderPreset("YouTube - 2160p") # names come from project.GetRenderPresetList()
project.SetRenderSettings({
"SelectAllFrames": True,
"TargetDir": "/mnt/renders/harbour",
"CustomName": "harbour_v1",
"ExportVideo": True,
"ExportAudio": True,
})
job_id = project.AddRenderJob()
# Batch: one job per timeline
job_ids = []
for i in range(1, project.GetTimelineCount() + 1):
tl = project.GetTimelineByIndex(i)
project.SetCurrentTimeline(tl)
project.SetRenderSettings({"TargetDir": f"/mnt/renders/{tl.GetName()}", "CustomName": tl.GetName()})
job_ids.append(project.AddRenderJob())
project.StartRendering(job_ids) # or StartRendering() for the whole queue
import time
while project.IsRenderingInProgress():
for jid in job_ids:
st = project.GetRenderJobStatus(jid)
print(jid, st.get("JobStatus"), st.get("CompletionPercentage"))
time.sleep(5)
その他のキー:MarkIn/MarkOut、FormatWidth、FormatHeight、FrameRate、VideoQuality、AudioCodec、ColorSpaceTag。コーデックとコンテナの取得には、project.GetRenderFormats()、GetRenderCodecs(fmt)、SetCurrentRenderFormatAndCodec(fmt, codec) を使用します。project.RenderWithQuickExport(preset, {"TargetDir": ..., "CustomName": ...}) は、現在のタイムラインに Quick Export プリセットを適用して実行します。
ステップ 6:Fusion スクリプティングと統合
# Add Fusion text overlay to a clip
resolve.OpenPage("fusion")
item = timeline.GetItemListInTrack("video", 1)[0]
fusion_comp = item.GetFusionCompByIndex(1) if item.GetFusionCompCount() else item.AddFusionComp()
text_node = fusion_comp.AddTool("TextPlus", -32768, -32768)
text_node.StyledText = "Episode 1"
text_node.Font = "Arial"
text_node.Size = 0.08
text_node.Center = {"x": 0.5, "y": 0.9}
タイムラインのインポート/エクスポート:
mediaPool.ImportTimelineFromFile("/mnt/edits/harbour_v3.edl", {
"timelineName": "Imported Edit",
"importSourceClips": True,
"sourceClipsPath": "/mnt/footage/harbour/",
})
timeline.Export("/mnt/edits/harbour_v3.fcpxml", resolve.EXPORT_FCPXML_1_10)
timeline.Export("/mnt/edits/harbour_v3.edl", resolve.EXPORT_EDL, resolve.EXPORT_CDL) # EDL and AAF need a subtype
# Types: EXPORT_AAF, EXPORT_DRT, EXPORT_EDL, EXPORT_FCP_7_XML, EXPORT_FCPXML_1_8/1_9/1_10, EXPORT_OTIO, EXPORT_ALE, EXPORT_TEXT_CSV
例
例 1:データベースフォルダー内のすべてのプロジェクトを ProRes 422 HQ で一括レンダリングする
ユーザープロンプト:「現在の Resolve データベースフォルダーにあるすべてのプロジェクトを順番に処理し、各タイムラインを ProRes 422 HQ で /mnt/renders/harbour-doc/assembly-v1/ にレンダリングする Python スクリプトを書いてください(プロジェクト名、その後にタイムライン名)。完了時に概要を表示してください。」
エージェントは、GetProjectListInCurrentFolder() を呼び出し、LoadProject() で各プロジェクトを読み込みながら処理するスクリプトを作成します。各プロジェクトで GetTimelineByIndex() を使ってタイムラインを順番に処理し、LoadRenderPreset(...)(または GetRenderCodecs("mov") から取得したコーデックを指定した SetCurrentRenderFormatAndCodec)と SetRenderSettings を適用します。プロジェクト名とタイムライン名に基づく出力先ディレクトリを設定し、レンダージョブを追加して、AddRenderJob() が返す ID を収集します。その後、StartRendering(job_ids) を呼び出し、ループ内で IsRenderingInProgress() をポーリングして、完了統計を表示します。
例 2:最初のビデオトラックにあるすべてのクリップに LUT とカラーグレードを適用する
ユーザープロンプト:「/home/editor/luts/FilmLook.cube に FilmLook.cube LUT があります。この LUT をビデオトラック 1 のすべてのクリップのノード 1 に適用し、彩度を 1.15 に上げ、少し暖色寄りのオフセットを加える Resolve スクリプトを書いてください。」
エージェントは、resolve.OpenPage("color") で Color ページに切り替え、ビデオトラック 1 のすべてのアイテムを取得する Python スクリプトを作成します。各クリップで item.GetNodeGraph().SetLUT(1, "/home/editor/luts/FilmLook.cube") を使って LUT を適用し、続いて item.SetCDL() に "Saturation": "1.15" と "Offset": "0.01 0.005 0.0"(文字列値)を指定します。
ガイドライン
- DaVinci Resolve を起動しておく必要があります。スクリプトはアクティブなインスタンスに接続するため、Resolve をヘッドレスで起動することはできません。アプリの外部から起動するスクリプトでは、Preferences で外部スクリプティングを Local に設定し、
RESOLVE_SCRIPT_API/RESOLVE_SCRIPT_LIBを設定してください(Step 1)。「Network」はセキュリティリスクとして扱ってください - 変更を加えた後は、作業内容が Resolve やスクリプトのクラッシュで失われないよう、
pm.SaveProject()(ProjectManager のメソッド)を呼び出してください - 設定値は文字列です。例:
project.SetSetting("timelineFrameRate", "24")。CDL 値はスペース区切りの文字列です。返された Bool はすべて確認してください。ほとんどの呼び出しは例外を発生させず、FalseまたはNoneを返します - レンダリングを無期限にブロックするのではなく、
time.sleep()を使ったポーリングループでproject.GetRenderJobStatus()を呼び出し、レンダリングの状態を監視してください - Fusion スクリプティングの座標では、ピクセル値ではなく正規化された値(0.0~1.0)を使います。そのため、
Center = {"x": 0.5, "y": 0.9}は、水平方向に中央揃えで、下部近くに配置することを意味します