Open7

DaVinci Resolve Python

h_kishimotoh_kishimoto
> print(dir())
['OrderedDict', '_UIAutoTbl', '_UIDefault', '_UIDispatcher', '_UIWindow',
'__annotations__', '__builtins__', '__doc__', '__loader__', '__name__',
'__package__', '__spec__', '_thisapp', 'app', 'bmd', 'fu', 'fu_stderr',
'fu_stdout', 'fusion', 'importlib', 'pprint', 'res', 'resolve', 'sys', 'threading']

resolve からいろいろ操作する模様

> print(res)
Resolve (0x0x11e461350) [App: 'Resolve' on 127.0.0.1, UUID: 0466009f-a24c-4060-a937-402171fa7768]
> print(resolve)
Resolve (0x0x11e461350) [App: 'Resolve' on 127.0.0.1, UUID: 0466009f-a24c-4060-a937-402171fa7768]

> print(dir(res))
['DeleteLayoutPreset', 'ExportBurnInPreset', 'ExportLayoutPreset', 'ExportRenderPreset', 'Fusion', 'GetCurrentPage', 'GetKeyframeMode', 'GetMediaStorage', 'GetProductName', 'GetProjectManager', 'GetVersion', 'GetVersionString', 'ImportBurnInPreset', 'ImportLayoutPreset', 'ImportRenderPreset', 'LoadLayoutPreset', 'OpenPage', 'Print', 'Quit', 'SaveLayoutPreset', 'SetHighPriority', 'SetKeyframeMode', 'UpdateLayoutPreset']
> print(dir(resolve))
['DeleteLayoutPreset', 'ExportBurnInPreset', 'ExportLayoutPreset', 'ExportRenderPreset', 'Fusion', 'GetCurrentPage', 'GetKeyframeMode', 'GetMediaStorage', 'GetProductName', 'GetProjectManager', 'GetVersion', 'GetVersionString', 'ImportBurnInPreset', 'ImportLayoutPreset', 'ImportRenderPreset', 'LoadLayoutPreset', 'OpenPage', 'Print', 'Quit', 'SaveLayoutPreset', 'SetHighPriority', 'SetKeyframeMode', 'UpdateLayoutPreset']
h_kishimotoh_kishimoto

プロジェクトマネージャーを取得

> projectManager = resolve.GetProjectManager()

プロジェクトを取得

> project = projectManager.GetCurrentProject()

タイムラインを取得

> timeline = project.GetCurrentTimeline()
h_kishimotoh_kishimoto

タイムラインの情報

# タイムラインの名前
timeline.GetName()

# スタートエンド
timeline.GetStartFrame()
timeline.GetEndFrame()

# 設定
> print(timeline.GetSetting())
{'audioCaptureNumChannels': '2',
 'audioOutputHasTimecode': '0',
 'audioPlayoutNumChannels': '2',
 'cloudProjectMediaLocation': '',
 'colorAcesGamutCompressType': 'None',
 'colorAcesIDT': 'No Input Transform',
...
 'videoPlayoutBatchHeadDuration': '8',
 'videoPlayoutBatchTailDuration': '8',
 'videoPlayoutLTCFramesOffset': '0',
 'videoPlayoutMode': 'video_audio',
 'videoPlayoutShowLTC': '0',
 'videoPlayoutShowSourceTimecode': '0'}
h_kishimotoh_kishimoto

トラックに置いているクリップを取得。

timeline.GetItemListInTrack('video',1)

↑トラックのインデックスは0ではなく1から。

clip = timeline.GetItemListInTrack('video',1)[0]
h_kishimotoh_kishimoto

クリップのパスを取りたい時 = メディアプールアイテムを経由する

media_pool_item = clip.GetMediaPoolItem()
media_pool_item.GetClipProperty("File Path")

/path/to/source.mov

GetClipPropertyは何も渡さなければ辞書として全項目返ってくる。

> pprint.pprint(media_pool_item.GetClipProperty())
{'Alpha mode': 'None',
 'Angle': '',
 'Audio Bit Depth': '32',
 'Audio Ch': '2',
 'Audio Codec': 'AAC',
 'Audio Offset': '',
...
 'Transcription Status': '',
 'Type': 'ビデオ + オーディオ',
 'Uploaded From': '',
 'Usage': '2',
 'V-FLIP': 'オフ',
 'Video Codec': 'H.264 High L5.1'}
h_kishimotoh_kishimoto

Scripts 以下に .py を置いて Resolve を起動するとスクリプトメニューから使えるようになる

# win:
%APPDATA%\Blackmagic Design\DaVinci Resolve\Fusion\Scripts\Comp

# mac:
/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Comp/

メニューを足したりできるのはおそらくここだけで、任意にメニューを足したりはできない。
Resolve自体はQt製アプリケーションだが、PySideオブジェクトを取得してメニューを足したりは不可。
そういえばtk-fuisonでもメニューではなくボタンを並べたウィンド王になっていたので、そういうことかと
https://github.com/mikedatsik/tk-fusion

h_kishimotoh_kishimoto

メディアプールに素材を追加

new_file_path = 'path/to/source.mov'

mediaPool = project.GetMediaPool()
new_media_pool_items = mediaPool.ImportMedia([new_file_path])

パスをリストで渡し、新しいメディアプールアイテムもリストで返ってくる