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!