VEGAS oldMedia.ReplaceWith(newMedia) (VEGASPython)

xjirj22 wrote on 11/30/2020, 10:42 AM

Dear All,

I am testing to replace three videos (HD to UHD), later just with one...

    def isSibling(media): #Short one
        return PureWindowsPath(media.FilePath) #return path object or None

    def isVideo(media):
        isVideo = False
        if media.HasVideo() and not media.IsGenerated():
            isVideo = True
        return isVideo
    
    mediaPool = pyVEGAS.Project.MediaPool
    for media in mediaPool:
        sibling = isSibling(media)
        if isVideo(media) and sibling!=None:
            print(media.FilePath, str(sibling), sep=" - ")
            newMedia = Media(str(sibling))
            media.ReplaceWith(newMedia)
            # pyVEGAS.WaitForIdle() - The Clash - Should I Stay or Should I Go... ;-)
        else:
            print("Nothing to do.")

I read Media ReplaceWith works in script but not in extension. I guess that Harold-Linke crumbled VEGASPython to UndoBlock mentioned by jetdv already (I can see the undo step).

First media is replaced in MediaBin and then I am hitted ...

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ScriptPortal.Vegas.IMediaPoolIterator.MoveNext(Boolean& atEnd)
   at ScriptPortal.Vegas.MediaPoolEnumerator.MoveNext()
   at Python.Runtime.Iterator.tp_iternext(IntPtr ob)
   at Python.Runtime.Runtime.PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw)
   at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw)
   at Python.Runtime.PyObject.InvokeMethod(String name, PyTuple args, PyDict kw)
   at Python.Runtime.PyObject.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
   at CallSite.Target(Closure , CallSite , Object , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
   at VegasPython.VEGASPythonManager.Execute_VPython_File_PN(String module, String fileName, List`1 sysargs)
*******************************************
   at ScriptPortal.Vegas.IMediaPoolIterator.MoveNext(Boolean& atEnd)
   at ScriptPortal.Vegas.MediaPoolEnumerator.MoveNext()
   at Python.Runtime.Iterator.tp_iternext(IntPtr ob)
   at Python.Runtime.Runtime.PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw)
   at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw)
   at Python.Runtime.PyObject.InvokeMethod(String name, PyTuple args, PyDict kw)
   at Python.Runtime.PyObject.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
   at CallSite.Target(Closure , CallSite , Object , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
   at VegasPython.VEGASPythonManager.Execute_VPython_File_PN(String module, String fileName, List`1 sysargs)

 

I've already tested WaitForIdle() (Wait for asynchonous actions (such as building audio peaks) to complete.) without any success.

What I am doing wrong?

Best regards

Jan

Test PC: i7-5820K 3.30, 8GB RAM, W10 last updates, Vegas 18 build:373

Comments

jetdv wrote on 11/30/2020, 12:17 PM

Is it possible you're trying to go through the media pool list but you're changing the media pool list?

What if you read the media pool into an array or something and then process the array so you won't be trying to iterate through a changing list.

xjirj22 wrote on 11/30/2020, 3:17 PM

Dear jetdv,

thank you again.

Jan

    def isVideo(media):
        isVideo = False
        if media.HasVideo() and not media.IsGenerated():
            isVideo = True
        return isVideo

    def mediaToChange():
        mediaPool = pyVEGAS.Project.MediaPool
        mediaToChange = []
        for media in mediaPool:
            sibling = isSibling(media)
            if isVideo(media) and sibling!=None:             
                mediaToChange.append((media.FilePath, str(sibling)))
        return mediaToChange
    
    paths = mediaToChange()
    if len(paths) == 0:
        print("Nothing to do.")
        
    mediaPool = pyVEGAS.Project.MediaPool
    for path in paths:
        oldMedia = mediaPool.Find(path[0])
        newMedia = Media(path[1])
        oldMedia.ReplaceWith(newMedia)

 

jetdv wrote on 12/1/2020, 7:56 AM

Glad to hear that fixed it for you. Trying to progress through a changing list is never a good thing so it's always best to just pull out the entire list and then process it as needed.

xjirj22 wrote on 12/1/2020, 2:02 PM

When You mentioned it (Is it possible you're trying to go through the media pool list but you're changing the media pool list?), I felt bad, how could I do it.... changing the media pool while iterating through, common …;-) Sorry.

Sometimes one solves too many stupid small mistakes to oversee the big one.

Thank You for Your continuous and fast friendly replies. I have some other ideas to solve with Vegas scripting,

jetdv - I’ll be back... ;-)