Script works fine in v12, crashes v13

malowz wrote on 8/3/2014, 11:58 AM
hi, i modified a script that process media pool files, to replace original with proxy files for better editing.

it look for files with same name but different extensions to replace in the media pool. worked fine in v12. now in v13, it crashes vegas.

to test just need a file and another file with same name on a "Proxy" subfolder.

the crash happens at "mediaEnum.moveNext();", but i cant figure it out why...

any help appreciated


import System.Windows.Forms;
import Sony.Vegas;
import System.IO;

var clipNumber = 0;
try {


var mediaEnum = new Enumerator(Vegas.Project.MediaPool);
while (!mediaEnum.atEnd())
{
var media = mediaEnum.item();
var replaceFilePath = Path.GetDirectoryName(media.FilePath);

if (Directory.Exists(replaceFilePath + "\\Proxy"))
{

var replaceFileName = Path.GetFileNameWithoutExtension(media.FilePath);

var proxyFinder = (replaceFilePath + "\\Proxy\\" + replaceFileName)


if (File.Exists(proxyFinder + ".avi"))
{
var originalExtension = ".avi";
}
if (File.Exists(proxyFinder + ".mov"))
{
var originalExtension = ".mov";
}
if (File.Exists(proxyFinder + ".mp4"))
{
var originalExtension = ".mp4";
}
if (File.Exists(proxyFinder + ".mxf"))
{
var originalExtension = ".mxf";
}
if (File.Exists(proxyFinder + ".m2t"))
{
var originalExtension = ".m2t";
}
if (File.Exists(proxyFinder + ".mts"))
{
var originalExtension = ".mts";
}
if (File.Exists(proxyFinder + ".m2ts"))
{
var originalExtension = ".m2ts";
}
if (File.Exists(proxyFinder + ".ts"))
{
var originalExtension = ".ts";
}
if (File.Exists(proxyFinder + ".mpg"))
{
var originalExtension = ".mpg";
}

var newFileName = (proxyFinder + originalExtension);

var replaced = media.FilePath.Replace(media.FilePath, newFileName);
var newMedia = new Media(replaced);
media.ReplaceWith(newMedia);
clipNumber++;
}

mediaEnum.moveNext();
}
}
catch (e)
{
MessageBox.Show(e);
}

if (!clipNumber == 0) Vegas.Project.MediaPool.RemoveUnusedMedia();

if (!clipNumber == 0) Vegas.UpdateUI();

if (!clipNumber == 0) MessageBox.Show(" Eventos alterados para Proxy: " + clipNumber);

Comments

Rosebud wrote on 8/8/2014, 9:23 AM
It seem I have same problem with my script Proxy Stream which the Switch function don't work any more in VP13

Please SCS help us !

TIA
Warper wrote on 8/12/2014, 5:54 AM
You create new Media and then replace old one with new one. This operation can modify mediapool list that your script iterates on.
If list is modified, iterators can become invalid and MoveNext operation can stop working.
There are two workarounds:
1) Start iteration over from beginning each time you found and replaces media with proxy. It will increase algorythm complexity to O(n*n), where n is the number of media files in media pool. That is, script will be slower on very large media pools. Nevertheless it's safe as far as you don't modify already processed media.
To do it: add mediaEnum = new Enumerator(Vegas.Project.MediaPool); after "clipNumber++;" and put movenext line under else
2) You can try to save references to media objects beforehand in some javascript array and then go through that array instead of through mediapool.
It will be quicker, but can cause issues if mediapool is modified by anything else than your script.
malowz wrote on 9/11/2014, 9:28 PM
thanks Warper. used the "method 1" and now woks fine ;)