Jean Paul Sneider wrote:I haven't really dived into scripting for resolve yet, but having a look into your might be a nice jumpstart to it.
New way to export thumbnails? Idea where I could look into it? (other than the script I am thinking of exporting the edit index... I will check it too.)
Hi,
Here is a python3 script that will export markers to a csv file.
The script will log data and shot name of all timeline markers in any timeline that begins with "$" in its name and will save the files to home/temp folder.
As for the thumbnails options, as mentioned in the documentation:
Returns a dict (keys "width", "height", "format" and "data") with data containing raw thumbnail image data (RGB 8-bit image data encoded in base64 format)
You can use openCV to decode it as shown in one of the examples. This is possible only from the color page.
Very interesting indeed, will need to play around with it more.
You can read about it and of Resolve scripting in the Help menu => Documentation => Developer
code:
- Code: Select all
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, os, time, csv, gspread
from pathlib import Path as path
from tkinter import Tk, filedialog, messagebox
# ///////////////////////////
# ===============
# Utils
# ===============
# ///////////////////////////
def GetResolve():
try:
# The PYTHONPATH needs to be set correctly for this import statement to work.
# An alternative is to import the DaVinciResolveScript by specifying absolute path (see ExceptionHandler logic)
import DaVinciResolveScript as bmd
except ImportError:
if sys.platform.startswith("darwin"):
expectedPath="/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules/"
elif sys.platform.startswith("win") or sys.platform.startswith("cygwin"):
import os
expectedPath=os.getenv('PROGRAMDATA') + "\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting\\Modules\\"
elif sys.platform.startswith("linux"):
expectedPath="/opt/resolve/libs/Fusion/Modules/"
# check if the default path has it...
print("Unable to find module DaVinciResolveScript from $PYTHONPATH - trying default locations")
try:
import imp
bmd = imp.load_source('DaVinciResolveScript', expectedPath+"DaVinciResolveScript.py")
except ImportError:
# No fallbacks ... report error:
print("Unable to find module DaVinciResolveScript - please ensure that the module DaVinciResolveScript is discoverable by python")
print("For a default DaVinci Resolve installation, the module is expected to be located in: "+expectedPath)
sys.exit()
return bmd.scriptapp("Resolve")
def frames2tc (frames, fps):
print(frames)
print(fps)
h = str(int(frames / (fps * 3600)))
m = str(int(frames / (fps * 60)) % 60)
s = str(int((frames % (fps * 60)) /fps))
f = str(int(frames % (fps * 60)) % fps)
return f'{h.zfill(2)}:{m.zfill(2)}:{s.zfill(2)}:{f.zfill(2)}'
def makeCSV(csvfile, dict, fps):
"""checks if csv file exists, deletes it and dump to CSV file"""
csvColumns = ['TC', 'name', 'color', 'note', 'duration', 'Shot']
if os.path.isfile(csvfile):
path(csvfile).unlink()
# log to CSV file
try:
with open(csvfile, 'w', encoding='utf-8') as c:
writer = csv.DictWriter(c, fieldnames=csvColumns)
writer.writeheader()
for key in dict:
writer.writerow(markers[key])
except Exception as ex:
print(ex)
print(f'Loged {csvfile}')
# ///////////////////////////
# ===============
# system config
# ===============
# ///////////////////////////
desDir = path.home() / 'temp'
if not path.exists(desDir):
desDir.mkdir()
os.chdir(desDir)
# //////////////////////////////////////////
# =============
# Resolve
# =============
# //////////////////////////////////////////
print('[*]Working...')
# instancing Resolve object
resolve = GetResolve()
if resolve == None:
print('[!] --ERROR-- Can not get Resolve. Make sure Resolve is running')
sys.exit()
projectManager = resolve.GetProjectManager()
project = projectManager.GetCurrentProject()
fps = round(float(project.GetSetting('timelineFrameRate')))
timelineCount = int(project.GetTimelineCount())
timelinelList = [project.GetTimelineByIndex(float(i)).GetName() for i in range(1,
timelineCount+1) if project.GetTimelineByIndex(float(i)).GetName()[0] == '$']
# For every timeline extract markers and shot name
# save to temp CSV file
for count in range(1, timelineCount+1):
if project.GetTimelineByIndex(count).GetName()[0] == '$':
currentTimeline = project.GetTimelineByIndex(count)
offset = currentTimeline.GetStartFrame()
markers = currentTimeline.GetMarkers()
markerTC = [k for k in markers]
trackCount = int(currentTimeline.GetTrackCount('video'))
shots = {tr : currentTimeline.GetItemsInTrack('video', tr) for tr in\
range(1, trackCount+1) if len(currentTimeline.GetItemsInTrack('video', tr))}
trackNum = sorted([k for k in shots])
csvFileName = currentTimeline.GetName()+'.csv'
# creates an updated markers dictonary with ofsset TC and shots name
for marker in markerTC:
markers[marker]['TC'] = frames2tc(marker+offset, fps)
flag = True
for track in reversed(trackNum):
if flag:
for shot in shots[track]:
shotName = shots[track][shot].GetName()
start = shots[track][shot].GetStart()
end = shots[track][shot].GetEnd()
if (marker + offset) >= start and (marker + offset) < end:
markers[marker]['Shot'] = shotName
flag = False
break
else:
break
# log markers and shots name to CSV file
print(f'Loging markers to {csvFileName} @ {desDir}')
makeCSV(csvFileName, markers, fps)
print('***************************\n DONE!\n***************************')