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: 399
  • 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: 154
  • 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: 154
  • 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: 154
  • 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: 399
  • 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: 154
  • 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: 112
  • 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: 477
  • 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.065
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
Offline

Framestamp

  • Posts: 1
  • Joined: Mon Jun 25, 2018 7:33 pm
  • Real Name: Gilles de Saint-Aubert

Re: Python scripting in Resolve 15

PostMon Jun 25, 2018 7:45 pm

GeeOBCR wrote: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

Hi,

I'm having the same issue (Win 10).
However, I'm running the free version of Resolve 15 (beta 5). As there there is no option for scripting in the Preference menu, I'm suspecting Scripting is only available using the Studio version. Can anybody confirm ?

As mentioned at steakunderwater.com :
If you open Resolve's System > Configuration section there is an External Scripting Using control that can be configured to allow remote systems to control and automate the Resolve GUI session using fuscript. You have the choice of selecting "None", "Local", or "Network" in this menu.

I do not see this option in my settings.

Thanks.
Offline

Igor Riđanović

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

Re: Python scripting in Resolve 15

PostWed Jun 27, 2018 3:38 pm

Chip.Murphy wrote: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.


It wasn't a script. I only tested that in an interactive Python interpreter session. And it was back in April on beta 1.

I was able to read metadata written in Resolve. I was also able to write and read metadata from Python, but i could not read that metadata in Resolve.
Offline

Igor Riđanović

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

Re: Python scripting in Resolve 15

PostWed Jun 27, 2018 3:53 pm

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


Do you get any specific response in the console when you try this?

Windows is not a factor, except that it doesn't come with Python preinstalled. I haven't tried it, but I don't see how the Fusion console would work in Python if the interpreter is missing. Lua is installed with Fusion.

Did you add the path to the module to the $PATH environment variable?
Offline

Rodion Zhabrev

  • Posts: 3
  • Joined: Fri Sep 28, 2012 9:11 am

Re: Python scripting in Resolve 15

PostMon Jul 02, 2018 8:32 pm

Hello,

Can't understand what am I doing wrong. After setting Variables in Windows as mentioned above still getting "Could not locate module dependencies" error on importing DaVinciResolveScript.

It's my first time setting variables so maybe I did something terribly wrong.
Offline

im.thatoneguy

  • Posts: 1
  • Joined: Fri Jul 06, 2018 11:52 pm
  • Real Name: Gavin Greenwalt

Re: Python scripting in Resolve 15

PostFri Jul 06, 2018 11:55 pm

I can't get it to work on windows either.

If I run scriptapp("Fusion") it works.
FusionUI (0x000002884A77A020) [App: 'Fusion' on 127.0.0.1, UUID: 750f52fb-0a45-40d9-ade8-c68e975277a0]

if I run scriptapp("Resolve")
None

I tried setting the Environment Variables and I tried doing it pragramatically through Python in the python shell.

I tried in the Console. I tried in IDLE ad I tried through fuscript with the same result.
Offline

Val Gameiro

  • Posts: 47
  • Joined: Thu May 02, 2013 11:42 pm
  • Location: Austin, Texas

Re: Python scripting in Resolve 15

PostThu Jul 12, 2018 7:02 pm

Ok, after a lot of back and forth and research, I got Resolve 15 scripting to stop giving me errors, but it's still not working.

First, I tried running lines from the DaVinciResolveScript.py directly in python to help find the problem.

Code: Select all
script_module = None
-- ran fine

Code: Select all
import fusionscript as script_module
-- gave "no module named 'fusionscript'

Code: Select all
>>> lib_path=os.getenv("RESOLVE_SCRIPT_LIB")
>>> print(lib_path)
"C:\Program Files\Blackmagic Design\DaVinci Resolve Beta\fusionscript.dll"


So, that worked fine.

And here it tanked:
Code: Select all
script_module = imp.load_dynamic("fusionscript", lib_path)


"ImportError: DLL load failed: The specified module could not be found."

But I knew the file was there. I could see it.

Finally, the problem turned out to be that the sys env variable had to have double backslashes in order for it to work:

script_module = imp.load_dynamic("fusionscript", "C:\\Program Files\\Blackmagic Design\\DaVinci Resolve Beta\\fusionscript.dll")

So, I went to System Properties / Advanced / Environment Variables, and made the change.

Here are my env vars -- you'll notice I'm running the Beta concurrently with v14, so I will have to update these vars once I upgrade to the final release:

Code: Select all
RESOLVE_SCRIPT_API=C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\
RESOLVE_SCRIPT_LIB="C:\\Program Files\\Blackmagic Design\\DaVinci Resolve Beta\\fusionscript.dll"


But, even with all that, and manually running each statement from the DaVinciResolveScript.py, I'm still stuck.

Basically, after I run
Code: Select all
sys.modules[__name__] = script_module
it seems to lose all the imports and variables, and I can't load them back.

For instance, if I try
Code: Select all
import sys
I get an ImportError:

Code: Select all
ImportError: __import__ not found


Anybody had any luck? Not sure where to go from here. It seemed, at first, that it was working (once the errors disappeared) but I can't run statements.

Code: Select all
resolve = script_module.scriptapp('Resolve')
pm = resolve.GetProjectManager()
Val Gameiro
Writer/Director/Filmmaker
Austin, Texas
http://www.AmnesiaTheMovie.com
http://www.ValGameiro.com
http://www.IdealSceneProductions.com
http://www.TXSTARentertainment.com
Offline

Igor Riđanović

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

Re: Python scripting in Resolve 15

PostFri Jul 13, 2018 2:30 am

Are you saying that
Code: Select all
import sys

on your machine returns an error? If that's correct, you should reinstall Python. Something is botched and it has nothing to do with Resolve.

Other than that, the scripting definitely works on all public beta releases so far. Look up getresolve.py that's installed in the developer directory. Actually, I'm not sure if this is the original name or if I renamed my customized version. Either way, this script will show you the best way to load the API.

It evaluates the host OS, attempts to import DaVinciResolveScript using your system envirnoment variables, and if the variables are not set it uses the imp module to import DaVinciResolveScript from semi-hard coded paths where this file is most likely to be found.

Or you can forget the all of this and just use imp for brute force loading, but your script will not be cross platform compatible. Here is the Windows compatible hard coded version:
Code: Select all
# loading without sys env variables
import imp
dr = imp.load_source('DaVinciResolveScript', 'C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support\Developer\Scripting\Modules\DaVinciResolveScript.py')
resolve = dr.scriptapp('Resolve')
Offline

Val Gameiro

  • Posts: 47
  • Joined: Thu May 02, 2013 11:42 pm
  • Location: Austin, Texas

Re: Python scripting in Resolve 15

PostFri Jul 13, 2018 1:44 pm

Well, let me explain.

The "import sys" doesn't fail at first, only when I manually try to execute the python commands in the DavinciResolveScript.py.

Specifically after sys.modules call:

Code: Select all
script_module = imp.load_dynamic("fusionscript", "C:\\Program Files\\Blackmagic Design\\DaVinci Resolve Beta\\fusionscript.dll")
sys.modules[__name__] = script_module


But, if I restart the interpreter, then it goes back to working fine.

By the way, I really enjoyed your video on Resolve 15 scripting! :)
Val Gameiro
Writer/Director/Filmmaker
Austin, Texas
http://www.AmnesiaTheMovie.com
http://www.ValGameiro.com
http://www.IdealSceneProductions.com
http://www.TXSTARentertainment.com

Return to DaVinci Resolve 15 Beta

Who is online

Users browsing this forum: No registered users and 3 guests