MAGIX VEGAS: MAGIX Vegas Tutorials MAGIX Vegas Forum Articles Black Magic Design Forum AJA Xena Forum

directoryconverter.js errors

COW Forums : VEGAS Pro

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Todd Geer
directoryconverter.js errors
on Jan 21, 2009 at 8:23:23 pm

I have this "directoryconverter.js" from some time way in the past. I'm trying to run it in V Pro 8 and it errors out. Any pointers?

Error:

C:Program FilesSonyVegas Pro 8.0Script MenuMisc ScriptsDirectoryconverter.js(180) : Deprecated: Please use GetInvalidPathChars or GetInvalidFileNameChars instead.


The script:


---start
/**
* This script renders media files found in an input directory using a
* single render template and saves the results in an output
* directory. To change the input directory, output directory, and
* render template, edit the variables below.
*
* NOTE!!! This script requires Vegas 4.0c.
*
* Revision Date: May 01, 2003.
**/

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

// The inputDirectory variable specifies where the rendered files will
// be created (do not include the trailing back-slash)
var inputDirectory = "C:/TEMP/1";

// The outputDirectory variable specifies where the rendered files
// will be created (do not include the trailing back-slash)
var outputDirectory = "C:/TEMP/2";

// The rendererRegexp and templateRegexp variable are regular
// expressions used to match renderer file type names and template
// names.
var rendererRegexp = /Windows Media Video V9/;
var templateRegexp = /3 Mbps Video/;

// The inputFileRegexp is used to filter the input files. Only those
// whose file name matches using this regular expression will be
// converted. The following will match all files the end with avi
// (ignoring case):
var inputFileRegexp = /.avi$/i;

// This version will match all input files.
//var inputFileRegexp = /.*/;

// The overwriteExistingFiles variable determines whether or not it is
// OK to overwrite files that may already exist whose name is the same
// as ones created by running this script. For safety, the default is
// false. Set the variable to true to allow overwrites.
var overwriteExistingFiles = false;


try {

// make sure the output directory exists
if (!Directory.Exists(inputDirectory))
{
var msg = new StringBuilder("The input directory (");
msg.Append(outputDirectory);
msg.Append(") does not exist.n");
msg.Append("Please edit the script to specify an existing directory.");
throw msg;
}

// make sure the output directory exists
if (!Directory.Exists(outputDirectory))
{
var msg = new StringBuilder("The output directory (");
msg.Append(outputDirectory);
msg.Append(") does not exist.n");
msg.Append("Please edit the script to specify an existing directory.");
throw msg;
}

var renderer = FindRenderer(rendererRegexp);
if (null == renderer) {
throw "Failed to find renderer";
}

var renderTemplate = FindRenderTemplate(renderer, templateRegexp);
if (null == renderTemplate) {
throw "Failed to find render template";
}

var newExtension = renderer.FileExtension.substring(1);

// create a new project with one video track and one audio track.
var proj = new Project();

var videoTrack = new VideoTrack();
proj.Tracks.Add(videoTrack);

var audioTrack = new AudioTrack();
proj.Tracks.Add(audioTrack);

// save the new project to the output directory
//Vegas.SaveProject(Path.Combine(outputDirectory, "temp.veg"));

// enumerate the files in the input directory
var fileEnum = new Enumerator(Directory.GetFiles(inputDirectory));
while (!fileEnum.atEnd()) {
var inputFile = fileEnum.item();

// skip files that don't end with the right extension
if (null == inputFile.match(inputFileRegexp)) {
fileEnum.moveNext();
continue;
}

// skip files that are not valid media files.
var media = new Media(inputFile);
if (!media.IsValid()) {
fileEnum.moveNext();
continue;
}

var videoStream = media.Streams.GetItemByMediaType(MediaType.Video, 0);
var audioStream = media.Streams.GetItemByMediaType(MediaType.Audio, 0);

// if needed, add a video event and associate video stream
if (null != videoStream) {
var videoLength = videoStream.Length;
var videoEvent = new VideoEvent(new Timecode(), videoLength);
videoTrack.Events.Add(videoEvent);
var videoTake = new Take(videoStream);
videoEvent.Takes.Add(videoTake);
}

// if needed, add a audio event and associate audio stream
if (null != audioStream) {
var audioLength = audioStream.Length;
var audioEvent = new AudioEvent(new Timecode(), audioLength);
audioTrack.Events.Add(audioEvent);
var audioTake = new Take(audioStream);
audioEvent.Takes.Add(audioTake);
}

var outputFileName = Path.GetFileNameWithoutExtension(inputFile) + newExtension;
var outputPath = Path.Combine(outputDirectory, outputFileName);

var status = DoRender(outputPath, renderer, renderTemplate);
if (status == RenderStatus.Canceled) {
// may want have a dialog here allowing user to
// continue with remaining files.
break;
} else if (status != RenderStatus.Complete) {
throw "Failed on input file: " + inputFile;
}

// clean up the project.
videoTrack.Events.Clear();
audioTrack.Events.Clear();
proj.MediaPool.Remove(inputFile);

fileEnum.moveNext();
}

} catch (e) {
if (!e.skipMessageBox)
MessageBox.Show(e);
}

// Perform the render. The Render method returns a member of the
// RenderStatus enumeration which is, in turn, returned by this
// function.
function DoRender(fileName, rndr, rndrTemplate) {
ValidateFileName(fileName);

// make sure the file does not already exist
if (!overwriteExistingFiles && File.Exists(fileName)) {
throw "File already exists: " + fileName;
}

// perform the render. The Render method returns
// a member of the RenderStatus enumeration. If
// it is anything other than OK, exit the loops.
//var status = Vegas.Render(fileName, rndrTemplate);
var status = Vegas.Render(fileName, rndrTemplate);
return status;
}

function ValidateFileName(fileName : System.String) {
if (fileName.length > 260)
throw "file name too long: " + fileName;
var illegalCharCount = Path.InvalidPathChars.Length;
var i = 0;
while (i < illegalCharCount) {
if (0 <= fileName.IndexOf(Path.InvalidPathChars[i])) {
throw "invalid file name: " + fileName;
}
i++;
}
}

function FindRenderer(rendererRegExp : RegExp) : Renderer {
var rendererEnum : Enumerator = new Enumerator(Vegas.Renderers);
while (!rendererEnum.atEnd()) {
var renderer : Renderer = Renderer(rendererEnum.item());
if (null != renderer.FileTypeName.match(rendererRegExp)) {
return renderer;
}
rendererEnum.moveNext();
}
return null;
}

function FindRenderTemplate(renderer : Renderer, templateRegExp : RegExp) : RenderTemplate {
var templateEnum : Enumerator = new Enumerator(renderer.Templates);
while (!templateEnum.atEnd()) {
var renderTemplate : RenderTemplate = RenderTemplate(templateEnum.item());
if (null != renderTemplate.Name.match(templateRegExp)) {
return renderTemplate;
}
templateEnum.moveNext();
}
return null;
}




---end




Return to posts index

cow
Steve Rhoden
Re: directoryconverter.js errors
on Jan 22, 2009 at 3:12:11 am



I have no idea what all that is saying or for what purpose you
would need such a script.....otherwise i see NOTE!!! This script requires Vegas 4.0c. then clearly it is not compatible with
Vegas pro 8.

Steve Rhoden
(Cow Leader)
Creative Arts Director and Film Maker.
Portfolio at:
http://www.youtube.com/hentys



Return to posts index

Todd Geer
Re: directoryconverter.js errors
on Jan 22, 2009 at 3:38:09 am

Correct, it appears to have been written when V4 was the current version, so I'm sure the developer put that in as a disclaimer/clarifier.

Someone out there who knows js should recognize the error and know what it's talking about, and THAT's what I'm looking for. Else I would be able to solve it myself.





Return to posts index


cowcowcowcowcow
Gilles Pialat
Re: directoryconverter.js errors
on Jan 22, 2009 at 8:10:44 am

Proxy Stream can do the same job:
http://sony.vegas.1.free.fr/


Return to posts index

Todd Geer
Re: directoryconverter.js errors
on Jan 22, 2009 at 7:38:44 pm

Thanks, Gilles! Just what I was looking for!



Return to posts index

John Rofrano
Re: directoryconverter.js errors
on Jan 22, 2009 at 11:44:42 am

That script is from the Sony Script SDK. Just download the Script SDK for Vegas Pro 8.0 from the Sony site and you'll have the latest version.

~jr

http://www.johnrofrano.com
http://www.vasst.com



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]