Creating Scripts for DaVinci Resolve

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline

Christoph Schmid

  • Posts: 841
  • Joined: Thu Sep 26, 2019 10:15 am
  • Real Name: Christoph Schmid

Re: Creating Scripts for DaVinci Resolve

PostFri Feb 09, 2024 11:15 pm

Vojta Filipi wrote:The new problem I´m facing now is that I want to place the clip to my playhead (in the same way as pasting by ctrl+v) but the AppendToTimeline is placing the clip behind the latest clip on the timeline instead.


This little script appends clip at playhead position:
Code: Select all
#!/usr/bin/env python

import DaVinciResolveScript
from timecode import Timecode

DR_FRAMERATES = {16: 16, 18: 18, 23: 23.976, 23.976: 23.976, 24: 24, 25: 25,
                 29: 29.97, 29.97: 29.97, 30: 30, 47: 47.952, 47.952: 47.952,
                 48: 48, 50: 50, 59: 59.94, 59.94: 59.94, 60: 60, 72: 72,
                 95: 95.904, 95.904: 95.904, 96: 96, 100: 100, 119: 119.88,
                 119.88: 119.88, 120: 120}

resolve = DaVinciResolveScript.scriptapp('Resolve')
project_manager = resolve.GetProjectManager()
project = project_manager.GetCurrentProject()
current_timeline = project.GetCurrentTimeline()
curr_timeline_fr = current_timeline.GetSetting('timelineFrameRate')
curr_timeline_fr = DR_FRAMERATES.get(float(curr_timeline_fr))
mediapool = project.GetMediaPool()
current_bin = mediapool.GetCurrentFolder()
clips = current_bin.GetClipList()

clipProperty = clips[0].GetClipProperty()
startFrame = int(clipProperty['Start'])
endFrame = int(clipProperty['End'])

tl_curr_tc = Timecode(curr_timeline_fr, current_timeline.GetCurrentTimecode())
recordFrame = int(tl_curr_tc.frame_number)

mediapool.AppendToTimeline([{'mediaPoolItem': clips[0],
                             'startFrame': startFrame,
                             'endFrame': endFrame,
                             'recordFrame': recordFrame}])


The "recordFrame" variable is the playhead position.

You might have to install the python timecode library with:
Code: Select all
pip install timecode

Davinci Resolve Studio 20.0B3 Build 38
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline
User avatar

Vojta Filipi

  • Posts: 73
  • Joined: Wed May 18, 2022 4:24 pm
  • Real Name: Vojtěch Filipi

Re: Creating Scripts for DaVinci Resolve

PostMon Feb 19, 2024 6:30 pm

csx333 wrote:This little script appends clip at playhead position:


Duuude, thank you so much! At the end I was able to do it with this code, but your way seems more robust 8-)

Code: Select all
# Import Scripting modules
import DaVinciResolveScript as dvr_script
import math

# Foundation
resolve = dvr_script.scriptapp("Resolve")
project = resolve.GetProjectManager().GetCurrentProject()
mp = project.GetMediaPool()
folder = mp.GetRootFolder()
clips = folder.GetClipList()

#put your clip ID here:
clip_ID = [1]

# Get clip from medial pool to Timeline
timeline = project.GetCurrentTimeline()
tcode = timeline.GetCurrentTimecode()
dt = tcode.split(":")
hours = int(dt[0])
mins = int(dt[1])
sec = int(dt[2])
frame = int(dt[3])
frameRate = timeline.GetSetting("timelineFrameRate")

sframe = frameRate
if frameRate == 23:
    frameRate = 23.976
    sframe = 24
elif frameRate == 29:
    frameRate = 29.97
    sframe = 30
elif frameRate == 59:
    frameRate = 59.94
    sframe = 60

totalsec = hours * 3600 + mins * 60 + sec + frame / frameRate
playframe = math.floor(sframe * totalsec + 0.5)
mp.AppendToTimeline([{"mediaPoolItem": clip_ID, "startFrame": 0, "recordFrame": playframe}])
print("Clip imported to timeline at playhead!")


Igor Riđanović wrote:That what Append to Timeline does. The same behavior as when used the normal way, outside of the API.

Thanks for the info! Now I finally better understand how it works!
Offline

jjsereday

  • Posts: 45
  • Joined: Thu May 26, 2022 8:58 am
  • Real Name: JJ Sereday

Re: Creating Scripts for DaVinci Resolve

PostFri Apr 05, 2024 3:32 am

cat99_0 wrote:I tested "Grab Stills at Markers.lua" on mac in18.6. It does not work now.
截屏2023-11-04 16.53.34.png


Do you know if this has been fixed? Its not working for me either. :?

Also is there a way to add timecode to the stills?
Offline
User avatar

stuzbot

  • Posts: 13
  • Joined: Sun Dec 10, 2023 11:07 am
  • Real Name: Albert Tatlock

Re: Creating Scripts for DaVinci Resolve

PostSun Apr 07, 2024 11:45 am

Thanks roger.magnusson for posting this thread. It's been really useful to try and get a handle on Lua scripting with Resolve.

I've been trying to come up with what should be a firly simple script:

I've got two cameras that I use for making my YouTube vids; a DJI Osmo Pocket 3 and a DJI Osmo Action 4. What I want to do is find a way to create a Smart Bin for each camera so that, when I import my footage, it's easier to narrow down which bits were shot on which camera.

Unfortunately this info doesn't seem to be available on any of the metadata that Resolve makes available for each clip. So I can't use any of the built-in methods. However, the info is available in the EXIF data for each clip, which I can extract with EXIFtool:

Code: Select all
$: exiftool  <path/to/some/video-file.mp4>

<snip>
Encoder                         : DJI OsmoAction4
<snip>



I did find a Resolve script online, which supposedly syncs EXIF data with Resolve's metadata. But it wouldn't run without erroring on my setup.

Code: Select all
[Clip 14] DJI_20240328150146_0049_D.MP4 [b8ffec70-2475-4654-9e41-cd230df27fb8]
 !! Error fetching metadata
[Clip 15] DJI_20240316150541_0176_D.MP4 [770adcd0-1902-4c09-a2e9-37c8dc428686]
 !! Error fetching metadata
[Clip 16] DJI_20240328150342_0052_D.MP4 [456be53c-2c74-4cb1-afea-0a8aef7a77a5]
 !! Error fetching metadata
...
etc. etc.


Besides which it's a bit overcomplicated for what I want to do. And, out of all the EXIF fields it reads in, "Encoder" isn't among them. So I'd have to hack that in, after I got the thing to run in the first place.

Another option I've thought might work would involve using a Finder attribute, or flag. I've got a vague recollection of seeing something along these lines mentioned somewhere. But can't find it again. If that's an option, I could set up a Smart Folder in the Finder which automatically applied a tag or attribute [based on the EXIF data] to any footage dropped there and then Resolve could read that Finder tag, when I import the footage, and use it as metadata [Sorry. A bit vague on this one, as I only half-remember reading something about it].

Anyway, has anyone any solutions to this? I feel sure I must be missing something obvious here as the available metadata fields Resolve seem to cover everything from what the weather was like to what the cameraman had for breakfast. I can't believe there isn't <something> that can grab the name/model of the camera used.
Last edited by stuzbot on Sun Apr 07, 2024 12:23 pm, edited 1 time in total.
Offline
User avatar

Robert Niessner

  • Posts: 5567
  • Joined: Thu Feb 21, 2013 9:51 am
  • Location: Graz, Austria

Re: Creating Scripts for DaVinci Resolve

PostSun Apr 07, 2024 12:03 pm

There is a tool you can buy for 40 Euros:
https://www.evrapp.cloud/evrexpanse#hero
Saying "Thx for help!" is not a crime.
--------------------------------
Robert Niessner
LAUFBILDkommission
Graz / Austria
--------------------------------
Blackmagic Camera Blog (German):
http://laufbildkommission.wordpress.com

Read the blog in English via Google Translate:
http://tinyurl.com/pjf6a3m
Offline
User avatar

stuzbot

  • Posts: 13
  • Joined: Sun Dec 10, 2023 11:07 am
  • Real Name: Albert Tatlock

Re: Creating Scripts for DaVinci Resolve

PostSun Apr 07, 2024 12:28 pm

Ah. I think I have at least discovered why the script I found wasn't working for me. Yes, folks, in a delicious piece of irony, it's my old friend "hard-wiring" again!

Code: Select all
function setupexiftool(argfilename)
  local cmd = ''
 
  if platform == 'Mac' then
      cmd = 'PATH=/usr/local/bin:/opt/homebrew/bin:$PATH; exiftool -stay_open true -@ "' .. argfilename .. '"'


Since I use MacPorts and not Homebrew, my exiftool is in a different location

Code: Select all
► which exiftool
/opt/local/bin/exiftool


Time to get a-hacking, methinks!
Offline
User avatar

stuzbot

  • Posts: 13
  • Joined: Sun Dec 10, 2023 11:07 am
  • Real Name: Albert Tatlock

Re: Creating Scripts for DaVinci Resolve

PostSun Apr 07, 2024 5:06 pm

A random thought occurs to me: if Resolve isn't reading EXIF data from imported files, then where is it getting its metadata from?

EDIT:

I got the script I mentioned earlier to work, with a bit of tweaking. as I said previously, my DJI cameras store the camera name under the EXIF "Encoder" tag. [HINT: run exiftool with the '-s' flag to see the actual tags your camera is using. Otherwise exiftool will give you the pretty-printed versions].

Antyway, it was a simple matter of changing the line:

```
{ exif = 'Model', check = itm.CheckCamera, combo = itm.ComboCamera},
```

to

```
{ exif = 'Encoder', check = itm.CheckCamera, combo = itm.ComboCamera},
```

and I can now run the modfified script to identify my cameras in Resolve's Metadata panel:

Image

and assign them to individual smart bins, based on that.

I think I'll probably tweak the script a lot more and delete most of it, as it runs really slowly [possibly because it's parsing all the available metadata] and I really only wanted a quick hack to ID which camera each clip was filmed with.
Offline

RaduGh

  • Posts: 1
  • Joined: Thu Apr 11, 2024 9:10 am
  • Real Name: Radu Gheorghe

Re: Creating Scripts for DaVinci Resolve

PostThu Apr 11, 2024 9:21 am

Hi!
I'm new to scripting, no idea if this is even possible. I capture video and audio via decklink card. Job is remote and i wonder if it's possible to write a script to automate the capture, say at a specific time. Something like, at 12:00 o'clock start capture. That's it, nothing else. I tryed something but i'm really not even sure if those methods exists:

import time
from datetime import datetime
import DaVinciResolveScript as dvr_script

# Initialize the Resolve script
resolve = dvr_script.scriptapp("Resolve")
project_manager = resolve.GetProjectManager()
project = project_manager.GetCurrentProject()
media_pool = project.GetMediaPool()

# Define the specific system time for capture (24-hour format)
start_time = "12:30:00"

# Function to start capture
def start_capture():


# Main loop to check the current time and start capture at the defined time
while True:
current_time = datetime.now().strftime("%H:%M:%S")
if current_time == start_time:
start_capture()
break
time.sleep(1) # Sleep for 1 second before checking the time again


So far no luck. For the script above i've put togheter info from forum posts, not sure of anything.
Offline

iclubb

  • Posts: 2
  • Joined: Fri Apr 12, 2024 11:10 am
  • Real Name: Issa Clubb

Re: Export Timeline Markers

PostFri Apr 12, 2024 11:25 am

Hi, first post! This script (Export Timeline Markers) is incredibly useful to me, or would be. As I'm using it now, everything works as advertised, except that text from the subtitle track does not populate the Notes column as it does in the example provided. I've tried it with single frame markers and also markers with a duration covering the duration of a given title. (Assuming the script working as it should, would that be necessary for subtitle text to be included in the Notes column? Or would single frame markers be sufficient?)

I'm on 18.6.6 in the free version - perhaps one of these two variables is the issue? Pretty close to plonking down for Studio and this would almost certainly give me sufficient reason to do so. Thanks.
Offline
User avatar

stuzbot

  • Posts: 13
  • Joined: Sun Dec 10, 2023 11:07 am
  • Real Name: Albert Tatlock

Re: Creating Scripts for DaVinci Resolve

PostFri Apr 12, 2024 4:27 pm

RaduGh wrote:
Code: Select all
current_time = datetime.now().strftime("%H:%M:%S")
if current_time == start_time:


So far no luck. For the script above i've put togheter info from forum posts, not sure of anything.


I'm no coder, just an occasional tinkerer. But, looking at your Python code, it occcurs to me that you're checking whether current_time is exactly equal to start_time in order to trigger your capture event. Since the timer will most likely be using milliseconds internally, I think it would [almost literally] be 1000-1 chance, if not more, that the current_time and start_time would be '==' at the very instant of checking. And, either side of that exact millisecond, the equality test will always fail.

Probably you should rewrite to check whether current_time has exceeded start_time?
Offline
User avatar

Robert Niessner

  • Posts: 5567
  • Joined: Thu Feb 21, 2013 9:51 am
  • Location: Graz, Austria

Re: Creating Scripts for DaVinci Resolve

PostTue Apr 16, 2024 12:00 pm

Resolve 18.5 Beta 1 has now added a few improvements to the scripting API:
• Scripting API support to import and export DRT and DRB files.
• Scripting API support to load data burn presets.
• Scripting API support to get node label.
• Scripting API support to apply ARRI CDL and LUT to a clip.
• Scripting API support for querying and setting clip enabled state.
• Supported containers for selected codecs are now listed in the encode API.

Resolve 18.5 Beta 2 has added those improvements to the scripting API:
• Scripting API support to create subtitles from timeline audio.
• Scripting API support to transcribe source clips.

Resolve 18.5 Beta 3 has added another few improvements to the scripting API:
• Scripting API support to trigger object mask tracking.
• Scripting API support to trigger stabilization.
• Scripting API support to invoke scene cut detection in timelines.
• Scripting API support to enable smart reframe for clips.
• Scripting API support to export current frame as still.
• Scripting API for adding subclips to the media pool.
• Scripting API support to export and import OpenTimelineIO files.
• Scripting API support to render PNG and JPEG image sequences.

Resolve 18.5 Beta 4 has added those improvements to the scripting API:
• Support to add, delete, enable and lock timeline tracks.
• Support to delete and link timeline clips.
• Support to specify target track and record frame to add clips to timeline.
• Support to specify record frame to create timeline from media pool clips.

Resolve 18.6 has added those improvements to the scripting API:
• Scripting API support to import and export render and data burn presets.
• Scripting API support to import stills and list powergrades.
• Scripting API support for per-timeline Resolve Color Management.

Resolve 19 Beta 1 has added a few improvements/support to the scripting API:
• Managing clip color groups.
• Querying timeline and group node graphs for a clip.
• Enumerating tools used in a given node.
• Setting and getting color keyframe mode.
• Exporting clip LUTs.
• Exporting timeline ALE and CDL.
• Importing OpenTimelineIO timelines with custom import options.

Resolve 19 Beta 2 has added a few improvements/support to the scripting API:
• Scripting API support for querying media audio track mapping.
• Scripting API support to query and set speaker detection from project settings.

Resolve 19 Beta 3 has added a few improvements/support to the scripting API:
• Scripting API support to add a timeline track at a given index.

Resolve 19 Beta 4 has added a few improvements/support to the scripting API:
• Scripting API support for getting node stack layers of a timeline item.

Resolve 19 Beta 5 has added a few improvements/support to the scripting API:
• Scripting API support to enable or disable color nodes using a graph object.
• Scripting API support to get and set cloud project media location from project settings.
• Scripting API support to invoke Dolby Vision analysis on a timeline.

Resolve 19 Beta 6 has added a few improvements/support to the scripting API:
• Scripting API support to query for a timeline item’s linked clips.
• Scripting API support to query for a timeline item’s track type and index.
• Improved media pool scripting support for stereoscopic 3D clips.
• Addressed scripting API issue with loading render presets.
• Addressed scripting API issue with elision of long LUT names when querying node tools.
• Addressed an issue where scripting APIs would not honor timeline disabled state.

Resolve 19.01 has added a few improvements/support to the scripting API:
• Scripting API support to query audio mapping for timeline clips.
• Scripting API support to query format for audio tracks.

Resolve 19.02 has added a few improvements/support to the scripting API:
• Scripting API support to get and set per-clip custom metadata.
• Scripting API support to get and set source start and end frames.
• Scripting API support to get and set source start and end timecode.
• Scripting API support to get and set media pool selection.
• Scripting API support to query timeline clip positions at subframe precision.
• Scripting API support to append clips to timelines at subframe offsets.

Resolve 19.03 has added a few improvements/support to the scripting API:
• Scripting APIs to add clips to timeline now support source subframes.

Resolve 19.1 has added a few improvements/support to the scripting API:
• Load cloud projects.
• Query and set mark in and out ranges.
• Auto sync media pool clips using audio waveform or timecode.
• Render options for start frame, timecode and to replace files.
• Ability to delete a render preset.
• Invoke Quick Export renders.
• Reset all grades and nodes from node graph.
• Apply grade from DRX and CDL LUT to layers from the Graph API.
• Create gallery albums.
• Query and set per-node cache modes.
• Query and enable clip cache for Fusion output and color output
• Query media pool entry for a timeline.

Resolve 20 Beta 3 has added a few improvements/support to the scripting API:
• Scripting API support to link full resolution media.
• Scripting API support to replace media pool clip preserving sub clip extents.

Resolve 20 Beta 4 has added a few improvements/support to the scripting API:
• Scripting API support for media pool clip to monitor growing file.
Last edited by Robert Niessner on Tue May 20, 2025 4:29 am, edited 14 times in total.
Saying "Thx for help!" is not a crime.
--------------------------------
Robert Niessner
LAUFBILDkommission
Graz / Austria
--------------------------------
Blackmagic Camera Blog (German):
http://laufbildkommission.wordpress.com

Read the blog in English via Google Translate:
http://tinyurl.com/pjf6a3m
Offline

kayakfishingaddict

  • Posts: 78
  • Joined: Wed Oct 30, 2019 2:29 am
  • Real Name: Ron Jones

Re: Creating Scripts for DaVinci Resolve

PostTue May 21, 2024 6:23 am

Found this thread and love the content. We really could use a DR forum/sub-forum under software development for scripts!

Given that, I decided to hack a bit and fix a bug with DJI OSMO Action 4 timecode when looping. If anyone is interested in code reviewing it I'd appreciate it :).

DJI OSMO Action 4 Serious Timecode Bug Fix -> [download]
Offline
User avatar

Igor Riđanović

  • Posts: 1654
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Creating Scripts for DaVinci Resolve

PostTue May 21, 2024 5:29 pm

Like Roger said, use ":" in Lua to call object methods and "." in Python. For example:

Python:
Code: Select all
timelineitem = timeline.GetCurrentVideoItem()

Lua:
Code: Select all
timelineitem = timeline:GetCurrentVideoItem()


Your AddMarker block would work, but there is a typo in the timelineitem instance. Also, all the values you're passing to the AddMarker() that have dots in them should not follow such syntax. The name, note, customdata are all strings. Duration is an integer, but maybe it will accept a string too. I'm not sure.

And then:
CODE: SELECT ALL
local binClip = timelneItem:GetMediaPoolItem()
binClip:AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)
www.metafide.com - DaVinci Resolve™ Apps
Offline

jjsereday

  • Posts: 45
  • Joined: Thu May 26, 2022 8:58 am
  • Real Name: JJ Sereday

Re: Grab Stills at Markers

PostWed Jun 05, 2024 8:57 pm

roger.magnusson wrote:Image


Is there a way to export stills from markers from the clips themselves? I see theres one to copy timeline markers to media pool clips, but if I already have markers on media pool clips there doesnt seem to be a way to export those markers as stills.

Ideally being able to export markers as stills directly from the media pool clip would be amazing but if its only possible to do within a timeline that is still better than nothing.

Thanks!
Offline

aauurreell26

  • Posts: 6
  • Joined: Thu Jun 06, 2024 8:58 am
  • Real Name: Aurélien Gonnet

Re: Creating Scripts for DaVinci Resolve

PostThu Jun 06, 2024 9:50 am

Hello everyone,

sorry for my poor English, I will use a translator to speak to you :)

I have a question please.

Now that we can send multiple timelines directly to the render queue in Deliver but only in H264 or H265, do you think it is possible to create a script that would modify the queue to switch from H264/265 to the Avid settings in Dnx36?
Offline
User avatar

Uli Plank

  • Posts: 25409
  • Joined: Fri Feb 08, 2013 2:48 am
  • Location: Germany and Indonesia

Re: Creating Scripts for DaVinci Resolve

PostThu Jun 06, 2024 12:36 pm

You can send to the render queue any kind of settings DR offers. Or do I misunderstand your question?
My disaster protection: export a .drp file to a physically separated storage regularly.
www.digitalproduction.com

Studio 19.1.3
MacOS 13.7.4, 2017 iMac, 32 GB, Radeon Pro 580 + eGPU
MacBook M1 Pro, 16 GPU cores, 32 GB RAM, MacOS 14.7.2
SE, USM G3
Offline

aauurreell26

  • Posts: 6
  • Joined: Thu Jun 06, 2024 8:58 am
  • Real Name: Aurélien Gonnet

Re: Creating Scripts for DaVinci Resolve

PostThu Jun 06, 2024 12:47 pm

For some time now, you've been able to send several timelines to deliver at once via edit.

For example, when creating proxies, I need to send a hundred timelines with a particular setting.

Via edit I select the timelines and via a right-click I do timeline -> add to render queue using.

There are only two choices: H264 or H265.

What I'd like to know is, once I've added my 100 timelines to the render queue, can I use a script to modify the export settings?

or find another solution that will allow me to send my 100 timelines for export with the avid dnx settings and all that follows.
Offline
User avatar

Igor Riđanović

  • Posts: 1654
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Creating Scripts for DaVinci Resolve

PostThu Jun 06, 2024 1:51 pm

aauurreell26 wrote:Hello everyone,

sorry for my poor English, I will use a translator to speak to you :)

I have a question please.

Now that we can send multiple timelines directly to the render queue in Deliver but only in H264 or H265, do you think it is possible to create a script that would modify the queue to switch from H264/265 to the Avid settings in Dnx36?
Yes, you can load any existing render preset when making a render job.

Igor Riđanović
www.metafide.com - DaVinci Resolve™ Apps
Offline

aauurreell26

  • Posts: 6
  • Joined: Thu Jun 06, 2024 8:58 am
  • Real Name: Aurélien Gonnet

Re: Creating Scripts for DaVinci Resolve

PostThu Jun 06, 2024 3:38 pm

maybe with a photo I'd be more explicit, sorry again for my English.

Image
Offline

aauurreell26

  • Posts: 6
  • Joined: Thu Jun 06, 2024 8:58 am
  • Real Name: Aurélien Gonnet

Re: Creating Scripts for DaVinci Resolve

PostThu Jun 06, 2024 3:40 pm

it's from the edit tab that you can send several timelines to deliver at the same time. Directly from deliver and one by one, I have no problem with that.
Offline

Christoph Schmid

  • Posts: 841
  • Joined: Thu Sep 26, 2019 10:15 am
  • Real Name: Christoph Schmid

Re: Creating Scripts for DaVinci Resolve

PostFri Jun 07, 2024 9:54 pm

Set your export settings on the Deliver page. Then use the menu with the three dots (...) in the render settings to “Save as new preset...”. Back on the Edit page, the preset will be shown when you add timelines to the render queue.
No script needed.

Davinci Resolve Studio 20.0B3 Build 38
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline

aauurreell26

  • Posts: 6
  • Joined: Thu Jun 06, 2024 8:58 am
  • Real Name: Aurélien Gonnet

Re: Creating Scripts for DaVinci Resolve

PostMon Jun 10, 2024 12:00 pm

Have you ever tried it? My deliver custom settings don't appear in EDIT, I still have H264 and H265 Master.

Then the second thing is that when I create a custom setting, I lose the automatic export of the aaf to my folder.

I could go back to edit and generate the aafs, but then I'd have to do them one by one.

As for the version, I'm on the latest 18.6.6 build 7.
Offline

Christoph Schmid

  • Posts: 841
  • Joined: Thu Sep 26, 2019 10:15 am
  • Real Name: Christoph Schmid

Re: Creating Scripts for DaVinci Resolve

PostMon Jun 10, 2024 2:56 pm

aauurreell26 wrote:Have you ever tried it?

Otherwise I wouldn't have posted it.
And this is covered in the manual on page 4040:
https://documents.blackmagicdesign.com/ ... Manual.pdf
aauurreell26 wrote:My deliver custom settings don't appear in EDIT, I still have H264 and H265 Master.

Then, unfortunately, there is an error in your system...
aauurreell26 wrote:Then the second thing is that when I create a custom setting, I lose the automatic export of the aaf to my folder.

What does that mean ?

Davinci Resolve Studio 20.0B3 Build 38
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline

Kevin.Naben

  • Posts: 70
  • Joined: Wed May 31, 2023 9:32 am
  • Real Name: Kevin Naben

Re: Copy Timeline Clip Markers to Media Pool

PostTue Jul 09, 2024 2:39 pm

This sounds great!
Can it copy timeline markers to the timeline item as well, so I can see them in the source window?
I am creating markers on my timeline on the fly on all my raw footage while cleaning up unused audio tracks.
Then I usually drag my timeline to the source window and edit the marked bits into a new edit timeline (in AVID or Premiere).
But in Resolve I cannot see those timeline markers of a timeline in the source window.
Can this script convert all those timeline markers to "clip" markers on the SAME timeline?
This would be fantastic!

roger.magnusson wrote:Ok, here's the smaller marker transfer script. All it does is copy timeline clip markers to matching media pool clips.

If there are markers on the same frame for both audio and video, the marker on the video clip is used.
If there are multiple instances on the timeline of the same clip with markers on the same frame, the first encountered marker is used.

Image
Image

Known Issues
As mentioned before, the DaVinci Resolve scripting API marker functions do not include keywords, meaning this script will strip any assigned keywords from markers it processes.

Download
Copy Timeline Clip Markers to Media Pool.lua

Follow the instructions for putting a script in the Scripts folder here.
Always using latest stable release of Resolve Studio on the latest MacOS on a MBP M2 Max with 32 GB Ram.
Offline

Kevin.Naben

  • Posts: 70
  • Joined: Wed May 31, 2023 9:32 am
  • Real Name: Kevin Naben

Re: Creating Scripts for DaVinci Resolve

PostWed Jul 10, 2024 2:25 pm

Hmm, would this be the solution to add the markers to the whole timeline clip so I can see the timeline markers when I drag a timeline in the source window?
in which format are the timeline markers saved that can be seen in the source window?

roger.magnusson wrote:The full marker transfer script will have to be put on hold for now. That's a script where timeline markers can be copied/moved to timeline clip markers and media pool clips. Resolve has a bug where a script can't create clip markers in a timeline if the marker ends at the end of the clip. Doing it manually works but it fails when doing the same using a script (TimelineItem.AddMarker()).

A smaller script for updating media pool clip markers from timeline clip markers should still be possible though, unless I find something else along the way.
Always using latest stable release of Resolve Studio on the latest MacOS on a MBP M2 Max with 32 GB Ram.
Offline

Andy Mees

  • Posts: 4044
  • Joined: Wed Aug 22, 2012 7:48 am

Copy Timeline Markers to Media Pool Timeline Clip script

PostWed Jul 10, 2024 5:03 pm

Hey Kevin

I've posted the code for a very basic script to do what you want below... but bear in mind that there's currently no failsafe method to (programmatically) identify the exact media pool item that matches any given timeline object. So, before running the script, use the Timeline menu > Find Current Timeline in Media Pool function to ensure the script finds the right media pool item.

If you're ok with that, save Copy Timeline Markers to Timeline Clip.lua to your Scripts folder and enjoy.

For reference, the script simply looks in the 'current' bin (hence use 'Find Current Timeline in Media Pool' beforehand) and finds the media pool item with type 'Timeline' that has the same name as the current timeline. Then, for each of the current timeline's markers, the script adds a 'clip' marker to the identified media pool item.

Note 1: if any clip marker already exists at any of the timeline marker offsets, that original clip marker is preserved.

Note 2: type 'Timeline' is a language specific variable, so if you're not using an English language installation of Resolve then you'll need to replace the term 'Timeline' with the localised variable for your language.

Cheers
Andy

Code: Select all
local function GetMatchingMediaPoolItem(tl)
    -- Get media pool item list for current bin
    items = project:GetMediaPool():GetCurrentFolder():GetClipList()
    -- iterate through list
    for item = 1, #items, 1 do
        -- find matching media pool item
        if tl:GetName() == items[item]:GetName()
            and items[item]:GetClipProperty()['Type'] == 'Timeline' then
            -- return the matching media pool item
            return items[item]
        end
    end
    -- if not found, exit the script
    os.exit()
end

resolve = Resolve()
project = resolve:GetProjectManager():GetCurrentProject()

if not project then
    print("No project is loaded")
    os.exit()
end

timeline = project:GetCurrentTimeline()

if not timeline then
    print("No timeline is active")
    os.exit()
end

-- Get first matching media pool item in current bin
mediapoolTimeline = GetMatchingMediaPoolItem(timeline)

-- Get timeline markers from the active timeline
timelineMarkers = timeline:GetMarkers()

-- Add those markers to the matching media pool item
for marker_offset, marker in pairs(timelineMarkers) do
    mediapoolTimeline:AddMarker(marker_offset, marker.color, marker.name, marker.note, marker.duration, marker.customData)
end
Offline

Kevin.Naben

  • Posts: 70
  • Joined: Wed May 31, 2023 9:32 am
  • Real Name: Kevin Naben

Re: Creating Scripts for DaVinci Resolve

PostThu Jul 11, 2024 3:38 pm

Fantastic!! :) Thanks a lot Andy!
Always using latest stable release of Resolve Studio on the latest MacOS on a MBP M2 Max with 32 GB Ram.
Offline

Kevin.Naben

  • Posts: 70
  • Joined: Wed May 31, 2023 9:32 am
  • Real Name: Kevin Naben

Re: Creating Scripts for DaVinci Resolve

PostThu Jul 11, 2024 3:54 pm

Andy you nailed it! :) Thats EXACTLY what I was looking for and the perfect workaround for the resolve flaws I am experiencing! THANKS A LOT! Now I dont have to switch NLEs again! :)
Always using latest stable release of Resolve Studio on the latest MacOS on a MBP M2 Max with 32 GB Ram.
Offline

Dani Urdiales

  • Posts: 25
  • Joined: Mon Jan 13, 2020 6:57 pm
  • Real Name: Dani Urdiales

Re: Creating Scripts for DaVinci Resolve

PostThu Jul 11, 2024 7:38 pm

roger.magnusson wrote:Here's a small script for batch changing the color of timeline markers. You can change a selected color or any color into a specific color, random colors or cycle through all colors.Image
Known Issues
Unfortunately, the DaVinci Resolve scripting API marker functions do not include keywords, meaning this script will strip any assigned keywords from markers it processes.

When you add a marker using a script, Resolve will automatically switch to the Edit page, unless you're on the Color page. However, if you're on the Color page the markers won't be redrawn until the user clicks the Color page timeline. As a workaround I'm forcing a switch to the Edit page and then switch back to the original page.

Not related to scripting, but I noticed that Resolve 18.1.2 can't undo any changes you make to markers on the Color page. To undo you have to switch to another page and undo there instead.

Download
Change Timeline Marker Colors.lua

Follow the instructions for putting a script in the Scripts folder here.
Hello Roger, I have one question: how did you get to know the existence of setting 'useCustomSettings'? In the current version,
timeline.GetSettings() output dict, it is not present and It's pretty crucial setting to change timeline settings. Now Im in doubt if there are more hidden settings that I'm not aware of.
Thanks

Enviado desde mi Mi 9 Lite mediante Tapatalk
Offline

JBreckeen

  • Posts: 2
  • Joined: Wed Mar 15, 2023 11:58 am
  • Real Name: Joshua Breckeen

Python API SetCurrentDatabase()

PostTue Jul 16, 2024 1:30 pm

Hello all.

I have made some scripts into a plugin to Prism2 that saves "shortcuts" to the Resolve project into the pipeline. This will directly open the project in Resolve from the pipeline (or desktop) instead of having to find it in Resolve's Project Manager.

It saves the project "path" from Resolve (example):
projectPath = "db_cXXXXXXXXXXXXf\Testing\Sub 1\Sub 2\ShortCutTests"

(X's for security.)

I can get the current database correctly and this works to create the "path".

(cloud example):
' {'DbType': 'PostgreSQL', 'DbName': 'db_c0a56XXXXXXXXXXX5a4be99f', 'IpAddress': 'postgres-jXXXXXd.cXXXXXXXX5.us-east-2.rds.amazonaws.com'}

(local example):
{'DbType': 'Disk', 'DbName': 'XXXXXXXXXXXX'}

But it seems I cannot use SetCurrentDatabase() to switch from a local database to a cloud database. It throws no errors in python, or the python console, but just does not switch.

Has anyone else seen this?

Thanks in advance.

JRB.
Offline

Dani Urdiales

  • Posts: 25
  • Joined: Mon Jan 13, 2020 6:57 pm
  • Real Name: Dani Urdiales

Re: Creating Scripts for DaVinci Resolve

PostSun Jul 21, 2024 8:06 pm

Hello, I've just shared my first UI script in this post:

https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=205241

Hope you find it useful.

Thank your @roger.magnusson as your scripts let me learn how to use the UIManager.
Offline
User avatar

cat99_0

  • Posts: 133
  • Joined: Sun Feb 12, 2023 6:25 pm
  • Real Name: Danniel Ni

Re: Creating Scripts for DaVinci Resolve

PostSat Nov 02, 2024 5:18 am

I tried "grab stills at markers" today. It doesn't work in my DR19 mac version.
Offline

algernonex

  • Posts: 1
  • Joined: Fri Nov 08, 2024 9:46 pm
  • Real Name: Yugene Kokoshko

Re: Creating Scripts for DaVinci Resolve

PostFri Nov 08, 2024 9:48 pm

Hello.
I have one clip and n specific time positions where I want to apply some fusion effect (let it be blurring transitions).
intuitively I'd like to create n adjustment layers and put them to the specified positions and then for each just to create fusion composition and create needed effect.
The problem arises from the start cause I cannot create (at least I haven't found something in official API) adjustment layer.

Could you please give some advice on the subject?
Thanks in advance.
Offline

Andy Mees

  • Posts: 4044
  • Joined: Wed Aug 22, 2012 7:48 am

Re: Copy Timeline Markers to Media Pool Timeline Clip script

PostTue Nov 12, 2024 8:52 am

Andy Mees wrote: bear in mind that there's currently no failsafe method to (programmatically) identify the exact media pool item that matches any given timeline object.
Looks like this functionality may have been added to the Scripting API, in 19.1:

• Query media pool entry for a timeline.
Offline

AndrewHallNZ

  • Posts: 73
  • Joined: Sat Jun 25, 2022 9:05 pm
  • Real Name: Andrew Hall

Re: Creating Scripts for DaVinci Resolve

PostMon Dec 09, 2024 4:56 am

I have been wondering if this can be done with scripting:

My Sony video files come with an associated XMP file which contains metadata including the lens used. I would love to be able to read the xmp files in my media pool bin and have the lens data added to the metadata in Resolve (such that the xmp can then be deleted).

Any thoughts?

I do have some experience with scripting though nothing recent (mostly javascript for Photoshop) and have not worked with Lua though I could possibly pick things up reasonably well.

Cheers Andrew
Intel i9 12900F; Z690M DDR5 Desktop Motherboard; 64GB DDR5-4800; RTX3080 12GB GDDR6; Windows 11, Resolve Studio 19.1.1
https://www.youtube.com/@NewZealandBirdsNature
Offline

Shrinivas Ramani

Blackmagic Design

  • Posts: 3080
  • Joined: Wed Sep 20, 2017 10:19 am

Re: Creating Scripts for DaVinci Resolve

PostMon Dec 09, 2024 7:49 am

For metadata mapping workflows, a general recommendation would be to:
a. take a representative clip in Resolve, and based on metadata source, add the entries manually into he metadata panel in the media page.

b. from the Resolve console or from an external script, invoke "mediapoolItem.GetMetadata()" without inputs to get a list of all relevant metadata keys, as well as a representation of the entered values (including type).

c. use the keys and values from this query as a representative basis for inputs to your "mediapoolItem.SetMetadata(k, v) or "mediapoolItem.SetMetadata({k:v})" calls.
Offline
User avatar

renzhezhu

  • Posts: 240
  • Joined: Fri May 27, 2022 9:04 am
  • Location: USA
  • Real Name: Kuang Zhaohui

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 06, 2025 7:00 am

Hi, I can"t use the " Grab Stills at Markers " script, when I put it in control panal, it say "[string
"???"]:293:attempt to redefine "AVTimecodeFlag"".
CPU: i7-12700 14900K 13900kf Gold5218 M1pro M1 M2U M3pro M4Ultra
GPU: 5080 4090 4090D 4080S 6600XT 3080ti 3060.......
Memory: 64GB DDR4 3200HZ(no xmp)
SSD: RC20 1TB C2000pro 2TB HDD4TB
Resolve Version: 19.1.4 20.0 18.5 18.6.6 19.1
Offline

rbn_vda

  • Posts: 3
  • Joined: Wed May 31, 2023 1:02 pm
  • Real Name: Robin Van den Acker

Re: Creating Scripts for DaVinci Resolve

PostMon Feb 24, 2025 1:42 pm

Hello,

Does anyone know if it is possible to enable or disable timelines from the API? I am talking about the function in this screenshot.

Image

Best
Offline
User avatar

Mel Matsuoka

  • Posts: 1407
  • Joined: Wed Aug 22, 2012 9:54 am
  • Location: Buffalo, NY

Re: Grab Stills at Markers

PostWed Feb 26, 2025 5:59 pm

Thanks so much for the GrabStillsAtMarkers script, Roger! One question though, can you tweak it so that the exported files are all named using the name of the Label for each gallery still?

I've set my "Automatically label gallery still using..." setting to Timeline timecode, and was hoping I could have each exported still contain their respective label name, so that the files will sort in chronological order, particularly when uploaded to Frame.io, which very annoyingly doesn't sort the stills in proper order if the files are using the default `StillID` numbers at the end of the filenames:

Image

If each file could simply take the Label name given to each still (e.g. Timeline timecode), it would sort in a more predictable way:

Image
Blog: https://PostProductive.tv
YouTube: https://www.youtube.com/@postproductive
Offline
User avatar

Vojta Filipi

  • Posts: 73
  • Joined: Wed May 18, 2022 4:24 pm
  • Real Name: Vojtěch Filipi

Re: Creating Scripts for DaVinci Resolve

PostMon Mar 24, 2025 12:48 am

Christoph Schmid wrote:
Vojta Filipi wrote:The new problem I´m facing now is that I want to place the clip to my playhead (in the same way as pasting by ctrl+v) but the AppendToTimeline is placing the clip behind the latest clip on the timeline instead.


This little script appends clip at playhead position:
Code: Select all
#!/usr/bin/env python

import DaVinciResolveScript
from timecode import Timecode

DR_FRAMERATES = {16: 16, 18: 18, 23: 23.976, 23.976: 23.976, 24: 24, 25: 25,
                 29: 29.97, 29.97: 29.97, 30: 30, 47: 47.952, 47.952: 47.952,
                 48: 48, 50: 50, 59: 59.94, 59.94: 59.94, 60: 60, 72: 72,
                 95: 95.904, 95.904: 95.904, 96: 96, 100: 100, 119: 119.88,
                 119.88: 119.88, 120: 120}

resolve = DaVinciResolveScript.scriptapp('Resolve')
project_manager = resolve.GetProjectManager()
project = project_manager.GetCurrentProject()
current_timeline = project.GetCurrentTimeline()
curr_timeline_fr = current_timeline.GetSetting('timelineFrameRate')
curr_timeline_fr = DR_FRAMERATES.get(float(curr_timeline_fr))
mediapool = project.GetMediaPool()
current_bin = mediapool.GetCurrentFolder()
clips = current_bin.GetClipList()

clipProperty = clips[0].GetClipProperty()
startFrame = int(clipProperty['Start'])
endFrame = int(clipProperty['End'])

tl_curr_tc = Timecode(curr_timeline_fr, current_timeline.GetCurrentTimecode())
recordFrame = int(tl_curr_tc.frame_number)

mediapool.AppendToTimeline([{'mediaPoolItem': clips[0],
                             'startFrame': startFrame,
                             'endFrame': endFrame,
                             'recordFrame': recordFrame}])


The "recordFrame" variable is the playhead position.

You might have to install the python timecode library with:
Code: Select all
pip install timecode


Ok I found out, that this version for some reason works only for video clips, not for audio and Adjustment clips

I get these errors:
Code: Select all
Exception in thread Thread-2 (process):
Traceback (most recent call last):
  File "C:\Users\javoj\AppData\Local\Programs\Python\Python313\Lib\threading.py", line 1041, in _bootstrap_inner
    self.run()
    ~~~~~~~~^^
  File "C:\Users\javoj\AppData\Local\Programs\Python\Python313\Lib\threading.py", line 992, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\javoj\AppData\Local\Programs\Python\Python313\Lib\site-packages\keyboard\_generic.py", line 58, in process
    if self.pre_process_event(event):
       ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "C:\Users\javoj\AppData\Local\Programs\Python\Python313\Lib\site-packages\keyboard\__init__.py", line 218, in pre_process_event
    callback(event)
    ~~~~~~~~^^^^^^^
  File "C:\Users\javoj\AppData\Local\Programs\Python\Python313\Lib\site-packages\keyboard\__init__.py", line 649, in <lambda>
    handler = lambda e: (event_type == KEY_DOWN and e.event_type == KEY_UP and e.scan_code in _logically_pressed_keys) or (event_type == e.event_type and callback())
                                                                                                 
                                                        ~~~~~~~~^^
  File "f:\knihovny\dokumenty\1\Creative\Programy\Programovani\mp2Playhead\mp2Playhead.py", line 27, in mp2timeline
    clip = clips[int(clip_id)]
           ~~~~~^^^^^^^^^^^^^^
IndexError: list index out of range


This version that I have used before worked for every type of clip:
Code: Select all
# Import Scripting modules
import DaVinciResolveScript as dvr_script
import math

# Foundation
resolve = dvr_script.scriptapp("Resolve")
project = resolve.GetProjectManager().GetCurrentProject()
mp = project.GetMediaPool()
folder = mp.GetRootFolder()
clips = folder.GetClipList()

#put your clip ID here:
clip_ID = [1]

# Get clip from medial pool to Timeline
timeline = project.GetCurrentTimeline()
tcode = timeline.GetCurrentTimecode()
dt = tcode.split(":")
hours = int(dt[0])
mins = int(dt[1])
sec = int(dt[2])
frame = int(dt[3])
frameRate = timeline.GetSetting("timelineFrameRate")

sframe = frameRate
if frameRate == 23:
    frameRate = 23.976
    sframe = 24
elif frameRate == 29:
    frameRate = 29.97
    sframe = 30
elif frameRate == 59:
    frameRate = 59.94
    sframe = 60

totalsec = hours * 3600 + mins * 60 + sec + frame / frameRate
playframe = math.floor(sframe * totalsec + 0.5)
mp.AppendToTimeline([{"mediaPoolItem": clip_ID, "startFrame": 0, "recordFrame": playframe}])
print("Clip imported to timeline at playhead!")
Offline

Christoph Schmid

  • Posts: 841
  • Joined: Thu Sep 26, 2019 10:15 am
  • Real Name: Christoph Schmid

Re: Creating Scripts for DaVinci Resolve

PostMon Mar 24, 2025 9:15 am

The error message you are showing has nothing to do with the example script I provided.
My script does not use the keyboard library or the variable "clip_id", which is out of range in your case.
Without seeing the actual script that is producing these errors, it is hard to help.

Davinci Resolve Studio 20.0B3 Build 38
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline

Christoph Schmid

  • Posts: 841
  • Joined: Thu Sep 26, 2019 10:15 am
  • Real Name: Christoph Schmid

Re: Creating Scripts for DaVinci Resolve

PostMon Mar 24, 2025 10:50 am

The problem with audio-only and adjustment clips is that the clip properties “Start” and “End” are empty.
I have only included them in the sample code for the sake of completeness.
You can leave them out. Then the script will also work with audio-only and adjustment clips.
Code: Select all
# clipProperty = clips[0].GetClipProperty()
# startFrame = int(clipProperty['Start'])
# endFrame = int(clipProperty['End'])

tl_curr_tc = Timecode(curr_timeline_fr, current_timeline.GetCurrentTimecode())
recordFrame = int(tl_curr_tc.frame_number)

mediapool.AppendToTimeline([{'mediaPoolItem': clips[0],
                             # 'startFrame': startFrame,
                             # 'endFrame': endFrame,
                             'recordFrame': recordFrame}])

Davinci Resolve Studio 20.0B3 Build 38
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline
User avatar

Hans Barbé

  • Posts: 7
  • Joined: Mon May 26, 2014 9:09 pm
  • Location: Belgium

Re: Copy Timeline Clip Markers to Media Pool

PostSat Mar 29, 2025 2:49 am

roger.magnusson wrote:Ok, here's the smaller marker transfer script. All it does is copy timeline clip markers to matching media pool clips.

Download
Copy Timeline Clip Markers to Media Pool.lua

Follow the instructions for putting a script in the Scripts folder here.


Still works fine in Resolve 19 :)
Thank you very much!
___________________
Hans Barbe
MediaMagneet - Belgium
Offline
User avatar

Vojta Filipi

  • Posts: 73
  • Joined: Wed May 18, 2022 4:24 pm
  • Real Name: Vojtěch Filipi

Re: Creating Scripts for DaVinci Resolve

PostSun Mar 30, 2025 12:12 am

Christoph Schmid wrote:The problem with audio-only and adjustment clips is that the clip properties “Start” and “End” are empty.
I have only included them in the sample code for the sake of completeness.
You can leave them out. Then the script will also work with audio-only and adjustment clips.
Code: Select all
# clipProperty = clips[0].GetClipProperty()
# startFrame = int(clipProperty['Start'])
# endFrame = int(clipProperty['End'])

tl_curr_tc = Timecode(curr_timeline_fr, current_timeline.GetCurrentTimecode())
recordFrame = int(tl_curr_tc.frame_number)

mediapool.AppendToTimeline([{'mediaPoolItem': clips[0],
                             # 'startFrame': startFrame,
                             # 'endFrame': endFrame,
                             'recordFrame': recordFrame}])


Oh, I see! Thank you so much for being helpful!
Offline

agrave

  • Posts: 4
  • Joined: Mon Jun 06, 2022 9:16 pm
  • Real Name: Alex Gravenstein

Re: Creating Scripts for DaVinci Resolve

PostTue Apr 15, 2025 3:57 pm

Just wanted to say thank you for all your hard work --- this has saved me hours if not more form coding research and internet digging. Thank you!!!
Previous

Return to DaVinci Resolve

Who is online

Users browsing this forum: Bing [Bot] and 166 guests