Creating Scripts for DaVinci Resolve

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

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Creating Scripts for DaVinci Resolve

PostThu Feb 02, 2023 12:43 am

Scripting is a great feature in DaVinci Resolve. With the exception of a few brave souls that have shared their scripts the forum isn't exactly overflowing with them so I thought I'd make a few contributions on the subject. These will mostly have some kind of GUI and are meant to be run from the Workspace > Scripts menu but where appropriate I will also provide bare-bones snippets that can be pasted directly to the console.

To put a script in the Scripts menu, place the script file here:

macOS
In Finder, press Shift+Command+G to open "Go to Folder" and paste the path to open it.
Current user: ~/Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Utility
All users: /Library/Application Support/Blackmagic Design/DaVinci Resolve/Fusion/Scripts/Utility

Windows
In File Explorer, paste the path in the address bar to open it.
Current user: %AppData%\Blackmagic Design\DaVinci Resolve\Support\Fusion\Scripts\Utility
All users: %ProgramData%\Blackmagic Design\DaVinci Resolve\Fusion\Scripts\Utility

Linux
Current user: ~/.local/share/DaVinciResolve/Fusion/Scripts/Utility
All users: /opt/resolve/Fusion/Scripts/Utility (or /home/resolve/Fusion/Scripts/Utility)

I have listed the "Utility" folder here which makes a script accessible in the root of the Scripts menu on all pages. You can also put the file in one of the page-specific subfolders to the Scripts folder. I have noticed on Windows it sometimes takes a while for the menu to update. Restart Resolve if you're impatient.

The scripts I make are for both the free and paid versions of DaVinci Resolve on macOS, Windows and Linux unless otherwise specified.

Downloads
These are direct links to all the scripts I have posted in this thread (forum post + download). They all use the MIT license, specified in each file.
2023-04-28 - Updated "Set Timecode for Media Pool Clips" to v1.1. It can now set timecode from the "Date Created" metadata field.

2023-02-14 - Tweaked the GUI layout for all the scripts, added a fix for 119.88fps drop frame.

Make your own?
You don't have to be a programmer to run the scripts I post here but if you would like to learn more you can find the Blackmagic Design scripting documentation for the DaVinci Resolve API here:
Help > Documentation > Developer

You'll find readme.txt in the Scripting folder. There's also relevant information for scripts in the Workflow Integrations folder, where the readme covers how to create GUIs for scripts under the UIManager Introduction header. For more information, check out the Building GUIs With Fusion's UI Manager thread and my own script, Class Browser.

I will be using the Lua programming language (Fusion/Resolve uses LuaJIT, a Just-In-Time compiler for Lua) because it's built into Resolve and works in both the Studio and free versions on all platforms.

Other links of interest
- Undocumented Resolve API functions
- The Lua 5.1 Reference Manual
- LuaJIT and specifically the LuaJIT Extensions
Last edited by roger.magnusson on Fri Apr 28, 2023 12:56 pm, edited 18 times in total.
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Timelines with Custom Settings

PostThu Feb 02, 2023 12:43 am

We'll start with something very simple. If you've ever used the ability to have custom timeline settings per timeline, you have no doubt wondered which of all the timelines in a project have custom settings. It might not be obvious just by looking at a list view in the Media Pool.

This little snippet will print out a list of the timelines that have the "Use Project Settings" checkbox unchecked.

To open the console, go to:
Workspace > Console

Paste the following into the entry field at the bottom of the console window and press enter.
Code: Select all
local project = assert(resolve:GetProjectManager():GetCurrentProject(), "Couldn't get current project")
print()
print("Timelines with custom settings")
print("------------------------------")

for i = 1, project:GetTimelineCount() do
   local timeline = project:GetTimelineByIndex(i)

   if timeline:GetSetting("useCustomSettings") == "1" then
      print(timeline:GetName())
   end
end

Simple and useful. It loops through all the timelines in the project and checks if the "useCustomSettings" setting is activated. If it is, the timeline name is printed to the console. Of course, if there are no timelines with custom settings, no timeline names will be printed.

Lets spruce it up a bit with a GUI. In the complete script linked below there are two functions, main() and create_window().

The main() function basically does what we did in the snippet, it loops through all the timelines and adds them as a list of items to one of the GUI controls. It also shows and hides the window and if the user has double clicked a timeline in the list, it's set as the current timeline in Resolve.

The create_window() function defines the look of the window and how it should respond to events. An event is usually triggered by something the user does, like clicking a button. The window has three controls, a Tree, a Label and a Button.
Image
Download
Timelines with Custom Settings.lua

Follow the instructions for putting a script in the Scripts folder here.
Last edited by roger.magnusson on Thu Mar 16, 2023 4:08 pm, edited 3 times in total.
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Libavutil

PostThu Feb 02, 2023 12:44 am

One of the hurdles to overcome when using the DaVinci Resolve scripting API is that sooner or later you will have to convert timecode to frames and frames to timecode. That gets a bit tricky if you also need to use drop frame timecode. I usually use my homegrown algorithms for this but since Resolve comes with some interesting open source libraries I figured we can use those instead and at the same time learn how to invoke external functions directly from a Lua script. It won't make the scripts smaller, but cooler. ;-)

Specifically we will be using libavutil, part of the libav fork of FFmpeg.

LuaJIT allows calling external C functions using the FFI library. It involves declaring the C functions you want to use with the ffi.cdef function.

When working with Lua code I find it really helps to have an editor that can fold/outline parts of the code, like functions and Lua tables. On Windows I use Visual Studio 2022, the community version is free. On macOS I usually use Sublime Text, but Visual Studio Code is nice too.

Now, there's a pretty serious issue in DaVinci Resolve where timeline frame rates can be reported in the API as integers even though you have a timeline with a fractional frame rate. This seems to happen when the operating system regional setting is set to a region that uses another decimal separator, so 23.976 becomes 23. The script below compensates for this issue. I should note that I haven't tested whether this is still an issue in DaVinci Resolve Studio 18.1 but it's been there since the beginning so I expect we will live with it for a while.

The libavutil library defines frame rates as fractions, or rational numbers, in order to avoid rounding errors. The script abstracts all of this, so you'll only be using straightforward functions that are suitable for use with Resolve.

The luaresolve table in the script contains two functions for timecode conversion:
  • frame_from_timecode(string timecode, number frame_rate)
  • timecode_from_frame(number frame, number frame_rate [, boolean drop_frame])
Code: Select all
Example:
    print(luaresolve:frame_from_timecode("01:00:00;00", 29.97))
    print(luaresolve:frame_from_timecode("01:00:00:00", 25))
    print(luaresolve:timecode_from_frame(107892, 29.97, true))
    print(luaresolve:timecode_from_frame(90000, 25))

This outputs:
    107892
    90000
    01:00:00;00
    01:00:00:00

In the next script we'll put it to good use. Usually you would put functionality like this in a separate file, a module, that's then loaded by your script. But I think for this series of scripts I will make all scripts self-contained so it's easy for everyone to just add a single file to the Scripts folder.

Known Issues
DaVinci Resolve comes with libavutil-56 which doesn't support drop frame for frame rates above 59.94, meaning it will create incorrect timecode for 119.88fps when using drop frame. Keep in mind this will affect all scripts I post in this thread. It's certainly possible to fix it by compensating for the drop frame offset but if you add that you have basically done the hardest part of writing your own timecode functions. If BMD were to upgrade to libavutil-57 or later it would fix the issue. Update: It didn't feel right to release scripts with this issue even though it's probably extremely rare for people to use a 119.88DF timeline. So I have updated all the scripts with a workaround.

Download
Libavutil.lua

Follow the instructions for putting a script in the Scripts folder here.
Last edited by roger.magnusson on Thu Mar 16, 2023 4:08 pm, edited 4 times in total.
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Grab Stills at Markers

PostThu Feb 02, 2023 12:44 am

To grab a still from the current timeline position into the current still album, we use the GrabStill() function. Here's a console snippet that grabs the current frame.
Code: Select all
local project = assert(resolve:GetProjectManager():GetCurrentProject(), "Couldn't get current project")
local timeline = assert(project:GetCurrentTimeline(), "Couldn't get current timeline")
assert(timeline:GrabStill(), "Couldn't grab still")

To also export the still to disk we need to have a reference to the grabbed still, and feed that to the ExportStills() function. Note that you have to change the path in the export_to variable before running this.

Code: Select all
local project = assert(resolve:GetProjectManager():GetCurrentProject(), "Couldn't get current project")
local timeline = assert(project:GetCurrentTimeline(), "Couldn't get current timeline")
local settings =
{
   stills = {},
   export_to = [[d:\Stills]],
   prefix = "",
   format = "jpg"
}

settings.stills[#settings.stills+1] = assert(timeline:GrabStill(), "Couldn't grab still")
local gallery = assert(project:GetGallery(), "Couldn't get the Resolve stills gallery")
local still_album = assert(gallery:GetCurrentStillAlbum(), "Couldn't get the current gallery still album")
assert(still_album:ExportStills(settings.stills, settings.export_to, settings.prefix, settings.format), "An error occurred while exporting stills")

If we want to grab a still somewhere else on the timeline we have to move the playhead to the specific timecode with Timeline:SetCurrentTimecode(). However, we want to grab stills on each marker and Timeline:GetMarkers() returns a table with markers listed by frame. This is where our timecode conversion functions in the previous script come into play.

Features
This full script linked below will grab stills from timeline markers of the color you select or from all markers. The scripts table has some new members, like load_settings() and save_settings(). These demonstrate a way of storing settings in a file. In this example it simply stores a file with the same path and name as the script but with a different file extension.

Clicking the Browse button opens a standard folder selector just like you would expect. The script remembers the selected folder using the new load/save functions.
Image
Known Issues
There's a function, luaresolve.stills.reselect_album(), to workaround an issue in Resolve where you can't export stills if the user has selected the "Timelines" album in the gallery. The workaround simply switches to another album first and then back to the album you want to export from.

Another issue that is common with scripts in Resolve is that there's currently no way to lock the user interface while you're executing Resolve API functions. This means that if you're grabbing stills in a loop, the user might switch to another page in Resolve, or open the Project Settings window. This will make many API functions fail, including GrabStill() and SetCurrentTimecode(). You may have noticed that if we're in a "modal" window the user can't click anything in Resolve, can't we just keep the GUI window open while running the operations? Unfortunately no, most Resolve API functions don't work when a modal window is open.

For user interaction that's no so bad, you can just tell the user not to click anything while the script is running. But it also fails if an automated project backup starts while the script is running.

One way to handle that is by checking the return value of GrabStill() and if it's false, wait for a while and retry. Continue retrying until you've reached your timeout limit, then fail. This strategy isn't implemented in this script, but I'll get to that in a future script.

In my opinion Resolve needs a way to lock the GUI and postpone backups when running scripts, just like it does when rendering files.

Download
Grab Stills at Markers.lua

Follow the instructions for putting a script in the Scripts folder here.
Last edited by roger.magnusson on Thu Mar 16, 2023 4:08 pm, edited 3 times in total.
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Timeline Duration

PostThu Feb 02, 2023 12:45 am

Every now and then someone asks why their rendered files are longer than their timeline. If they haven't missed something after the presumed last clip, the answer is invariably that they have a timeline with a fractional frame rate and they are watching the rendered file in a player or on YouTube where it's showing elapsed time instead of timecode.

Time and timecode won't match exactly in a 23.976 or 29.97 timeline because the base time used for the timecode is still 24fps or 30fps as it has to reference whole frames.

Here's a script that lists both the timecode and time for all timelines in a project. If fractional frame rates are used the time field is shown in yellow to make it very clear it can differ from the timecode.

We also get the playhead position info at the bottom, again with real time. I don't think Resolve has a built-in way to show this so I find it useful.

Time is rounded to the nearest millisecond.

Image
Download
Timeline Duration.lua

Follow the instructions for putting a script in the Scripts folder here.
Last edited by roger.magnusson on Thu Mar 30, 2023 11:23 am, edited 4 times in total.
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 02, 2023 12:47 am

That's it for today. I have some more substantial scripts coming but not making any promises as to when. :)

In the mean time, feel free to chime in and post your scripts!
Offline

Andrew Kolakowski

  • Posts: 9206
  • Joined: Tue Sep 11, 2012 10:20 am
  • Location: Poland

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 02, 2023 1:03 am

You can do the same with Python or there is a difference ?

This should have good math for DF:
http://www.andrewduncan.net/timecodes/

And 1 more:
https://www.davidheidelberger.com/2010/ ... -timecode/
(not sure about accuracy of this one)
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 02, 2023 1:31 am

Python has the same access to the Resolve API, but getting Python to work with Resolve can be tricky depending on if you have installed some custom interpreter. Default installs should be fine now I think.

Lua is built-in so there's nothing to configure, it just works. Of course Python has the edge if you need to integrate with existing custom workflows that are already using Python.
Offline

Andrew Kolakowski

  • Posts: 9206
  • Joined: Tue Sep 11, 2012 10:20 am
  • Location: Poland

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 02, 2023 1:36 am

It would be great if you had easy access to frames from Resolve render engine (some 16bit RGB data).
You get that in Flame.
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Creating Scripts for DaVinci Resolve

PostThu Feb 02, 2023 2:00 am

Yeah, nothing like that is available unfortunately. The best you can do with the script engine is render EXRs to disk but there's no in-memory access to frames in the Color or Delivery stages (except the clip thumbnails on the Color page timeline). Or write some OpenFX plugin or use the encoder plugin architecture they launched with v17. But none of those can be used with the script engine so it's a bit off topic.

You can write a Fuse (https://documents.blackmagicdesign.com/UserManuals/Fusion_Fuse_SDK.pdf) for the Fusion engine though. Overall Fusion is much more scriptable than Resolve.
Offline
User avatar

Igor Riđanović

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

Re: Creating Scripts for DaVinci Resolve

PostFri Feb 03, 2023 12:05 am

Andrew Kolakowski wrote:You can do the same with Python or there is a difference ?

This should have good math for DF:
http://www.andrewduncan.net/timecodes/

And 1 more:
https://www.davidheidelberger.com/2010/ ... -timecode/
(not sure about accuracy of this one)


Here is a Python implementation of the Duncan/Heidelberger DF method I use.
https://github.com/IgorRidanovic/smpte
www.metafide.com - DaVinci Resolve™ Apps
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Change Timeline Marker Colors

PostFri Feb 03, 2023 12:47 am

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.
Last edited by roger.magnusson on Thu Mar 16, 2023 4:09 pm, edited 5 times in total.
Offline
User avatar

Sean Nelson

  • Posts: 758
  • Joined: Sun Feb 07, 2021 9:48 pm
  • Location: Vancouver, Canada
  • Real Name: Sean Nelson

Re: Creating Scripts for DaVinci Resolve

PostFri Feb 03, 2023 3:02 am

I'm an IT guy who believes big time in the power of scripting for automating routine OS tasks. I've been aware that Resolve has a scripting capability but haven't been motivated to go through the learning curve. I think these posts are going to be very useful, thanks so much for taking the time to organize everything and put these posts together. I know these things always take more work than it looks like on the surface, and I really appreciate it.

Thanks!
DR Studio 18.6.4 Build 6, Win10Pro x64 22H2/19045.3570
Asus C246 Pro Motherboard, Xeon E-2278G@3.4GHz, 64GB ECC RAM
GeForce 3060 12GB, "Studio" driver 512.15
OS,Library: 1TB NVMe SSD - Project,Cache: 1TB NVMe SSD
Offline

TiDa

  • Posts: 28
  • Joined: Mon Mar 25, 2013 1:05 pm

Re: Creating Scripts for DaVinci Resolve

PostFri Feb 03, 2023 3:58 pm

@roger.magnusson many thanks for this threat. This gives a nice practical overview of possibilities regarding scripting in DaVinci Resolve. I always wonder if a combination of Resolve scripting and an integrated dispatch of hotkey sequences is somehow possible. In this case, we wouldn't need to wait that BMD does integrate more functions for scripting which might never come.
Offline

Andrew Kolakowski

  • Posts: 9206
  • Joined: Tue Sep 11, 2012 10:20 am
  • Location: Poland

Re: Creating Scripts for DaVinci Resolve

PostFri Feb 03, 2023 4:28 pm

As you are familiar with possibilities I have a question.
Can you write script which at each marker makes a cut, fades audio/video on each side and inserts 2 sec. of black ?
Offline
User avatar

Igor Riđanović

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

Re: Creating Scripts for DaVinci Resolve

PostFri Feb 03, 2023 4:37 pm

Andrew Kolakowski wrote:As you are familiar with possibilities I have a question.
Can you write script which at each marker makes a cut, fades audio/video on each side and inserts 2 sec. of black ?


No, you can't place a cut and transitions into an existing clip on a timeline using the API. You could make a new timeline that has a clip and elements you describe, but it's a little complicated.
www.metafide.com - DaVinci Resolve™ Apps
Offline

Andrew Kolakowski

  • Posts: 9206
  • Joined: Tue Sep 11, 2012 10:20 am
  • Location: Poland

Re: Creating Scripts for DaVinci Resolve

PostFri Feb 03, 2023 4:52 pm

Ok- thought so.
Magic Automa is much better in this case.
Offline

Zodret

  • Posts: 2
  • Joined: Sat Feb 04, 2023 6:15 pm
  • Real Name: Gin Aren

Re: Creating Scripts for DaVinci Resolve

PostSat Feb 04, 2023 9:27 pm

I am facing a problem on how subclips work. My current workflow process involves putting bunch of 1-10mins of clips in length on timeline, then cutting out unnecessary parts and leaving only bunch of clips lasting few seconds. If then I drag those clips to media pool, subclips are created. The problem is that all subclips are in full length of original files containing in and out points. It would be really convenient if only in-out parts would be visible when hovering with a mouse pointer. Then I could see bunch of clips at the same time and only selected parts. This would make editing noticeably faster and more convenient.

Is it possible to do such modification via scripting? Don't know nothing about scripting just tried to use that new fancy chatGPT tool, but the script doesn’t work and shows an error in console:

File "C:\Users\xxx\AppData\Roaming\Blackmagic Design\DaVinci Resolve\Support\Fusion\Scripts\Utility\Individual clips.py", line 1, in <module>
import ResolveScript
ModuleNotFoundError: No module named 'ResolveScript'

Script generated by chatGPT:

Code: Select all
import ResolveScript

def create_individual_clips():
    # Get the current project
    project = ResolveScript.GetCurrentProject()

    # Get the selected clips on the timeline
    clips = project.GetSelectedTimelineClips()

    for clip in clips:
        # Get the in and out points of the clip on the timeline
        clip_in = clip.GetTimelineIn()
        clip_out = clip.GetTimelineOut()

        # Create a new clip with the in and out points of the timeline clip
        new_clip = project.CreateClip(clip.GetMediaClip(), clip_in, clip_out)

        # Create a unique name for the new clip
        clip_name = clip.GetName() + " - Individual Clip"

        # Add the new clip to the project media pool
        project.AddMediaClipToMediaPool(new_clip, clip_name)

create_individual_clips()
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 9:24 am

Dragging a clip from the timeline to the Media Pool doesn't create a subclip, it creates a copy of the entire clip as you've noticed. I have no idea why that is but it's the way Resolve is currently designed.

To create a subclip you have to drag from the Source Viewer. Edits of clips that are already in the timeline can be viewed in the Source Viewer but they can't be dragged from the Source Viewer into the Media Pool.

Here's a video on subclips:


The script created by ChatGPT reads more like a wishlist than a script you can run. It's using methods that we would need but that don't exist, like GetSelectedTimelineClips() and GetTimelineIn().
Offline

TiDa

  • Posts: 28
  • Joined: Mon Mar 25, 2013 1:05 pm

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 11:04 am

To convert clips into subclips, you can follow these steps:
1. Assign a keyboard shortcut to "Create SubClip".
2. In the Edit Page, drag and drop the desired clips into a separate bin.
3. Go to the bin in the Media Pool and sort the clips according to "Type".
4. Select one clip at a time, apply the assigned shortcut, and repeat the process.
5. Finally, delete non-subclips.

To semi-automate this, it would be a hybrid job between a hotkey generator combined with a number of clip detection via GetCurrentFolder() to run it repeatedly...

(I will try that for MacOS as I found a solution to output keystrokes from a Lua Script)
Offline
User avatar

iddos-l

  • Posts: 798
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 2:57 pm

Some great resources here, thanks!

Here is a very simple python script to delete all clip markers in the active timeline.

Code: Select all

import DaVinciResolveScript as bmd

colors = ['Blue', 'Red', 'Green', 'Yellow', 'Pink', 'Sky', 'Mint', 'Lemon',
          'Cyan', 'Purple', 'Fuchsia', 'Rose', 'Lavender', 'Sand', 'Cocoa',
          'Cream']

resolve = bmd.scriptapp('Resolve')
pmanager = resolve.GetProjectManager()
proj = pmanager.GetCurrentProject()
mpool = proj.GetMediaPool()
tl = proj.GetCurrentTimeline()
tNumber = tl.GetTrackCount('Video')
clips = []
for n in range(tNumber + 1):
    if n:
        for clip in tl.GetItemListInTrack('Video', n):
            for color in colors:
                clip.DeleteMarkersByColor(color)
 
Offline
User avatar

iddos-l

  • Posts: 798
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 3:04 pm

roger.magnusson wrote:The script created by ChatGPT reads more like a wishlist than a script you can run. It's using methods that we would need but that don't exist, like GetSelectedTimelineClips() and GetTimelineIn().


Also, chatGPT doesn’t know how to instantiate the resolve object with python.
If you don’t have any knowledge of coding, chatGPT is not a good helper. You need to know how to direct it and to fix its errors. In its current state, the chat will give you wrong answers instead of "I don’t know how"
Offline
User avatar

iddos-l

  • Posts: 798
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 3:18 pm

Here's a link to a python script to import markers from avid:
https://github.com/Iddos-l/resolve_import_avid_markers
Offline

TiDa

  • Posts: 28
  • Joined: Mon Mar 25, 2013 1:05 pm

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 4:09 pm

TiDa wrote:To convert clips into subclips, you can follow these steps:
..........
To semi-automate this, it would be a hybrid job between a hotkey generator combined with a number of clip detection via GetCurrentFolder() to run it repeatedly...

(I will try that for MacOS as I found a solution to output keystrokes from a Lua Script)


Here we are:


And this is the Code:
Code: Select all
-- To convert (by MacOS) clips into subclips, you can follow these steps:
-- 1. Install https://github.com/socsieng/sendkeys
-- 2. Assign the keyboard shortcut "Control+Command+s" to "Create SubClip".
-- 4. In the Edit Page, drag and drop the desired clips into a separate bin.
-- 5. Go to the bin in the Media Pool and sort the clips according to
--    "Clip Name" in descending order.
-- 6. Run this Script.
-- 7. Finally, delete non-subclips.

pm = resolve:GetProjectManager()
cp = pm:GetCurrentProject()
mp = cp:GetMediaPool()
cFolder = mp:GetCurrentFolder()
print(cFolder:GetName())
cItems = cFolder:GetClips()


local sendkeys = "/usr/local/bin/sendkeys --application-name 'Davinci Resolve' -c '"
local shortcuts = "<P:0.03>"
local shortcuts0 = "<c:up>"
for cIndex, key in ipairs(cItems) do
        shortcuts = shortcuts .. shortcuts0
end
local command = sendkeys..shortcuts.."'"
os.execute(command)
print(command)

shortcuts = "<P:0.1>"
shortcuts0 = "<c:s:control,command><c:enter><c:down>"
for cIndex, key in ipairs(cItems) do
    shortcuts = shortcuts .. shortcuts0   
end
command = sendkeys..shortcuts.."'"
os.execute(command)
print(command)
Last edited by TiDa on Sun Feb 05, 2023 4:15 pm, edited 1 time in total.
Offline

Andy Mees

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

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 4:12 pm

Thanks TiDa, have been wondering how to send keystrokes. This is super useful.
Let's have a return to the glory days, when press releases for new versions included text like "...with over 300 new features and improvements that professional editors and colorists have asked for."
Offline

pantau000

  • Posts: 143
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 6:07 pm

iddos-l wrote:Here is a very simple python script to delete all clip markers in the active timeline.


Great, would it be possible to transfer the timeline markers to clip marker for the clips in the media pool?
Offline
User avatar

waltervolpatto

  • Posts: 10498
  • Joined: Thu Feb 07, 2013 5:07 pm
  • Location: 1146 North Las Palmas Ave. Hollywood, California 90038 USA

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 7:23 pm

nice!
W10-19043.1645- Supermicro MB C9X299-PGF - RAM 128GB CPU i9-10980XE 16c 4.3GHz (Oc) Water cooled
Decklink Studio 4K (12.3)
Resolve 18.5.1 / fusion studio 18
GPU 3090ti drivers 512.59 studio
Offline
User avatar

Igor Riđanović

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

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 7:33 pm

pantau000 wrote:
iddos-l wrote:Here is a very simple python script to delete all clip markers in the active timeline.


Great, would it be possible to transfer the timeline markers to clip marker for the clips in the media pool?


Yes, it's possible to apply timeline markers to the bin clips.
www.metafide.com - DaVinci Resolve™ Apps
Offline

Sven H

  • Posts: 846
  • Joined: Mon May 24, 2021 9:11 am
  • Real Name: Sven Hegen

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 7:42 pm

Thanks everyone for contributing. Maybe by doing this officially, we can get Blackmagic Design to allow for even more features to be used with the API.
Offline
User avatar

iddos-l

  • Posts: 798
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 7:48 pm

Igor Riđanović wrote:
pantau000 wrote:
iddos-l wrote:Here is a very simple python script to delete all clip markers in the active timeline.


Great, would it be possible to transfer the timeline markers to clip marker for the clips in the media pool?


Yes, it's possible to apply timeline markers to the bin clips.
Not sure I follow, how can you apply markers to clips in the Media Pool?
Markers are only used in the timeline, clip markers or timeline markers.
What am I missing?
Offline

Andrew Kolakowski

  • Posts: 9206
  • Joined: Tue Sep 11, 2012 10:20 am
  • Location: Poland

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 8:36 pm

Clip markers should be assigned to clip so they travel with clip on the timeline.
Timeline markers are not linked to clip, but to timeline itself, so when you move clip then marker stays in the same place.
This is how other NLEs work- not sure about Resolve, but this 2 types are quite different and have its own usage.
Offline
User avatar

iddos-l

  • Posts: 798
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 8:39 pm

Yes I know that.
I don’t understand how markers are connected to the media pool.
Offline

Andy Mees

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

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 8:49 pm

'Clip Markers' that are marked on a timeline in the Source Viewer are visible in the associated Media Pool item... but 'Timeline Markers' that are marked on a timeline in the Timeline window are not.
Let's have a return to the glory days, when press releases for new versions included text like "...with over 300 new features and improvements that professional editors and colorists have asked for."
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 8:57 pm

But it doesn't go both ways. Markers you add on a clip in the Media page source viewer show up when you add the clip to a timeline. But markers you add on a clip in a timeline don't propagate "back" and won't show on a clip in the Media page.
Last edited by roger.magnusson on Sun Feb 05, 2023 8:58 pm, edited 1 time in total.
Offline
User avatar

iddos-l

  • Posts: 798
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 8:57 pm

Oh ok I understand.
I admit I never added markers in the viewer window.
I don’t know if the API supports this action but if Igor says it is I will take he’s word for it.
Will read the documentation on this topic.
Offline
User avatar

iddos-l

  • Posts: 798
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 8:58 pm

roger.magnusson wrote:But it doesn't go both ways. Markers you add on a clip in the Media page show up when you add the clip to a timeline. But markers you add on a clip in a timeline don't propagate "back" and won't show on a clip in the Media page.
Yes that’s why I didn’t understand before.
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 9:03 pm

Very happy to see people posting their scripts! To make it easier on the user, I suggest adding a note about which OS they've been tested on (I'll add that to my first post as well).
Offline

Andrew Kolakowski

  • Posts: 9206
  • Joined: Tue Sep 11, 2012 10:20 am
  • Location: Poland

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 05, 2023 9:08 pm

roger.magnusson wrote:But it doesn't go both ways. Markers you add on a clip in the Media page source viewer show up when you add the clip to a timeline. But markers you add on a clip in a timeline don't propagate "back" and won't show on a clip in the Media page.


Also- if you have clip used in timeline and add more clip markers then they won't show up in your existing timeline (unless you drag clip again).
Clip markers are very useful though.

Another note- Resolve doesn't preserve markers in exported files (MOV or MXF), where Premiere does and it's also a great feature. BM should add it. Metadata is so underestimated...
Offline
User avatar

Igor Riđanović

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

Re: Creating Scripts for DaVinci Resolve

PostMon Feb 06, 2023 5:21 am

iddos-l wrote:
roger.magnusson wrote:But it doesn't go both ways. Markers you add on a clip in the Media page show up when you add the clip to a timeline. But markers you add on a clip in a timeline don't propagate "back" and won't show on a clip in the Media page.
Yes that’s why I didn’t understand before.


You can:
Code: Select all
timelineItem.AddMarker()

You can also:
Code: Select all
binClip = timelneItem.GetMediaPoolItem()
binClip.AddMarker()
www.metafide.com - DaVinci Resolve™ Apps
Offline

AssistantEditor1

  • Posts: 107
  • Joined: Tue Jan 31, 2023 5:30 am
  • Real Name: Milton Breslin

Re: Creating Scripts for DaVinci Resolve

PostSat Feb 11, 2023 7:01 pm

Stills from markers is such a useful idea!

Thanks for making it!

Edit: if one had the know how, would it be possible to create a script that displays the duration of an in/out
range in seconds/milliseconds?

It seems like resolve doesn’t offer a way to see fractions of a second anywhere
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Creating Scripts for DaVinci Resolve

PostSat Feb 11, 2023 9:31 pm

I can add that to the Timeline Duration script. If I recall correctly there are some obstacles to getting the In/Out marks of a timeline. In order to get it, you have to get the media pool item that represents the current timeline and Resolve 18 doesn't have a function for that.

My current workaround is to loop through all the media pool items and compare the names to the current timeline. It's not perfect because multiple timelines in Resolve can have the same name: Not sure if that's a bug or by design, you can't create a timeline with the same name but you can copy/paste one into another bin and even move it back to the original bin.

There's also no straightforward way to directly determine the type of a media pool item - whether it's a clip or a timeline. Well, there is, but it's a translated property, so in terms of code I won't know whether to check for the item type in English or Spanish or any of the other supported languages. Resolve has a few of these issues. Dates are also translated/localized, making them impossible to use directly without parsing them in all languages.

Now we're getting to the secondary goal of this thread, bringing up issues like these so BMD can hopefully address them. The more interest there is for scripting the greater the likelihood that BMD can take the time to fix it.

All of the above is for timeline In/Out marks. If you want info from timeline duration markers instead, that's straightforward.
Offline

AssistantEditor1

  • Posts: 107
  • Joined: Tue Jan 31, 2023 5:30 am
  • Real Name: Milton Breslin

Re: Creating Scripts for DaVinci Resolve

PostSat Feb 11, 2023 11:30 pm

@Roger

While I do hope BM addresses those issues with in/out marks that you mention, I would in some ways be more happy with seeing the sec/milliseconds of all duration markers on a timeline listed out for input into a csv file.

In any case, I love everything going on in this thread.

These types of improvements can seem so small but they can save so much time.
Offline

pantau000

  • Posts: 143
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Re: Creating Scripts for DaVinci Resolve

PostSun Feb 12, 2023 12:21 pm

Igor Riđanović wrote:Yes, it's possible to apply timeline markers to the bin clips.

I tried to add the lines you suggest below to the script that changes timeline marker colours:
Code: Select all
local binClip = timelneItem.GetMediaPoolItem(marker_frame)
binClip.AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)

I put this just before these lines:
Code: Select all
timeline:DeleteMarkerAtFrame(marker_frame)
timeline:AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)

Nothing happens though... Could you help me?
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Creating Scripts for DaVinci Resolve

PostTue Feb 14, 2023 4:43 pm

For a Lua script you need to use the colon symbol when invoking the Resolve API methods. Like this:
Code: Select all
local binClip = timelneItem:GetMediaPoolItem(marker_frame)
binClip:AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)

But note that GetMediaPoolItem() doesn't take any parameters.
Last edited by roger.magnusson on Tue Feb 14, 2023 6:53 pm, edited 1 time in total.
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Export Timeline Markers

PostTue Feb 14, 2023 5:13 pm

Here's a script that might come in handy. It can export timeline markers to these formats:
  • Fairlight ADR Cues (*.csv)

  • JSON Data (*.json)

  • Premiere Pro CSV (*.csv)
    Even though this is tab-delimited, Adobe calls it a CSV file (comma-separated values).

  • SRT Subtitles (*.srt)

  • Tab-delimited Text (*.txt)
    This is the default format and contains all the fields, including Duration (Time).

    The exported file is compatible with Microsoft Excel and can be opened in Excel directly without an import process or any specific settings. In Google Sheets you need to use File > Import and you can unselect the option for "Convert text to numbers, dates and formulas" if you want the Duration (Time) column to keep its formatting.

  • WebVTT Subtitles (*.vtt)

  • YouTube Chapters (*.txt)
    If you would like more control and instant preview of the text, check out my other script, YouTube Video Chapters Plus.

Image

Here's the exported file opened in Excel (with some formatting applied):Image

Known Issues
Not an issue with the script, but Fairlight has a bug where it can't import ADR Cues with timecode for frame rates above 100fps.

Download
Export Timeline Markers.lua

Follow the instructions for putting a script in the Scripts folder here.
Last edited by roger.magnusson on Sun Jun 04, 2023 8:40 pm, edited 4 times in total.
Offline
User avatar

iddos-l

  • Posts: 798
  • Joined: Sat Mar 30, 2019 7:55 pm
  • Real Name: iddo lahman

Re: Creating Scripts for DaVinci Resolve

PostTue Feb 14, 2023 5:38 pm

Nice one
Offline

AssistantEditor1

  • Posts: 107
  • Joined: Tue Jan 31, 2023 5:30 am
  • Real Name: Milton Breslin

Re: Creating Scripts for DaVinci Resolve

PostTue Feb 14, 2023 5:41 pm

This is insanely useful, Roger!

Between this and the stills at markers script this thread is gold.
Offline
User avatar

evanfotis

  • Posts: 97
  • Joined: Sat Feb 23, 2019 2:42 pm
  • Real Name: Evangelos Georgoulakis

Re: Creating Scripts for DaVinci Resolve

PostTue Feb 14, 2023 7:22 pm

Great thread!
So much functionality automated!
An issue I manually have to deal with each time, which is time consuming is this workflow:

I have multible braw clips with video and audio, as well as multiple wav clips from an audio recorder which has two XLR mics recorded one on each track.
I then auto align clips based on waveform.
However, Resolve just outputs a single audio track for the aligned version which is not optimal in controlling levels of each speaker and mic.
I have to separate L/R into two separate mono tracks from the wav recordings, and I also want braw original audio on a third track. So I need three audio tracks visible just aligned.
Could this process be automated with a script?
Offline
User avatar

roger.magnusson

  • Posts: 3343
  • Joined: Wed Sep 23, 2015 4:58 pm

Re: Creating Scripts for DaVinci Resolve

PostWed Feb 15, 2023 12:06 am

Unfortunately scripts don't have access to the channel settings you would set under Clip Attributes > Audio. So for now it's not possible.

But if each shoot is done with the same settings you can at least select all the audio files and change the channel setup for all of them at once.
Offline

pantau000

  • Posts: 143
  • Joined: Wed Dec 21, 2022 5:42 pm
  • Real Name: Peter Antoni

Re: Creating Scripts for DaVinci Resolve

PostWed Feb 15, 2023 12:55 am

roger.magnusson wrote:For a Lua script you need to use the colon symbol when invoking the Resolve API methods. Like this:
Code: Select all
local binClip = timelneItem:GetMediaPoolItem(marker_frame)
binClip:AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)

But note that GetMediaPoolItem() doesn't take any parameters.

Thanks, but this is all still a mystery to me...
Would I have to include this line to get the item?
Code: Select all
timelineitem = timeline.GetCurrentVideoItem()

And then:
Code: Select all
local binClip = timelneItem:GetMediaPoolItem()
binClip:AddMarker(marker_frame, color, marker.name, marker.note, marker.duration, marker.customData)
Next

Return to DaVinci Resolve

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot], Shrinivas Ramani, Vdeveau97 and 117 guests