Page 1 of 1

Workflow Integration: replace a timelineItem's mediapoolItem

PostPosted: Thu Dec 29, 2022 1:36 pm
by Nowadays
I have a timelineItem that points to a certain mediaPoolItem, for example:

Code: Select all
...
const timelineItem = currentTimeline.GetItemListInTrack('audio', 1)[0]
const mediaPoolItem = timelineItem.GetMediaPoolItem()


I would like to change the mediaPoolItem pointed by the timelineItem with another one, say timelineItem.SetMediaPoolItem(...), but apparently there's no way to do it via API. Am I missing something? If not, is there a plan to add such function in the future?

Re: Workflow Integration: replace a timelineItem's mediapool

PostPosted: Thu Jan 04, 2024 9:18 am
by andrejal
I'm trying to solve a similar problem. I imported media items and set theirs name so it matches the ones in the .edl
Code: Select all
        mediaItem = mediaPool.ImportMedia(str(Path(mediaFile)))[0]
        mediaItem.SetClipProperty("Clip Name", shotName)


Than I import the .edl timeline, but the clips don't automatically link to the. Each is marked with "Media Offline"

Code: Select all
    timeline = mediaPool.ImportTimelineFromFile(
        edlPath,
        {
            "timelineName": "Conform Timeline",
            "importSourceClips": True,
            "sourceClipsFolders": [rootFolder]
        },
    )


I would also like to know how I can set a specific media entity to be linked to the pre-existing item on the timeline. :?:

Re: Workflow Integration: replace a timelineItem's mediapool

PostPosted: Wed Jan 10, 2024 4:08 pm
by philipbowser
There isn't a direct way to do this. But I've found that you can kind of use the take system in a bit of a hacky way. You basically add the new mediaPoolItem as a take to the timelineItem and then finalize the take.

I don't have the time to write out full code and test it (I also don't work with Python that often), but you can do something along the lines of this:
Code: Select all
timelineItem.AddTake(mediaPoolItem, startFrame, endFrame)
idx = timelineItem.GetTakesCount()
timelineItem.SelectTakeByIndex(idx)
timelineItem.FinalizeTake()

This will retain any clip transforms and effects applied, with one pretty huge caveat: retiming. Any clips that have been retimed cannot use the take system, so adding takes won't work. And within Resolve there is no easy way to determine if a clip has been retimed at all. The only way I have found to determine if a clip has been retimed is to export a temporary OTIO timeline to disk, read that in with a JSON parser library, then iterate through the OTIO clips until you find your matching clip and see if there are any retime effects applied to it. But I guess doing that won't really help you replace the clips, just let you know which ones will fail.

If you don't need to keep any effects / transforms, then you can always delete the timelineItem and add the new mediaPoolItem to the same spot. You'd use timeline.DeleteClips(timelineItem, false) and mediaPool.AppendToTimeline(clipInfo).

Hopefully this helps and if you find any other ways around this I'd be interested to know!

Re: Workflow Integration: replace a timelineItem's mediapool

PostPosted: Sun Mar 10, 2024 7:35 am
by DaveZap
Hi,

I'm also needing the mediaPool.ImportTimelineFromFile() function to respect the importOptions importSourceClips option.

It's a documented feature that is not working so clearly this is a bug. Can it please be escalated to the dev team to look at?

I've tried with every timeline timeline file type and they either import nothing or only the clips without the media.

I'm trying to target OTIO timelines in my application.

Thanks

David

Re: Workflow Integration: replace a timelineItem's mediapool

PostPosted: Mon Mar 11, 2024 6:06 am
by DaveZap
Forgive me, I upgraded from 18.6.4 to 18.6.5 and my issue is now Resolved (get it).

I can now import my OTIO timeline and have the clips imported correctly to the Media Pool.

Code: Select all
project_manager = resolve.GetProjectManager()
project = project_manager.GetCurrentProject()
mediaPool = project.GetMediaPool()
rootFolder = mediaPool.GetRootFolder()

timeline_file_path = "C:/path/to/timeline.json.otio"
importedTimelineClip = mediaPool.ImportTimelineFromFile(timeline_file_path,
        {
            "timelineName": "timeline",
            "importSourceClips": True,
            "sourceClipsFolders": [rootFolder]
        })


It still does not import the Fusion Comp's though like I was discussing in this thread.
https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=196808

But this is great progress.

David