Python scripting in Resolve 15

A place for feedback and discussion on DaVinci Resolve 15
  • Author
  • Message
Offline
User avatar

Nick Shaw

  • Posts: 208
  • Joined: Thu Sep 13, 2012 11:43 am
  • Location: London, UK

Python scripting in Resolve 15

PostMon Apr 16, 2018 12:28 pm

Is this the right place to look for help on Resolve scripting?

I am a bit of a noob to this, so I may well be doing something stupid.

Code: Select all
DaVinciResolveScript.scriptapp("Resolve")
returns a None object, so I can't then do anything with it.
Code: Select all
AttributeError: 'NoneType' object has no attribute 'GetProjectManager'

The example scripts fail for this same reason.

However,
Code: Select all
DaVinciResolveScript.scriptapp("Fusion")
returns a FusionUI object, so the module would appear to have loaded.

I do get a bunch of warnings when importing the module:
Code: Select all
dyld: warning, LC_RPATH @executable_path/../Libraries/Fusion in /Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/. in /Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/../Frameworks in /Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/libluajit-5.1.2.dylib being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/../Libraries/Fusion in /Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/libluajit-5.1.2.dylib being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/. in /Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/libluajit-5.1.2.dylib being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/../Libraries/Fusion in /Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/. in /Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/../Libraries/Fusion in /Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so being ignored in restricted program because of @executable_path
dyld: warning, LC_RPATH @executable_path/. in /Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so being ignored in restricted program because of @executable_path
Workflow Consultant, London UK
LUTs and LUT plugins
www.antlerpost.com/plugins
Offline
User avatar

Nick Shaw

  • Posts: 208
  • Joined: Thu Sep 13, 2012 11:43 am
  • Location: London, UK

Re: Python scripting in Resolve 15

PostTue Apr 17, 2018 11:06 am

Update, I got the errors mentioned above when trying to use scripting through a standard Terminal Python shell (under OS X) but when I run fuscript in interactive mode I have more success (/Applications/DaVinci\ Resolve/DaVinci\ Resolve.app/Contents/Libraries/Fusion/fuscript -l py2 -i). I discovered this via a post on steakunderwater.com although I can't see any mention of fuscript in the Resolve scripting README.

I'm sure yesterday I had the same problems using the console within Resolve, but today it seems to work! So maybe I missed something yesterday.

I am able to work through the steps from the 1_sorted_timeline_from_folder.py example script, and it seems mainly to work. I can create a project and add the clips to a timeline. There are a few things I am still unsure of, but I am feeling my way, and it may well be user error.

project.SetResolution(2048, 1152) sets the Timeline Resolution (as shown in the Project Settings panel) to 2048x1152, but then running timeline = mediapool.CreateEmptyTimeline("Test Timeline 1") creates a new timeline which is still 1920x1080, per defaults. But if the resolution is set via scripting, creating a new timeline by pressing CMD-N also produces a 1080p timeline, so maybe there is somewhere else that I need to set it to 2k as well.

project.SetFrameRate(25) sets the timeline framerate to 25, but the Playback Framerate stays at the default 24, and I can't find a way of setting that via scripting.

If this is a bug, I was just luck that a chose a folder of 2kp25 clips to test with. If they had been 1080p24, I would not have noticed.
Workflow Consultant, London UK
LUTs and LUT plugins
www.antlerpost.com/plugins
Offline
User avatar

Nick Shaw

  • Posts: 208
  • Joined: Thu Sep 13, 2012 11:43 am
  • Location: London, UK

Re: Python scripting in Resolve 15

PostTue Apr 17, 2018 11:50 am

…and now it works in a standard Python shell in Terminal as well!

Maybe it's because I restarted the machine. Maybe it's because I ran fuscript first. Who knows, but it works!

I can still only create a 1080p timeline that plays back at 24fps, but it's a good start.

Onwards and upwards!
Workflow Consultant, London UK
LUTs and LUT plugins
www.antlerpost.com/plugins
Offline
User avatar

Nick Shaw

  • Posts: 208
  • Joined: Thu Sep 13, 2012 11:43 am
  • Location: London, UK

Re: Python scripting in Resolve 15

PostMon Apr 23, 2018 3:25 pm

Has anybody found out if there are any methods enabled in Resolve scripting which are not listed in the ReadMe? Particularly ones for rendering.
Workflow Consultant, London UK
LUTs and LUT plugins
www.antlerpost.com/plugins
Offline

roger.magnusson

  • Posts: 384
  • Joined: Wed Sep 23, 2015 4:58 pm
  • Location: Sweden

Re: Python scripting in Resolve 15

PostWed May 02, 2018 2:41 pm

I can't answer the question but I hope it's ok to use this thread for general Python scripting feedback as well.

The DaVinci Resolve Beta 2 Python scripting documentation in %ProgramData%\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\README.txt has some mistakes in the environment variables for Windows.

It says:
Code: Select all
Windows:
RESOLVE_SCRIPT_API="%PROGRAMDATA%\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting\\"
RESOLVE_SCRIPT_LIB="C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\fusionscript.so"
PYTHONPATH="%PYTHONPATH%:%RESOLVE_SCRIPT_API%\\Modules\\"
But it should probably be:
Code: Select all
Windows:
RESOLVE_SCRIPT_API="%PROGRAMDATA%\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting\\"
RESOLVE_SCRIPT_LIB="C:\\Program Files\\Blackmagic Design\\DaVinci Resolve\\fusionscript.dll"
PYTHONPATH="%PYTHONPATH%;%RESOLVE_SCRIPT_API%\\Modules\\"

That's ".dll" at the end of the second variable, and a semicolon instead of a colon as a separator in the third variable (the Windows "Environment Variables" built-in GUI editor needs semicolon or it won't function properly).
Offline

Igor Riđanović

  • Posts: 137
  • Joined: Thu Jul 02, 2015 5:11 am

Re: Python scripting in Resolve 15

PostSat May 05, 2018 6:40 am

I spent a couple of hours testing it yesterday. It's pretty cool.

Yes, there is an error in readme.txt in the description of the Windows environment variables. Depending on how you create the variables the double slashes may also need to go. For example, of you use the whatever-it's-called Windows 10 GUI tool to define the variables, you need to use the single slashes.

Also, you can't define:

Code: Select all
PYTHONPATH="%PYTHONPATH%:%RESOLVE_SCRIPT_API%\\Modules\\"


Because the variables are sorted alphabetically and %RESOLVE_SCRIPT_API% does not exist until after %PYTHONPATH%.

Instead I defined mine as somewhat less flexible, but acceptable:

Code: Select all
PYTHONPATH = %PYTHONPATH%;C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\Modules\
Offline

Igor Riđanović

  • Posts: 137
  • Joined: Thu Jul 02, 2015 5:11 am

Re: Python scripting in Resolve 15

PostSat May 05, 2018 7:12 am

Nick Shaw wrote:Has anybody found out if there are any methods enabled in Resolve scripting which are not listed in the ReadMe? Particularly ones for rendering.


I may have seen something in the two sample .py scripts that was not listed in the API documentation. Also, the doc itself said that the methods listed were "often used" which would imply there are other ones. I haven't seen anything render oriented so far.

I've never needed to dig into a class looking for undocumented methods, but i think the Python inspect module does that.

The DaVinciResolveScript.py module is sort of passed right through to the fusionscript.dll or fusionscript.so on OSX/Linux. Reverse engineering library binaries looking for Python code is not the best way to do it.

I was initially unable to import the module and instantiate the class objects from the built in console in Fusion. I tried it only once before I set my system environment variables. After that it worked. But I understood the API documentation saying that it's not necessary to set the variables if you're using the built in console, but that's not how it worked for me.

After seeing that it worked I just used the Windows command line instead. I like the way Python interpreter echoes in the OS console better than the behavior in the Fusion console.

I have had some slowdowns. Particularly after creating a new timeline from existing media pool clips and appending it with clips Resolve would become sluggish to the point it needed a restart. On one occasion I had to kill the process to shut it down.

Reading existing clip metadata reading worked, but writing to clip metadata didn't seem to work well. I would write metadata, and could read it back from the command line, but the metadata panel in Resolve would still show the pre-existing metadata.

I love the ability to create a project, bins, populate with clips, and even conform timelines programmatically. We heavily rely on such automation for Media Composer project creation. It saves a ton of time on complex projects.

I made a couple of proof-of-concept apps wrapped in Qt that demo the API capabilities. I'll be putting out a scripting video tutorial in the coming weeks.
Offline

Igor Riđanović

  • Posts: 137
  • Joined: Thu Jul 02, 2015 5:11 am

Re: Python scripting in Resolve 15

PostMon May 07, 2018 8:29 pm

Here are several Resolve scripting Python tests i put together. The two examples installed by the V15 are very good for understanding the API usage.

https://github.com/IgorRidanovic/DaVinc ... ClipLister
https://github.com/IgorRidanovic/DaVinc ... ageFlipper
https://github.com/IgorRidanovic/DaVinc ... geSwitcher
Offline

roger.magnusson

  • Posts: 384
  • Joined: Wed Sep 23, 2015 4:58 pm
  • Location: Sweden

Re: Python scripting in Resolve 15

PostTue May 08, 2018 8:35 am

Nice, I've been meaning to check out the QT framework and this will be a good starting point.

@BMD, is there any chance you will publish the header file for fusionscript.dll so that we can use it in other languages/technologies as well? Or even better, a .NET Core managed dll.
Offline

Igor Riđanović

  • Posts: 137
  • Joined: Thu Jul 02, 2015 5:11 am

Re: Python scripting in Resolve 15

PostTue May 08, 2018 3:40 pm

You could spend many, many months learning the intricacies of Qt and the learning curve is steep. But the payback is significant. But before you dive into it, check this discussion of the stripped down Qt that's provided as a part of Fuscript. I haven't tried it myself yet. The advantages are the simplicity and the UI style inherited from Resolve.

I don't know if such apps could be portable and usable on a non-Resolve machine. You'd have to make sure all the dependencies are included in the package which is easy with Qt.

https://www.steakunderwater.com/wesuckl ... 1&start=15
Offline

Chip.Murphy

  • Posts: 105
  • Joined: Wed Mar 08, 2017 5:59 pm

Re: Python scripting in Resolve 15

PostSat May 19, 2018 5:58 am

Igor Riđanović wrote:Here are several Resolve scripting Python tests i put together. The two examples installed by the V15 are very good for understanding the API usage.

https://github.com/IgorRidanovic/DaVinc ... ClipLister
https://github.com/IgorRidanovic/DaVinc ... ageFlipper
https://github.com/IgorRidanovic/DaVinc ... geSwitcher


Igor, these are awesome.

Super curious to see your python script that has SetMetadata at some point. Were you able to set specific metadata?

This could be super useful for CatDV users. A script to just pull in a CSV without having to go through the import metadata function would be great.
Offline

Tom Early

  • Posts: 459
  • Joined: Wed Jul 17, 2013 11:01 am

Re: Python scripting in Resolve 15

PostSat May 19, 2018 10:18 am

Nick Shaw wrote:project.SetResolution(2048, 1152) sets the Timeline Resolution (as shown in the Project Settings panel) to 2048x1152, but then running timeline = mediapool.CreateEmptyTimeline("Test Timeline 1") creates a new timeline which is still 1920x1080, per defaults. But if the resolution is set via scripting, creating a new timeline by pressing CMD-N also produces a 1080p timeline, so maybe there is somewhere else that I need to set it to 2k as well.


Thr Mediapool timeline resolution column will display whatever resolution is set in Output Scaling
MBP2016, MacOS 10.13.4, 2.9 GHz Intel Core i7, 16 GB 2133 MHz LPDDR3,
Radeon Pro 460 4096 MB, Resolve Studio 15.0.0B.057
Offline

GeeOBCR

  • Posts: 1
  • Joined: Fri Jun 15, 2018 10:54 am
  • Real Name: George Antonopoulos

Re: Python scripting in Resolve 15

PostFri Jun 15, 2018 11:04 am

Hi, just wondering if you had any luck with initialising the Resolve side of scripting,

I can't get past DaVinciResolveScript.scriptapp("Resolve"), even though Fusion works,
I've tried Nick's suggestion of launching fuscript on interactive mode but that hasn't helped.

I'm on Windows so don't know if that plays a part as well,

Thanks for reading!

George

Return to DaVinci Resolve 15 Beta

Who is online

Users browsing this forum: Google [Bot], Iliya Gitlin, Shrinivas Ramani and 5 guests