How to move a clip in timeline with the Python API?

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

kolibril13

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

How to move a clip in timeline with the Python API?

PostTue May 21, 2024 5:28 pm

Hi there!
I'm new to the scripting API, and I was wondering:
Is there a way I can shift the first clip in the timeline one second to the right?
I was able to write the below script, which takes the first clip in the timeline and scales it down to 0.8 by `first_clip.SetProperty("ZoomX", 0.8)` and that works fine.
However, shifting the clip to the right does not work.
The function first_clip.GetStart() gets the start time correctly.
However, there is no function first_clip.SetStart()
Furthermore, I've tried`first_clip.SetProperty("Start", new_start)` but that also did not work.
any other ideas? Would be really great if there was a possibility to move clips via the API :)

```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]

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

# Get the original start time of the clip
original_start = first_clip.GetStart()

# Calculate the new start time by shifting one second to the right
timeline_frame_rate = float(currentTimeline.GetSetting("timelineFrameRate"))
frames_to_shift = int(timeline_frame_rate) # Number of frames in one second
new_start = original_start + frames_to_shift

# Set the new start time for the clip using SetProperty
result = first_clip.SetProperty("Start", new_start)
print(f"Original start time: {original_start}")
print(f"New start time: {new_start}")
print(f"SetProperty result: {result}")

# 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.")
```

out:
```
Original start time: 216000
New start time: 216060
SetProperty result: False
Pan: 0.0
Tilt: 0.0
ZoomX: 0.8
ZoomY: 0.8
ZoomGang: True
RotationAngle: 0.0
AnchorPointX: 0.0
AnchorPointY: 0.0
Pitch: 0.0
Yaw: 0.0
FlipX: False
FlipY: False
CropLeft: 0.0
CropRight: 0.0
CropTop: 0.0
CropBottom: 0.0
CropSoftness: 0.0
CropRetain: False
DynamicZoomEase: 0
CompositeMode: 0
Opacity: 100.0
Distortion: 0.0
RetimeProcess: 0
MotionEstimation: 0
Scaling: 0
ResizeFilter: 0
```
Offline

csx333

  • Posts: 134
  • Joined: Thu Sep 26, 2019 10:15 am
  • Location: Germany
  • Real Name: Christoph Schmid

Re: How to move a clip in timeline with the Python API?

PostThu Jun 06, 2024 9:44 pm

kolibril13 wrote:result = first_clip.SetProperty("Start", new_start)


The property you are trying to set does not exist.

There is a “Start” property for MediaPoolItems, which is the start frame of the clip and not the position of the clip on the timeline. For example, the “Start” property of a subclip is the frame of the original clip at which the subclip begins.

As far as I know there is no easy way to move a clip on the timeline.

These are the Properties of a TimelineItem you can get or set:
"Pan" : floating point values from -4.0*width to 4.0*width
"Tilt" : floating point values from -4.0*height to 4.0*height
"ZoomX" : floating point values from 0.0 to 100.0
"ZoomY" : floating point values from 0.0 to 100.0
"ZoomGang" : a boolean value
"RotationAngle" : floating point values from -360.0 to 360.0
"AnchorPointX" : floating point values from -4.0*width to 4.0*width
"AnchorPointY" : floating point values from -4.0*height to 4.0*height
"Pitch" : floating point values from -1.5 to 1.5
"Yaw" : floating point values from -1.5 to 1.5
"FlipX" : boolean value for flipping horizontally
"FlipY" : boolean value for flipping vertically
"CropLeft" : floating point values from 0.0 to width
"CropRight" : floating point values from 0.0 to width
"CropTop" : floating point values from 0.0 to height
"CropBottom" : floating point values from 0.0 to height
"CropSoftness" : floating point values from -100.0 to 100.0
"CropRetain" : boolean value for "Retain Image Position" checkbox
"DynamicZoomEase" : A value from the following constants
- DYNAMIC_ZOOM_EASE_LINEAR = 0
- DYNAMIC_ZOOM_EASE_IN
- DYNAMIC_ZOOM_EASE_OUT
- DYNAMIC_ZOOM_EASE_IN_AND_OUT
"CompositeMode" : A value from the following constants
- COMPOSITE_NORMAL = 0
- COMPOSITE_ADD
- COMPOSITE_SUBTRACT
- COMPOSITE_DIFF
- COMPOSITE_MULTIPLY
- COMPOSITE_SCREEN
- COMPOSITE_OVERLAY
- COMPOSITE_HARDLIGHT
- COMPOSITE_SOFTLIGHT
- COMPOSITE_DARKEN
- COMPOSITE_LIGHTEN
- COMPOSITE_COLOR_DODGE
- COMPOSITE_COLOR_BURN
- COMPOSITE_EXCLUSION
- COMPOSITE_HUE
- COMPOSITE_SATURATE
- COMPOSITE_COLORIZE
- COMPOSITE_LUMA_MASK
- COMPOSITE_DIVIDE
- COMPOSITE_LINEAR_DODGE
- COMPOSITE_LINEAR_BURN
- COMPOSITE_LINEAR_LIGHT
- COMPOSITE_VIVID_LIGHT
- COMPOSITE_PIN_LIGHT
- COMPOSITE_HARD_MIX
- COMPOSITE_LIGHTER_COLOR
- COMPOSITE_DARKER_COLOR
- COMPOSITE_FOREGROUND
- COMPOSITE_ALPHA
- COMPOSITE_INVERTED_ALPHA
- COMPOSITE_LUM
- COMPOSITE_INVERTED_LUM
"Opacity" : floating point value from 0.0 to 100.0
"Distortion" : floating point value from -1.0 to 1.0
"RetimeProcess" : A value from the following constants
- RETIME_USE_PROJECT = 0
- RETIME_NEAREST
- RETIME_FRAME_BLEND
- RETIME_OPTICAL_FLOW
"MotionEstimation" : A value from the following constants
- MOTION_EST_USE_PROJECT = 0
- MOTION_EST_STANDARD_FASTER
- MOTION_EST_STANDARD_BETTER
- MOTION_EST_ENHANCED_FASTER
- MOTION_EST_ENHANCED_BETTER
- MOTION_EST_SPEED_WRAP
"Scaling" : A value from the following constants
- SCALE_USE_PROJECT = 0
- SCALE_CROP
- SCALE_FIT
- SCALE_FILL
- SCALE_STRETCH
"ResizeFilter" : A value from the following constants
- RESIZE_FILTER_USE_PROJECT = 0
- RESIZE_FILTER_SHARPER
- RESIZE_FILTER_SMOOTHER
- RESIZE_FILTER_BICUBIC
- RESIZE_FILTER_BILINEAR
- RESIZE_FILTER_BESSEL
- RESIZE_FILTER_BOX
- RESIZE_FILTER_CATMULL_ROM
- RESIZE_FILTER_CUBIC
- RESIZE_FILTER_GAUSSIAN
- RESIZE_FILTER_LANCZOS
- RESIZE_FILTER_MITCHELL
- RESIZE_FILTER_NEAREST_NEIGHBOR
- RESIZE_FILTER_QUADRATIC
- RESIZE_FILTER_SINC
- RESIZE_FILTER_LINEAR

Davinci Resolve Studio 18.6.6
Windows 10 Pro 22H2
Davinci Resolve Studio 19.0B33
Linux Ubuntu Studio 24.04

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 3 guests