Script needed to import clips

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

Phadeguy

  • Posts: 33
  • Joined: Sun Feb 27, 2022 5:08 pm
  • Real Name: Kris McCormic

Script needed to import clips

PostFri Feb 23, 2024 12:12 am

Hey Everyone,

I need some help to create a macro/script/plugin for Davinci Resolve that will generate a timeline sequence from a text file. The text file contains a list of filenames with paths to each video clip. The script will then:
  1. Create a new timeline in the root master folder within the current project
  2. Name the new timeline as the name of the text file (ignore the file extension in the name).
  3. Create a new bin under master called "vid_source/[name of file]"
  4. Import all clips listed in the text file into the new bin
  5. Place all clips on the timeline in the order that they appear in the text file.
  6. Normalize the audio for each clip in the timeline.
Having a way to drag-and-drop the text file to start the import would be really nice.

I asked ChatGPT to generate this script and it produced expected results: code that does not work.

Can anyone here help a poor n00b out? I would greatly appreciate it!

Thanks and have a great day!!
Offline

Shrinivas Ramani

Blackmagic Design

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

Re: Script needed to import clips

PostFri Feb 23, 2024 5:25 am

Please have a look at the scripting examples under DaVinci Resolve's Help menu > Documentation> Developer > Scripting.

Specifically, 1_sorted_timeline_from_folder.(lua/py) has the basic info needed to create a timeline from a file listing.

You can make a copy of that and replace the logic in line 45 with your own.
Offline

Phadeguy

  • Posts: 33
  • Joined: Sun Feb 27, 2022 5:08 pm
  • Real Name: Kris McCormic

Re: Script needed to import clips

PostFri Feb 23, 2024 11:37 pm

Hey Shrinivas,

Thank you for getting me started! It is greatly appreciated!! I am not familiar with either of these languages, but I will do my best.

Using the "sorted timeline" file as an introduction, I see how I can get these parts done:
  1. Add clips by path to the root media folder
  2. Create a new timeline with a specified name
  3. Add clips to the timeline in a specified order

Where would I find examples of how to solve these steps?
  1. Input a text file to the script with drag/drop
  2. Read the contents of the text file into an array
  3. Create a media pool subfolder
  4. Save a clip to the newly created media pool subfolder
  5. Normalize the audio of the clip

Thank you again for your help!!
Offline

Phadeguy

  • Posts: 33
  • Joined: Sun Feb 27, 2022 5:08 pm
  • Real Name: Kris McCormic

Re: Script needed to import clips

PostSat Feb 24, 2024 10:03 pm

Hey Everyone,

I'm trying to get a fraction of the example script to run, but I can't get it past the first lines of the example script. Here is the script I have so far:
Code: Select all
import DaVinciResolveScript as dvr_script
import sys
import os

# Ensure DaVinci Resolve project is open and get the project manager
resolve         = dvr_script.scriptapp("Resolve")
project_manager = resolve.GetProjectManager()
project         = project_manager.GetCurrentProject()
media_pool      = project.GetMediaPool()
Here is the error:
Code: Select all
Traceback (most recent call last):
  File "C:\ProgramData\Blackmagic Design\DaVinci Resolve\Fusion\Scripts\Comp\testMe.py", line 16, in <module>
    project_manager = resolve.GetProjectManager()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'GetProjectManager'
'
Are these example scripts designed actually to run? Are they up to date or just old abandoned code?

Thanks again for your help!
Offline

Shrinivas Ramani

Blackmagic Design

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

Re: Script needed to import clips

PostSun Feb 25, 2024 3:48 am

The Scripting/README.txt is a good starting point.

From environment variable set up to prerequisites, it describes how to get started. In your case, if the variable "resolve" is None, check for options why it might be?
Offline

Phadeguy

  • Posts: 33
  • Joined: Sun Feb 27, 2022 5:08 pm
  • Real Name: Kris McCormic

Re: Script needed to import clips

PostSun Feb 25, 2024 2:12 pm

Hey Shrinivas,

Thank you again for the reply! Always appreciated!!

I did look at the readme, but it appeared to be a quick-reference note card for people who already know what they need but maybe forgot the exact parameters or spelling of a function (Was it "AddItemsListToMediaPool" or "AddItemListToMediaPool"? Ahh, the singular form of "Item" is correct...) rather than a how-to guide or teaching document.

For instance, there is no reference to audio normalization in the readme. In fact, there is no reference to setting audio volume levels at all. Is it actually possible to apply audio normalization in a script? My Google searches only returned results on how to normalize audio using the visual user interface (right-click on the audio track and select "Normalize Audio Levels..." seems like a straightforward thing to script).

As for the errored line in the script above, I ended up just deleting the previous line and the rest of the script worked; there was no real explanation as to what was wrong or why that fixed it.

This has reinforced my suspicion that the included readme and example scripts have been neglected (all too common for product developers) and are not really useful anymore to someone starting out with scripting.

Are there better (more complete) references, guides, or tutorials for DaVinci Resolve scripting out there? I have only found the occasional blog post and how-to YouTube video.

I know this forum is full of helpful and expertly knowledgeable people! You are awesome!!

Thanks again for your help!!
Offline

Phadeguy

  • Posts: 33
  • Joined: Sun Feb 27, 2022 5:08 pm
  • Real Name: Kris McCormic

Re: Script needed to import clips

PostSun Feb 25, 2024 9:26 pm

Hey Everyone,

Having never written a DaVinci Resolve script before (or ever used Python), I have combed forum posts and blog entries to achieve all of my needs except for two:
  1. Normalize audio
  2. Append timeline to timeline
I've searched high and low for a scripting way to normalize a clip's audio (or adjust audio at all), but I haven't found any yet. The only way I've found is by using the visual user interface (right-click on clip -> Normalize Audio Levels...). Is there a way to script this?

For the second challenge, I have created short bumper timelines to go in between each clip I am bringing in. I will manually tweak these timelines later, but I wanted them in place within the main timeline now. I can drag-and-drop the bumper timelines onto the main timeline, but scripting this doesn't seem to work. I have scripted an array to hold the bumper objects and printing them shows the bumper timeline object information. But when I try AppendToTimeline, I get nothing. Is there a separate method that will append a timeline to a timeline just like the drag-and-drop?

Thanks again for all your help!
Offline

Phadeguy

  • Posts: 33
  • Joined: Sun Feb 27, 2022 5:08 pm
  • Real Name: Kris McCormic

Re: Script needed to import clips

PostMon Feb 26, 2024 12:09 am

Hey Everyone,

I got the "append timeline to timeline" thing sorted. It turns out I had grabbed the timelines as "timeline" objects by using "GetTimelineByIndex" instead of grabbing them as "clip" objects by using "GetClipList".

One challenge down, one to go!

Thanks again!

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 11 guests