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: 6
  • 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: 6
  • 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: 946
  • 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: 6
  • 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: 6
  • 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
Offline

sushi ninja

  • Posts: 24
  • Joined: Tue Feb 14, 2023 8:01 am
  • Real Name: Satoru Taguchi

Re: Python Scripting Grab a Clip.

PostFri Jul 11, 2025 12:08 pm

Hi, gkuchera

Unkindly, the BMD does not use the word “subclip” in the script's README, though,
    MediaStorage.AddItemListToMediaPool ([{itemInfo}, ...])
    MediaPool.ImportMedia ([{clipInfo},...])

Subclips can be created using the above API.
There seems to be a way to use AddItemListToMediaPool for video files , and ImportMedia for still image sequences respectively.
Both have slightly different dict key names, but specify the file path, start frame and end frame.

Those specifications should be clearly stated...
Basically, I appreciate the software, and I think it's rather over-performed considering the price, but as far as the API is concerned, it's really incomplete.
Offline

Christoph Schmid

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

Re: Python Scripting Grab a Clip.

PostFri Jul 11, 2025 2:47 pm

Oh... nice! Thank you.
Sorry for the wrong information.

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: 6
  • Joined: Thu Jul 03, 2025 2:24 am
  • Real Name: Geoff Kuchera

Re: Python Scripting Grab a Clip.

PostFri Jul 11, 2025 10:26 pm

sushi ninja wrote:Hi, gkuchera

Unkindly, the BMD does not use the word “subclip” in the script's README, though,
    MediaStorage.AddItemListToMediaPool ([{itemInfo}, ...])
    MediaPool.ImportMedia ([{clipInfo},...])

Subclips can be created using the above API.
There seems to be a way to use AddItemListToMediaPool for video files , and ImportMedia for still image sequences respectively.
Both have slightly different dict key names, but specify the file path, start frame and end frame.

Those specifications should be clearly stated...
Basically, I appreciate the software, and I think it's rather over-performed considering the price, but as far as the API is concerned, it's really incomplete.


Yes i agree, my short time working with there API i have spent far more time trying to figure out ways around the short comings than actually producing functional scripts. Still love the software though. Hopefully if more people make requests they will improve the API. For now this does what i need or wanted. The other thing that would be nice is a way to pass arguments to a script through a keyboard shortcut. So i can create a generic script that can be setup on multiple keys and have different actions based on the arguments passed.

I'll have to play with what you suggested above at some point as well. The other thing that would be nice is better documentation for the API.

Thanks,
Geoff
Offline

gkuchera

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

Re: Python Scripting Grab a Clip.

PostFri Jul 11, 2025 10:29 pm

Christoph Schmid wrote:Oh... nice! Thank you.
Sorry for the wrong information.


No worries, your idea gave me the framework for what I created. Which works just fine for what i need at the moment. As I work with it more i will likely tune it and make it better. But part of the plan was to get more scripts out there for people to look at as examples. Because there really aren't very many that i could find...

Thanks,
Geoff Kuchera

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 6 guests