Python Scripting Grab a Clip.

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

gkuchera

  • Posts: 4
  • Joined: Thu Jul 03, 2025 2:24 am
  • Real Name: Geoff Kuchera

Python Scripting Grab a Clip.

PostFri Jul 04, 2025 3:31 am

Is there a way through the API to grab a Clip of a defined length from a timeline?

I do Stock video and would love to be able to grab with a single key a 30second or 60second clip and add it to a sub clips directory.

i have been playing with the python API for a few days now and it seems like i have most of what i need, i just can't figure out how to create the sub clip.

Any help would be appreciated.

Thanks,
Geoff Kuchera
Offline

gkuchera

  • Posts: 4
  • Joined: Thu Jul 03, 2025 2:24 am
  • Real Name: Geoff Kuchera

Re: Python Scripting Grab a Clip.

PostFri Jul 04, 2025 12:18 pm

I would be happy to be able to do this in the viewer as well, since i just read that's where sub-clips are made. My goal here is to be able to go through a large amount of media and be able to quickly isolate clips of set sizes from the current play head location to that +30 or 60 Seconds that I can eventually put on a timeline and then export as individual clips later.

Trying to build a better workflow for this process.

Thanks,
Geoff
Offline

Christoph Schmid

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

Re: Python Scripting Grab a Clip.

PostFri Jul 04, 2025 3:07 pm

Unfortunately, there is no way to create subclips with the API.
What you can do is set Duration Markers.
You have individual access to them in the MediaPool in List view.
You can also set up a SmartBin to view them.

Davinci Resolve Studio 20.0.1 Build 6
Windows 10 Pro 22H2
Davinci Resolve Studio 19.1.4 Build 11
Linux Ubuntu Studio 24.04 (Rocky 8.6 Container)
Offline

gkuchera

  • Posts: 4
  • Joined: Thu Jul 03, 2025 2:24 am
  • Real Name: Geoff Kuchera

Re: Python Scripting Grab a Clip.

PostFri Jul 04, 2025 5:31 pm

Christoph Schmid wrote:Unfortunately, there is no way to create subclips with the API.
What you can do is set Duration Markers.
You have individual access to them in the MediaPool in List view.
You can also set up a SmartBin to view them.


Thanks i'll look into that.
Offline

gkuchera

  • Posts: 4
  • Joined: Thu Jul 03, 2025 2:24 am
  • Real Name: Geoff Kuchera

Re: Python Scripting Grab a Clip.

PostSun Jul 06, 2025 8:12 pm

So here is the script I came up with for anyone who is interested. I wanted a script that i could use to make grabbing stock bits out of video clips a little more efficient.

The script does the following:
    1. Based on the current location of the play head in the timeline, it places a duration marker on the clip with a default length of 30 seconds. It includes the word STOCK in the notes of the marker so you can create a Smart Bin to collect the picks.
    2. I also place a duration marker in the same place on the timeline, this gives you a visual representation of the beginning and end of the marked clip.
    3. if the length of the clip is less than the duration marker wants, the marker is placed from the current location to the end of the current clip. So, if you’re getting clips shorter than what you wanted it's likely because it ran into the end of the clip.
The Smart Bin I use is created as follows:
    1. Add Smart Bin
    2. Name: Stock Clips
    3. Match: MediaPool Properties; Marker Notes; Contains; STOCK

Let me know if you have any ideas on other ways to use the script. I have included it here:
You can change the default length of the marker by changing the variable default_len

There is also a lot of debug info incorporated in the file that can be turned on or off with the variable Debug. I left Debug on in the script.

The code to convert between time code and frames was written by someone else I found in a forum somewhere but lost the reference, so sorry i didn't give credit for that.

This script works well from the command line as well as from the script menu, I assigned it to the key F4 in the keyboard for the Edit page that seems to work well, unfortunately there is no way to define an argument to the script either on the script menu or the keyboard shortcut. (if i could use arguments i could define two or more keys to use the same script with different clip lengths)

Hope this helps someone,
Geoff Kuchera

You can find the script here: https://github.com/gkuchera/Davinci-Resolve-Scripts.git

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 61 guests