Python - Import clips with .AddItemsToMediaPool

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline

jensenni

  • Posts: 23
  • Joined: Wed Jan 27, 2021 12:26 am
  • Real Name: Jens Klein

Python - Import clips with .AddItemsToMediaPool

PostTue Feb 02, 2021 11:59 am

Hi. I am working on some automation for DVR and got the following issue. I have a .txt file that contains python created links to clips (with the full path) for import into resolve. Like this:

clip_import.txt
Code: Select all
'/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2002_C0127/FW_A01_2021-12-12_2002_C0127_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0129/FW_A01_2021-12-12_2003_C0129_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0130/FW_A01_2021-12-12_2003_C0130_000000.dng',

I am loading the .txt file as follows: (python 3.6.8)
Code: Select all
# Read the search result clipList
with open("/Volumes/audio/TRANSCRIBE/SearchPhrases/" + searchPhrase + ".txt") as f:
    clipListRead = f.readlines()
    print('cliplistRead: ' + str(clipListRead))

Here is the OUTPUT:
Code: Select all
["'/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2002_C0127/FW_A01_2021-12-12_2002_C0127_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0129/FW_A01_2021-12-12_2003_C0129_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0130/FW_A01_2021-12-12_2003_C0130_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0131/FW_A01_2021-12-12_2003_C0131_000000.dng', "]

I created a variable called clipListRead (see above) and plugged that into the code below:
Code: Select all
clips = resolve.GetMediaStorage().AddItemsToMediaPool(clipListRead)

But that does not work for some reason. My question is: Do I need to create an object or an array to make this work? Or is this a DVR API issue? Any other tricks to this? The focus seems to be on what can be plugged into that function provided by the DVR API. AddItemsToMediaPool(??????). I couldn't find anything in the docs so far.
As a note, the same code below (path filled in by hand) works fine and is the correct format to import the two clips into resolve.
Code: Select all
clips = resolve.GetMediaStorage().AddItemsToMediaPool('/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A0_C0135/FW_A0_C0135_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A0_C0135/FW_A0_C0135_000000.dng',)


Thank you!
MacOS 10.13.2. | DVR v15.3.1 | Python 3.6.8
Last edited by jensenni on Tue Feb 02, 2021 4:49 pm, edited 1 time in total.
Offline

pperquin

  • Posts: 23
  • Joined: Thu May 23, 2019 8:31 am
  • Location: France
  • Real Name: philippe perquin

Re: Python - Import clips with .AddItemsToMediaPool

PostTue Feb 02, 2021 3:11 pm

hi,

have you try something like :

for oneClip in clipListRead:
clips = resolve.GetMediaStorage().AddItemsToMediaPool(clipListRead)
Philippe Perquin
https://news.afp.com/, https://www.afptvlive.com/
Offline

jensenni

  • Posts: 23
  • Joined: Wed Jan 27, 2021 12:26 am
  • Real Name: Jens Klein

Re: Python - Import clips with .AddItemsToMediaPool

PostTue Feb 02, 2021 4:01 pm

Hi, Philippe. I just tried that. Unfortunately, it didn't work. But no error messages either :) Thank you for looking into this though! -- It might be possible that the new API (Davinci Resolve) has some limitations - but there is not enough documentation available to tell for sure. It's a real petty because all other parts of the script are working really well -- I just can't get over that last hurdle...
Offline

pperquin

  • Posts: 23
  • Joined: Thu May 23, 2019 8:31 am
  • Location: France
  • Real Name: philippe perquin

Re: Python - Import clips with .AddItemsToMediaPool

PostTue Feb 02, 2021 4:44 pm

hi,

i make an error with the copy paste the good one is :

for oneClip in clipListRead:
clips = resolve.GetMediaStorage().AddItemsToMediaPool(oneClip)
Philippe Perquin
https://news.afp.com/, https://www.afptvlive.com/
Offline

Shrinivas Ramani

Blackmagic Design

  • Posts: 3030
  • Joined: Wed Sep 20, 2017 10:19 am

Re: Python - Import clips with .AddItemsToMediaPool

PostTue Feb 02, 2021 5:29 pm

Jens
In your code, printing this gives you a list with one line.
Code: Select all
str(clipListRead)

   ==> list with one str

["<--start of str     '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2002_C0127/FW_A01_2021-12-12_2002_C0127_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0129/FW_A01_2021-12-12_2003_C0129_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0130/FW_A01_2021-12-12_2003_C0130_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0131/FW_A01_2021-12-12_2003_C0131_000000.dng',       end of str-->"]
You want to either format your file in a way that produces the proper list (e.g separate lines) - or split in python using comma.
Offline

jensenni

  • Posts: 23
  • Joined: Wed Jan 27, 2021 12:26 am
  • Real Name: Jens Klein

Re: Python - Import clips with .AddItemsToMediaPool

PostTue Feb 02, 2021 8:06 pm

Philippe, you did it!

I'll mark this as solved, even though it's still not reading in. But the path is now absolutely correct and this might be an issue with the API. I am not sure what Blackmagic needs to plug-in correctly (array, object, etc). Not sure.

Great job, Philippe!
Last edited by jensenni on Tue Feb 02, 2021 8:25 pm, edited 1 time in total.
Offline

jensenni

  • Posts: 23
  • Joined: Wed Jan 27, 2021 12:26 am
  • Real Name: Jens Klein

Re: Python - Import clips with .AddItemsToMediaPool

PostTue Feb 02, 2021 8:25 pm

Shrinivas Ramani wrote:Jens
In your code, printing this gives you a list with one line.
Code: Select all
str(clipListRead)

   ==> list with one str

["<--start of str     '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2002_C0127/FW_A01_2021-12-12_2002_C0127_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0129/FW_A01_2021-12-12_2003_C0129_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0130/FW_A01_2021-12-12_2003_C0130_000000.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_2021-12-12_2003_C0131/FW_A01_2021-12-12_2003_C0131_000000.dng',       end of str-->"]
You want to either format your file in a way that produces the proper list (e.g separate lines) - or split in python using comma.



Hi Shrinivas, the path is now correct. If I copy-paste the output path list directly into AddItemsToMediaPool(xxxx) it works. However, plugging in anything else does not work - please see below.
Is there a trick to this :)?

Code: Select all
# Import clips from searchPhrase result
# TODO: clipList var is not working yet. Seems a API issue in DVRv15? We'll try DVRv16.
for oneClip in clipListRead:
    clips = resolve.GetMediaStorage().AddItemsToMediaPool(oneClip)  # <-- clipList goes here
    print(end='\n')  # <-- command line spacer:)
    print("oneClip: " + str(oneClip))


best regards
Jens

macOS 10.13.2 | Python 3.6.8 | DVR 15.3.1
Offline

pperquin

  • Posts: 23
  • Joined: Thu May 23, 2019 8:31 am
  • Location: France
  • Real Name: philippe perquin

Re: Python - Import clips with .AddItemsToMediaPool

PostTue Feb 02, 2021 9:49 pm

hi jensenni,

What are you trying to make when you say 'even though it's still not reading in' ?

Can you explain your scrip ?

regards,
Philippe Perquin
https://news.afp.com/, https://www.afptvlive.com/
Offline

jensenni

  • Posts: 23
  • Joined: Wed Jan 27, 2021 12:26 am
  • Real Name: Jens Klein

Re: Python - Import clips with .AddItemsToMediaPool

PostWed Feb 03, 2021 11:16 am

pperquin wrote:hi jensenni,

What are you trying to make when you say 'even though it's still not reading in' ?

Can you explain your scrip ?

regards,


What I meant is that I believe it has probably something to do with the API. Your ideas from yesterday worked but the function 'AddItemsToMediaPool(oneClip)' seems to be the issue -- it's just really hard to tell as there isn't any useful documentation about what we are supposed to plugin here. I checked the output again and it's now the correct path but for some reason, it's not working within that function... as for the idea itself, I am building a PhraseFind option for DavinciResolve for a film we are doing currently -- we have over 1200 film scenes and all of them are searchable for phrases spoken by actors -- super cool :) - once it's done I want to share that with the DavinciResolve community as a plugin -- well, that's the idea. I am happy to share the source code with you if you're interested...
Offline

pperquin

  • Posts: 23
  • Joined: Thu May 23, 2019 8:31 am
  • Location: France
  • Real Name: philippe perquin

Re: Python - Import clips with .AddItemsToMediaPool

PostWed Feb 03, 2021 12:10 pm

hi,

you can also have a look to https://www.steakunderwater.com/wesuckl ... m.php?f=35 that is a good forum about programming.

regards,
Philippe Perquin
https://news.afp.com/, https://www.afptvlive.com/
Offline

jensenni

  • Posts: 23
  • Joined: Wed Jan 27, 2021 12:26 am
  • Real Name: Jens Klein

Re: Python - Import clips with .AddItemsToMediaPool

PostThu Feb 11, 2021 12:22 am

Thanks for the link. The site is great!

Return to DaVinci Resolve

Who is online

Users browsing this forum: Bing [Bot], dirk-pel, qsipher and 248 guests