How to Trim a TimelineItem with the DaVinci Resolve Python API
Test SetStart, SetEnd, SetLeftOffset, and SetRightOffset defensively when changing clip boundaries
Find a video TimelineItem, read its current boundaries, and attempt a controlled trim using whichever TimelineItem boundary methods are exposed by the installed Resolve scripting version.
API
Resolve Scripting API
Language
Python
Resolve
19–20+
Requires
Running Resolve
Syntax
item.SetStart(new_start)
item.SetEnd(new_end)Parameters
- • The relevant arguments are shown in the complete working example below. Validate paths, object types, and required project state before calling the API method.
Returns
Always validate the returned object, list, identifier, or boolean before continuing to the next automation step.
import os
import sys
from pathlib import Path
def import_resolve_module():
try:
import DaVinciResolveScript as dvr
return dvr
except ImportError:
search_paths = [
os.environ.get("RESOLVE_SCRIPT_API", ""),
os.environ.get("RESOLVE_MODULES", ""),
r"C:\\ProgramData\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting\\Modules",
"/opt/resolve/Developer/Scripting/Modules",
"/opt/BlackmagicDesign/DaVinciResolve/Developer/Scripting/Modules",
"/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules",
str(Path.home() / "Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting/Modules"),
]
for path in search_paths:
if path and os.path.isdir(path) and path not in sys.path:
sys.path.append(path)
import DaVinciResolveScript as dvr
return dvr
def safe_call(obj, name, *args, **kwargs):
try:
fn = getattr(obj, name, None)
if callable(fn):
return fn(*args, **kwargs)
except Exception:
return None
return None
def get_project_and_timeline():
dvr = import_resolve_module()
resolve = dvr.scriptapp("Resolve")
if not resolve:
raise RuntimeError("DaVinci Resolve API is unavailable")
project_manager = resolve.GetProjectManager()
project = project_manager.GetCurrentProject() if project_manager else None
if not project:
raise RuntimeError("No DaVinci Resolve project is open")
timeline = project.GetCurrentTimeline()
if not timeline:
raise RuntimeError("No active Timeline")
return resolve, project, timeline
def trim_item(item, new_start: int | None = None, new_end: int | None = None) -> bool:
changed = False
if new_start is not None:
if safe_call(item, "SetStart", int(new_start)):
changed = True
else:
current_start = int(safe_call(item, "GetStart") or 0)
offset = max(0, int(new_start) - current_start)
if offset and safe_call(item, "SetLeftOffset", offset):
changed = True
if new_end is not None:
if safe_call(item, "SetEnd", int(new_end)):
changed = True
else:
current_end = int(safe_call(item, "GetEnd") or 0)
offset = max(0, current_end - int(new_end))
if offset and safe_call(item, "SetRightOffset", offset):
changed = True
return changed
def first_video_item(timeline):
track_count = int(safe_call(timeline, "GetTrackCount", "video") or 0)
for track_index in range(1, track_count + 1):
items = safe_call(timeline, "GetItemListInTrack", "video", track_index) or []
if items:
return items[0]
return None
resolve, project, timeline = get_project_and_timeline()
item = first_video_item(timeline)
if not item:
raise RuntimeError("No clips were found on video tracks")
start = int(safe_call(item, "GetStart") or 0)
end = int(safe_call(item, "GetEnd") or 0)
# Example: shorten the first video clip by 12 frames on each side.
ok = trim_item(item, new_start=start + 12, new_end=end - 12)
print("Trim applied:", ok)
Guide
What the example does
The script selects the first video item it can find, reads its current start and end, then tries to move both boundaries inward by 12 frames. It attempts direct SetStart/SetEnd calls first and then tries offset-based methods as a compatibility fallback.
Why the helper tests more than one method
TimelineItem mutation support has varied across Resolve scripting releases. A robust bridge should check method availability and return values instead of assuming a trim call succeeded. That makes version-specific behavior visible to the caller.
How to use the pattern in a real workflow
In production, new_start and new_end would normally come from a validated edit plan, silence detector, transcript cleanup pass, or another analysis step. The sample uses a fixed 12-frame trim only to keep the mutation easy to understand and verify.
How the example works
Connect to Resolve
Establish a Resolve Scripting API connection and stop early if the application object is unavailable.
Validate the current context
Check the active project, Timeline, Media Pool, source paths, or Render Queue state required by this specific operation.
Run the core API operation
Execute the operation demonstrated in this guide: how to trim a timelineitem with the davinci resolve python api.
Validate the result
Check the returned value before the workflow continues. Resolve methods often signal an unavailable object or failed operation with None, False, or an empty result.
Resolve API notes
- Trim operations modify the Timeline; test them on a duplicate Timeline or project.
- Some item types may not support SetStart, SetEnd, or offset methods.
- Never allow a calculated new_end to become less than or equal to new_start.
- Check the returned success state before applying the next dependent operation.
Common errors
Resolve API is unavailable
Reason: Resolve is closed or Python cannot import/use DaVinciResolveScript.
Fix: Start Resolve and verify the Developer/Scripting/Modules path from the same Python interpreter used by the script.
The method returns None or False
Reason: A required project, Timeline, clip, preset, path, or application state is missing.
Fix: Validate each input and add explicit result checks after important Resolve API calls.
The script only works on one workstation
Reason: Paths or environment assumptions are hard-coded for a single operating system or machine.
Fix: Move paths into configuration and support the required Windows, Linux, and macOS locations explicitly.
Next step
Continue only after the current operation has returned the expected Resolve object or result.
Related API guides
Timeline
How to Delete Timeline Clips with the DaVinci Resolve Python API
Locate an item on the active Timeline by its start and end frame positions, verify that DeleteClips is available, and delete only the TimelineItem that matches the requested range.
Timeline
How to Build a Timeline Clip Map with the DaVinci Resolve API
Build a technical map of the active Timeline containing media type, track number, clip name, start, end, duration, and source file path when a linked MediaPoolItem is available.
Timeline
How to Split a Clip at an Exact Frame in DaVinci Resolve with Python
Use the Scripting API to verify that a clip crosses the requested frame and move the playhead there, then trigger Resolve's native split command as a practical fallback when a direct SplitClip API method is unavailable.

