Git Product home page Git Product logo

pydavinci's Introduction

pydavinci

A lightly opinionated DaVinci Resolve Python API wrapper

Provides auto completion, type hints and great API reference documentation.

I really just wanted auto completion in the IDE and to program transcoding RAW formats


Install pydavinci

Install via pip using a Python 3.6 environment

pip install pydavinci

Now, with Davinci Resolve open, we just need to import it!

from pydavinci import davinci

resolve = davinci.Resolve()

Examples and documentation


Installation requirements and guidelines

pydavinci only works with Python 3.6.*, as that's a requirement on DaVinci Resolve's part.

For launching scripts externally, you also need the Studio version.

If you're working with the built-in Davinci Resolve Python console, you need to install pydavinci for the Python interpreter that's used by Davinci's console.

For avoiding conflicts when using inside the embedded console, don't use resolve as the entry point variable, as that's reserved by the console. Example of suggested usage:


Davinci Resolve v18 beta

For the newer DaVinci Resolve v18, currently in beta, newer Python installations are supported.

If you want to try out pydavinci with new Python versions for Resolve v18, use pip with the --ignore-requires-python flag.

Note that while I did some quick tests, I can't guarantee everything works on Resolve v18 beta. Full testing will become available as further betas come through, and will be supported fully on the official release.


Launching scripts externally (Studio version)

For pydavinci to work by launching scripts outside the embedded console, make sure external scripting is set to Local in Settings -> System -> General

To-do and contributing

Contributors are always welcome! I currently have a few things I want to change, some of them are:

  • Document all possible values of get_setting and set_setting New in 0.2.0!
  • Add a better way of interfacing with the whole get_setting and set_setting methods using a proxy class or something to that effect New in 0.2.0!
  • Deal with markers in a better way New in 0.2.0!
  • Auto launch Resolve when it's not open - I've ran into some issues while trying to connect to the C extension right after launching it, a dirty way to do it is to just implement a time.sleep before trying to import the fusionscript module, otherwise we'll need to create another entrypoint to the api for launching the process and then signaling when it's ready
  • Do the same wrapper made for settings to Metadata and Properties

If you want to contribute feel free to open a pull request!

pydavinci's People

Contributors

in03 avatar pedrolabonia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pydavinci's Issues

timeline.settings.frame_rate not working correctly with framerates that have a decimal

Describe the bug
timeline.settings.frame_rate & project.get_setting("timelineFrameRate") don't return the same value.

To Reproduce
In Davinci Resolve set the following setttings
Timeline framerate 29.97
Project framerate 29.97

Use the following code:

resolve = davinci.Resolve()

project = resolve.project
timeline = project.timeline
framerate = project.get_setting("timelineFrameRate")

timeline.custom_settings(True)
framerate2 = timeline.settings.frame_rate

Expected behavior
framerate and framerate2 should be the same? Instead framerate = 29.97 (correct) and framerate2 = 29.0 (incorrent)

Screenshots
timeline settings
image

project settings
image

the two variables
image

Desktop (please complete the following information):

  • OS: Windows 10
  • Python Version: 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)]
  • Davinci Resolve Version: 18.0.1 Build 3

Additional context
Same can be reproduced with framerates of 59.94 & probably any other which isn't a whole number.
So it probably has something to do with type casting or conversion.

A project & timeline framerate of 60 works as expected. Both return 60.0

struggling with code -1073741819 (0xC0000005) Please help

I have been trying to get this to work for serval hours now.

All I am getting is

Process finished with exit code -1073741819 (0xC0000005)

I have been trying this from Pycharm

from pydavinci import davinci
resolve = davinchi.Resolve()
timeline = resolve.active_timeline
print(timeline.name)

I have tried running it from the termal as well but all i get from that is that it cant find python

image

even though I have all the paths set.

image

Any chance you know what Im doing wrong.

Readme info may not be accurate

For the newer DaVinci Resolve v18, currently in beta, newer Python installations are supported.

Where did you get if from? I downloaded dr-studio 18.0b1, and in documentation it still says it wants python 3.6.

You also need the Studio version.

Why? The scripting launch is unavailable from out of the dr, but launching from within dr should work. The library should just help you to autocomplete while writing a script. So why you require Studio in this project?

GetTimelineByIndex(...) wrapper missing

Hi there,
I miss the wrapper for GetTimelineByIndex(...) in pydavinci/wrappers/project.py.
The implementation of open_timeline(...) already shows a call of Timeline(self._obj.GetTimelineByIndex(i + 1)), so this looks like a straight forward enhancement. Some pseudo code:

def get_timeline(self, index: int) -> "Timeline":
    """
    Returns timeline by index.
    Args:
        index (int): 1 <= index <= timeline_count
    Returns:
        "Timeline": ``Timeline`` if successful, ``None`` otherwise
    """
    from pydavinci.wrappers.timeline import Timeline

    return Timeline(self._obj.GetTimelineByIndex(index))

It would be helpful if you could add this. Thank you.
Thomas

Leftover debug print in `project_manager.open_folder` func?

Describe the bug
When opening a folder, Pydavinci prints entru open folder

To Reproduce

resolve = davinci.Resolve()
root_folder = resolve.project_manager.folder
resolve.project_manager.open_folder(root_folder)

Expected behavior
No such print to be present

Screenshots

Desktop (please complete the following information):

  • OS: Windows 10
  • Python Version: 3.10
  • Davinci Resolve Version: 18.1.1

Additional context
pydavinci > wrappers > projectmanager.py

    def open_folder(self, folder_name: str) -> bool:
        """
        Open folder named ``folder_name``

        Args:
            folder_name (str): folder name

        Returns:
            bool: ``True`` if successful, ``False`` otherwise
        """
        print("entru open folder")
        return self._obj.OpenFolder(folder_name)

Moving timeline playhead

First of all, thank you very much for this repo, I am enjoying it a lot.

I wanted to ask, is there a way to move the playhead? If I add to the timeline a list of MediaPoolItems, they get added one after another; I would like to add a video and an audio file "at the same time". Is that possible? If not, is there a way to set the time location of a MediaPoolItem?

Ability to add custom directory path inputs to cache/proxies/gallery stills/powergrades/captures

Hello,

My goal is to create an automated script to create a new project and save the presets for the specific database. However the request is to have the ability to add custom directory path inputs for

proxy generation location
cache files location
gallery stills location

Screen Shot 2023-11-19 at 7 32 30 PM

capture and playback / Capture / Save clips to
Screen Shot 2023-11-19 at 7 32 49 PM

Setting powergrade location
Screen Shot 2023-11-19 at 7 33 03 PM

with final step to then set as resolve data base preset.
Screen Shot 2023-11-19 at 7 33 15 PM

I am eager to learn more about this python package
I see there might already be one made which might work.
(settings.perf.cache_clips_location: Optional[Union[Path, str]])
I will test.

I suppose I could accomplish this task using outside UI - looking forward to learning about this package and eventually adding to it

Thanks for your time.

ALE file export

Hi there,

Great library. Easy to use and well documented! Keep up the good work.

I'm looking for a solution to export ALE files of a timeline through the library. Do you think this could be implemented moving forward?

Cheers,
Michael

Get Lut by Node Index

Hi again
I saw on the DR 17.4.6 release notes that they have "Added scripting API support to get node count and LUT by node index"

As usual, no official Resolve documentation of how to do this exactly, but I wondered if you'd looked into this and if you had plans to implement this feature in pydavinci?

My use case would be for doing dailies on multi-LUT shows. We usually create a two-node setup per clip, with CDLs on Node 1, and a LUT or LMT on Node 2. However there is no built-in way of extracting the LUT name from the node and exporting that to an ALE or other metadata file, meaning a lot of manual input and room for mistakes.

Roadmap, additional maintainers?

Is your feature request related to a problem? Please describe.
Love your work! โค๏ธ I can see the sheer amount of work you've put into this.
I'm slowly chipping away at missing wrappers I'd like. I've been working on the gallery ones atm.
Unfortunately, I can't publish my own PyPi packages using my fork of your project as a URL. PyPi doesn't seem to accept packages that have dependencies with git repository sources. And I certainly don't want to publish a fork of pydavinci to PyPi as a workaround...

I'm still getting my head around pydavinci. I don't have much experience with wrappers or stubs, but I'm learning. I'd love to help out in a greater capacity, especially if it means I can use some of Resolve's newer features in Pydavinci and publish to PyPi. I hope this doesn't sound pushy at all, but maybe what I'm asking is:

  • What are your plans for the future of pydavinci?
  • How much time do you have realistically to maintain pydavinci (approve pull requests, tests, etc?)
  • How much time do you have to offer support to contributors and users?
  • Is it feasible to allow additional maintainers, admin, etc?

Describe the solution you'd like
Obviously pydavinci is your baby and I don't want to overstep...
Maybe you could consider adding me as a maintainer? I'm using Python and scripting for Resolve almost every day as part of my job. I'd love to be able to give back as much as I can. Especially in a collaborative project. There isn't a heap of community around scripting for Resolve, but it's starting to get bigger. Having an up-to-date wrapper with typing and intellisense support is a fantastic head start for new projects.

very cool project!

Very cool project! Thanks for your hard work!
Hope more features can be added to fit with Davinci 18!
Many thanks!!!!

get_metadata() - optional argument is actually required - DR18

The docs state that calling mediapoolitem.get_metadata() with no argument will return a dict with all availible metadata, however i'm finding it throws a required positional argument error

To Reproduce

from pydavinci import davinci
import sys

resolve = davinci.Resolve()

media_pool = resolve.media_pool
root = media_pool.root_folder

all_clips = root.clips

for clip in all_clips:

	for item in clip.get_metadata():

		print(item)

Traceback i'm recieving:

Traceback (most recent call last):
  File "/Users/a_user_name/PyDavinciTests.py", line 18, in <module>
    for item in clip.get_metadata():
TypeError: get_metadata() missing 1 required positional argument: 'metadata_key'

System:

  • OS: MacOS Catalina (Macbook Pro 2019)
  • Python Version: 3.9.12
  • Davinci Resolve Version: 18.0B Build 7

Obviously I'm aware I'm running this on an unsupported version, so sorry if this is a problem on my end and not with the module. (Also if I've just written a buggy script!)
It's AvidResolver from Reddit here BTW.

`create_fusion_clip` crashes script

Describe the bug
It says AttributeError: 'function' object has no attribute '_obj' when passed a List[TimelineItem]

To Reproduce

from pydavinci import davinci

resolve = davinci.Resolve()

clips = resolve.media_pool.current_folder.clips

for clip in clips:
    resolve.media_pool.create_timeline_from_clips(clip.name, [clip])
    
    timelineItems = resolve.active_timeline.items
    
    fusionClip = resolve.active_timeline.create_fusion_clip([timelineItems ])

    print(fusionClip)

Expected behavior
The fusion clip to be printed

Screenshots

Traceback (most recent call last):
  File "C:\Users\me\AppData\Roaming\Blackmagic Design\DaVinci Resolve\Support\Fusion\Scripts\testCode.py", line 39, in <module>
    fusionClip = resolve.active_timeline.create_fusion_clip([selectedClip])
  File "C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site-packages\pydavinci\wrappers\timeline.py", line 298, in create_fusion_clip
    return TimelineItem(self._obj.CreateFusionClip(get_resolveobjs(timeline_items)))
  File "C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site-packages\pydavinci\utils.py", line 9, in get_resolveobjs
    return [x._obj for x in objs]
  File "C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site-packages\pydavinci\utils.py", line 9, in <listcomp>
    return [x._obj for x in objs]
AttributeError: 'function' object has no attribute '_obj'

Desktop (please complete the following information):

  • OS: Windows 10
  • Python Version: 3.6.8
  • Davinci Resolve Version: 18.0.4 BUILD 5

Additional context
Sorry if I'm just missing something obvious here! create_fusion_clip takes in List[TimelineItem], and timelineItems is typeof List[TimelineItem], so I figure this should work.

Missing `timeline.settings.timecode` property setter

timeline.settings._obj.GetCurrentTimecode() to get the current playhead position
timeline.settings._obj.SetCurrentTimecode('01:00:20:00') to move it to the specified position

Also @MarcoP91 not sure if you're aware, but PyDavinci's timecode property is Resolve's Get/SetCurrentTimecode. I noticed the property setter is missing though, so I've added that ready for the next release, but it should be as easy as:

timeline.settings.timecode to get current playhead position
timeline.settings.timecode = "01:00:20:00" to set it ๐Ÿ˜„

Originally posted by @in03 in #27 (comment)

Create New Track

Hi,

I'm trying to use this to watermark clips. I'm wondering if there's any functionality in here to create a new video track? I can't find anything in the documentation.

I'd also love if there was a way to speedramp? I Am using FFMPEG for this. Or even if there was a way to only add certain frames to timeline that would be good enough. Thank you

Settings validation error - DR18 beta only

They have changed the setting name from perfProxyMediaOn to perfProxyMediaMode.

  • Need to make old perfProxyMediaOna Optional[bool]

    proxy_media_on: bool = Field(alias="perfProxyMediaOn")

  • Test and add new perfProxyMediaMode, also making it Optional[Literal] for compatibility.
    The literals should be ['disable', 'prefer_proxies', 'prefer_originals'], mapped to "0", "1", "2" through a validator, respectively.

Error installing pydavinci due to pydantic dependency

I've installed Python 3.6 and when I try to do "pip install pydavinci" I'm getting the following:

Collecting pydantic==1.9.0 (from pydavinci)
Could not find a version that satisfies the requirement pydantic==1.9.0 (from pydavinci) (from versions: 0.0.1, 0.0.2, 0.0.3, 0.0.4, 0.0.5, 0.0.6, 0.0.7,
0.0.8, 0.1, 0.2, 0.2.1, 0.3, 0.4, 0.5, 0.6, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.7, 0.7.1, 0.8, 0.9, 0.9.1, 0.10, 0.11, 0.11.1, 0.11.2, 0.12, 0.12.1, 0.13, 0.13.
1, 0.14, 0.15, 0.16, 0.16.1, 0.17, 0.18, 0.18.1, 0.18.2, 0.19, 0.20a1, 0.20, 0.20.1, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27a1, 0.27, 0.28, 0.29, 0.30, 0.
30.1, 0.31, 0.31.1, 0.32, 0.32.1, 0.32.2, 1.0b1, 1.0b2, 1.0, 1.1, 1.1.1, 1.2, 1.3, 1.4, 1.5, 1.5.1, 1.6, 1.6.1, 1.6.2, 1.7, 1.7.1, 1.7.2, 1.7.3, 1.7.4)
No matching distribution found for pydantic==1.9.0 (from pydavinci)

Can we add Effects into timelime?

Is your feature request related to a problem? Please describe.
NO

Describe the solution you'd like
Add Effects into timelime using code.

Additional context
For example, can we add Title or Effects into timeline?
image

Support Resolve 18

Also I'm running Resolve 18 atm and so far works a charm. I do like to develop using poetry though, which doesn't allow ignoring required python version unfortunately... so I'm running my projects off my own fork of pydavinci atm. I suppose the only way to juggle support for 17 and 18 without having separate packages is to check at runtime?

Originally posted by @in03 in #18 (comment)

Unable to use GetProductName function

There is a function GetProductName that should be available.

I use a hack to support launching my script from both pycharm and dr py3 console. See it here

It is only about already having the resolve object in dr py3 while not having it immediately in pycharm.

After that point I am sure I have resolve object. And then I can use product = resolve.GetProductName().

However, with your library, I do not have it:

from pydavinci import davinci
resolve = davinci.Resolve()
product = resolve.GetProductName()
# AttributeError: 'Resolve' object has no attribute 'GetProductName'

Desktop (please complete the following information):

  • OS: Arch
  • Python Version: 3.6.11
  • Davinci Resolve Version: 18.0b1

Can't read files containing emoji after interacting with pydavinci & while DaVinci Resolve is open

Hi Pedro & @in03,

Bit of a weird one I've come across. Hoping you can help me to identify if this is something in my environment, or an actual bug, and where it might be located.

Describe the bug
With a pydavinci Resolve object established and DaVinci Resolve open, reading files via open() or YAML will be done using ASCII decoder. Instead of UTF8 decoder.

Therefore if there is Emojis in the file, UnicodeDecodeError is thrown.

This occurs only when Resolve is open - and therefore the Resolve API is accessible. When Resolve is not open, the file is read correctly as UTF8.

To Reproduce
Steps to reproduce the behavior:

Python 3.6:

% pyenv which python
/Users/data/.pyenv/versions/3.6.15/bin/python
% python test.py                                                   
Begin: โœ… Emoji on stdout
---
Try to load simple file as string
    data.txt: โœ…โœ…โœ… data !! โœ…โœ…โœ…
---
Try to load YAML file with emojis
{'normal_string': 'text here', 'string_with_emojis': 'โœ…โœ…โœ…'}
---
Try to import pydavinci
Imported pydavinci.
โœ… Emoji after pydavinci import
---
Try to create a Resolve object/contact API
Resolve (0x0x11a90f718) [App: 'Resolve' on 127.0.0.1, UUID: 5bb9cd9e-6912-4337-ab06-280f3effba0f]
โœ… Emoji after printing Resolve obj
---
Try to load simple file as string again
Traceback (most recent call last):
  File "test.py", line 31, in <module>
    print('data.txt:', stream.read())
  File "/Users/data/.pyenv/versions/3.6.15/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

The result with implementation specific option: -X utf8:
Same UnicodeDecodeError.

Python 3.10:
With an environment of Python 3.10, pydavinci@resolve18 0.3.1, and pyyaml 6.0.1.
Also have DaVinci Resolve open.

% pyenv which python
/Users/data/.pyenv/versions/3.10.10/bin/python
% python test.py
...
Try to load simple file as string again
Traceback (most recent call last):
  File "test.py", line 31, in <module>
    print('data.txt:', stream.read())
  File "/Users/data/.pyenv/versions/3.6.15/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

The result with -X utf8:

% python -X utf8 test.py
...
Try to load simple file as string again
data.txt: โœ…โœ…โœ… data !! โœ…โœ…โœ…
โœ… Emoji after reading back a file
---
Try to load emojis again...
{'normal_string': 'text here', 'string_with_emojis': 'โœ…โœ…โœ…'}
โœ… Emoji after safe loading yaml file
---

Expected behavior
Be able to read a UTF-8 file containing emojis and other characters - both via builtin open() and YAML.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Intel-based MacBook Pro 16" - macOS Monterey 12.6.5
  • Python Version - 3.6 and 3.10 as above. Using Pyenv.
  • Davinci Resolve Version - 18.6.4 Build 6

Also reproduced on a Mac Mini (M1, 2020) with macOS Sonoma 14.2, Resolve 18.6.4 and a similar pyenv environment.

Additional context
I am writing an app to watch Resolve render job events and send notifications. Notification text is stored in an external user config file in YAML format. Ideally I am able to read text from this file that contains emojis, and use it within the app/send notifs.

markers.find_all to support color

Is your feature request related to a problem? Please describe.
The markers.find_all doesn't support a needle based on the marker color. If you need all the marker's of certain color you have to do the filtering in a loop in the code.

Describe the solution you'd like
Add support for finding based on color to MarkerCollection.find() & MarkerCollection.find_all().

marker.py:144&158
if needle == marker.note or needle == marker.name or needle == marker.customdata or needle == marker.color:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.