Help using 'Batch Render GUI' sample Script

will-3 wrote on 9/22/2003, 3:14 PM
I can select a profile with this & have it render a single file I have open but...

How can I have it render a bundh of files in a folder... one after the other?

For rendering 'project' it want an Output Directory and Base File Name... but no matter if I use the 'Browse' button in the window to browse over to the folder with the files to render... it doesn't seem to do the job.

How can I make this thing work for a bunch of files I want to render?

Thanks for any help - Will

Comments

johnmeyer wrote on 9/22/2003, 3:52 PM
There are several Vegas scripts that have the word "batch" in their title, but they each do different things. I think the one you are using is designed to take a single project and render it multiple times using several different templates.

If what you want to do instead is take a whole bunch of .VEG files (Vegas project files) and render each project without any further operator intervention, then you want a different script. The two that SoFo/Sony provides on their dowload page won't do the trick.

You can try this basic script (although you have to edit it to specify your files and directory):

RenderQueue.js

I tried to find a link to the script file I use for batch rendering. I can't find it anymore. Therefore, here is the contents of that script. Just cut and paste it to a file, and give that file the extension ".js".
-------------------

/**
* 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 SonicFoundry.Vegas;

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

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

// The rendererRegexp and templateRegexp variable are regular
// expressions used to match renderer file type names and template
// names.
var rendererRegexp = /RealMedia 9/;
var templateRegexp = /256 Kbps 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;
}
jetdv wrote on 9/22/2003, 4:15 PM
Most of them are somewhere on the Sundance site:

http://www.sundancemediagroup.com/help/kb/kb_files.asp

but the particular one you are looking for may be here:
http://www.ayizwe.net/VegasScripts/