Can I render a single file, to another file

ingvarai wrote on 1/28/2009, 3:32 AM
I know scripts can mimic the usual render operation in Vegas, where media already is on the time line.

But is it possible to render media which does not reside on the time line? What I want is to render one (or more) video files in one format to another format, in a batch operation.

I would like to do this with disk files (just submit the path) or if this is not possible, to render a projects media file(s) even if they are not put on any tracks on the time line.

I assume one way is to create a new project, add media to the time line as a track, render, clear the track(s) and close down the project. But what I really want is to render foo.mpg --> foo.avi, as simple as this.

ingvarai

Comments

Rosebud wrote on 1/28/2009, 3:52 AM
No, you have to use the OpenFile() or the ImportFile() function..
You can batch render files with my script ProxyStream.
UltimateS4 from Vasst or Veggie ToolKit can do it as well.
ingvarai wrote on 1/28/2009, 4:28 AM
Rosebud,

> You can batch render files with my script ProxyStream.
> UltimateS4 from Vasst or Veggie ToolKit can do it as well.

all fine and well. But I am writing my own scripts! I am here to learn how to do it, not to get a certain project or a certain video production task done.

> No, you have to use the OpenFile() or the ImportFile() function..
Ok, I will look at this to see if I can move forward with this information.
But as I said, I want to find what script code I must write (as little as possible) to render foo.mpg --> foo.avi

ingvarai
Rosebud wrote on 1/28/2009, 5:48 AM
Ok, so you have to look at :

NewProject() function to clear project
OpenFile() function to import your mpeg file
Set a new RenderArgs (OutputFile and RenderTemplate)
Make the render: RenderStatus status = vegas.Render(renArgs);

and so on for each file.
ingvarai wrote on 1/28/2009, 5:58 AM
Thanks!
This means that the current opened project in Vegas will be closed, right? Because Vegas can only have one project open at the time, right?

I wonder if it, instead, would be possible to do this with a current project already opened, with certain meadia on the time line already. For example to render out one or all of the project media files, without "disturbing" anything (not disturbing the time line events, FXes added and so on)

ingvarai
jetdv wrote on 1/28/2009, 6:13 AM
The easiest way would probably be to save the current project, start a new project, load the file(s) you want to render, render them, and then in the end you could re-open the file so that when it's done you're back where you started.

Alternately, you could fire off a second instance of Vegas and have that do the rendering. It would be more complicated but you wouldn't have to close the current project.

As one other thought: You could always add the file to the END of the current project, only render the region of the timeline where that file exists, and then delete it back off the timeline. Then you don't have to close the project and you can still get the desired results.

So... there's several options available to you.
Rosebud wrote on 1/28/2009, 6:40 AM
The NewProject() function give you the ability to save the current project.
As Edward said, you can re-open your current project after that.

NewProject ( Boolean promptSave, Boolean showDialog )
ingvarai wrote on 1/28/2009, 7:12 AM
> So... there's several options available to you.

Wow - thanks a lot for your skilled help, jetdv and Rosebud, I will give this a try! All in all - as I understand - for Vegas ro render anything at all, it has to be on the timeline, if I am not completely wrong. This is ok with me, as long as I can make it transparent, meaning I can have a project already opened, tracks added, events added, FXs added, then do my stuff, then revert to the situation before I did my stuff.

ingvarai
jetdv wrote on 1/28/2009, 7:35 AM
Yes, it has to be on the timeline to render it. The options we gave you let that happen.
johnmeyer wrote on 1/28/2009, 11:12 AM
I found this old script. It could serve as a starting point. It has no author or copyright, so I think it is OK to post here.

/**
* 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 = "F:/Video/Video Aids/Veggies/2-Good";

// The outputDirectory variable specifies where the rendered files
// will be created (do not include the trailing back-slash)
var outputDirectory = "F:/Video/Video Aids/Veggies/2-Good";

// 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;
}




ingvarai wrote on 1/29/2009, 9:23 AM
John,

I am very happy about your post!
While I write in C#, I have no problems using this code. I use the parts of it that I need, and adjust when I find it necessary.
Thanks again, it was a big help,

ingvarai
johnmeyer wrote on 1/29/2009, 12:46 PM
Glad it was useful!
Grazie wrote on 2/1/2009, 11:27 PM
JM? jr makes a reference to this script on the COW as being part of the Vegas Scripting SDK.

Grazie
Blur Studio wrote on 3/17/2009, 3:41 PM
Hello ingvarai,

I was able to get around this (with a test) by having my script write out a second script, then having the script kick-off another copy of Vegas to run that script.

So I create a script that loads just that one piece of media onto a timeline and renders it, then using System.Diagnostics.Process, kick-off a new copy of vegas and pass in the new script with the -script option...

krash
BlurStudio