DaVinci Resolve API Issue: Managing Timeline Elements

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

SerhiiK

  • Posts: 4
  • Joined: Sat Mar 02, 2024 2:12 pm
  • Real Name: Serhii Kalinin

DaVinci Resolve API Issue: Managing Timeline Elements

PostSat Mar 02, 2024 2:14 pm

Hello everyone! I'm just starting to delve into scripting in DaVinci Resolve with Python and was initially amazed by the possibilities it opens up. However, the deeper I get, the more I encounter limitations and problems that prevent me from implementing my ideas. I've already spent a lot of time but haven't found a solution to my issues. Please help me figure this out.

One of the main problems I've faced is managing elements on the timeline. I need to move certain items along the timeline, but I don't understand how to do it properly. For instance, when I add two elements to the timeline, they are placed sequentially, one after the other. But I need one (a composition) to be on top of the other (a video), with both starting and ending simultaneously and having the same duration.

I've searched for solutions in the documentation, on YouTube, but haven't found a suitable answer. The only method that seems to work is editing the project's database through DB Browser for SQLite. Changes are applied after reloading the project, but this seems far from the best way.

I've also seen advice on using Python libraries to emulate mouse and keyboard actions to automate GUI interactions, but this seems to complicate the process and make it less reliable.

Therefore, I'm turning to experienced users: is it even possible to flexibly manage the placement and duration of clips on the timeline using the DaVinci Resolve API, perhaps through some hidden or undocumented functions? I would be grateful for any help and advice.
Offline

philipbowser

  • Posts: 274
  • Joined: Tue Oct 14, 2014 11:53 pm

Re: DaVinci Resolve API Issue: Managing Timeline Elements

PostMon Mar 11, 2024 3:56 pm

Hey Serhii,

I'm not an expert, but I may have enough info to help you out.

Unfortunately, you cannot "move" items on a timeline with the scripting API. However, you can add items to a timeline on any track, at any timecode, and for any duration, so you may not need to move clips to begin with.

The relevant method is:
Code: Select all
MediaPool.AppendToTimeline([{clipInfo}, ...])


You can read more about what "clipInfo" is in the documentation, but the basics are you need a dict / table of: mediaPoolItem, startFrame, endFrame, mediaType, trackIndex, and recordFrame.

If however you do need to "move" clips that are already on a timeline, the only way is to delete the old clip and append a new, identical clip to a different position using the above method. The downsides to this are that you cannot retain any clip effects as you'll be deleting the clip and the scripting API doesn't yet support reading or writing clip effects or keyframing any of the clip properties.
Offline

kolibril13

  • Posts: 6
  • Joined: Mon Apr 25, 2022 6:05 am
  • Real Name: Jan-Hendrik Müller

Re: DaVinci Resolve API Issue: Managing Timeline Elements

PostSat May 18, 2024 1:10 pm

I just tried this script:
```py
resolve = dvr_script.scriptapp("Resolve")

# Get the project manager and current project
projectManager = resolve.GetProjectManager()
currentProject = projectManager.GetCurrentProject()
media_pool = currentProject.GetMediaPool()
currentTimeline = currentProject.GetCurrentTimeline()

print(f"Current project: {currentProject.GetName()}")

# Find the media pool item for "test.png"
mediaPoolRoot = media_pool.GetRootFolder()
mediaPoolItems = mediaPoolRoot.GetClipList()
imageMediaPoolItem = None

for item in mediaPoolItems:
if item.GetName() == "test.png":
imageMediaPoolItem = item
break

clipInfo = {
"mediaPoolItem": imageMediaPoolItem,
"trackIndex": 2, # this works
"startFrame" : int(0), # this does not work
"endFrame" : int(20), # this does not work
}
media_pool.AppendToTimeline([clipInfo])
```
Offline

IIDavid

  • Posts: 2
  • Joined: Sun May 19, 2024 10:16 am
  • Real Name: David Danielsen

Re: DaVinci Resolve API Issue: Managing Timeline Elements

PostSun May 19, 2024 10:19 am

Could you please link me to some info about the database?

Maybe we could team up to make a solution, using the database, or something else.
I am trying to solve the exact same issue.

I want to move and resize things on the timeline.
Offline

kolibril13

  • Posts: 6
  • Joined: Mon Apr 25, 2022 6:05 am
  • Real Name: Jan-Hendrik Müller

Re: DaVinci Resolve API Issue: Managing Timeline Elements

PostTue May 21, 2024 4:46 pm

There's also a discussion on the unofficial Discord in #hangouts right now
Discord invite: https://discord.gg/blackmagic-design-co ... 4528647188
Message link: https://discord.com/channels/4792972545 ... 4694353008

Regarding your resize question: When you have a timeline, you can scale the first element like this
```py
import sys
sys.path.append('/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules')
import DaVinciResolveScript as dvr_script

# Initialize DaVinci Resolve scripting interface
resolve = dvr_script.scriptapp("Resolve")

# Get project manager and the current project
projectManager = resolve.GetProjectManager()
currentProject = projectManager.GetCurrentProject()

# Get the current timeline from the current project
currentTimeline = currentProject.GetCurrentTimeline()

# Get the number of video tracks in the timeline
video_track_count = currentTimeline.GetTrackCount("video")

# Retrieve the first clip in the first video track
if video_track_count > 0:
video_clips = currentTimeline.GetItemListInTrack("video", 1)
if video_clips:
first_clip = video_clips[0]

# Resize the clip by setting ZoomX and ZoomY to 0.8
first_clip.SetProperty("ZoomX", 0.8)
first_clip.SetProperty("ZoomY", 0.8)

# Verify that the properties have been updated
properties = first_clip.GetProperty()
for key, value in properties.items():
print(f"{key}: {value}")
else:
print("No clips found in the first video track.")
else:
print("No video tracks found in the timeline.")
```

cropping also works, see the screenshot for more options.

Moving elements I did not figure out
Attachments
image.png
image.png (265.25 KiB) Viewed 291 times

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 5 guests