www.jetdv.com Forum Index Edward Troxel
Vegas Scripting and Newsletters
Home of Excalibur and Montage Magic
 
 FAQ   Search   Memberlist   Usergroups   Register   Profile 
 Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do I add StretchToFill to this script?

 
Post new topic   Reply to topic    www.jetdv.com Forum Index -> Scripting FAQ
View previous topic :: View next topic  
Author Message
Svempa



Joined: 31 May 2006
Posts: 6
Location: Sweden

PostPosted: Thu Dec 06, 2007 1:53 pm    Post subject: How do I add StretchToFill to this script? Reply with quote

I have modified this script that I found somewere to render an AVI and a WMV but I need the StretchToFill command to apply to the WMV render and I can't figure out how to do that.
I also tried to make the WMV render automatically get the filename from the the first save file dialog and just change the ending _DV to _Webb but that didn't work out either.
Any help would be great!
Thanks



Code:
/**

 * The following script renders a project in two stages for use in DVD

 * Architect.  The first stage renders the video as MPEG-2 (NTSC),

 * second renders the audio as either AC-3 or 48KHz Wave.

 *

 * Revision Date: Feb. 10, 2003

 **/



import System;

import System.IO;

import System.Windows.Forms;

import Sony.Vegas;


var videoRendererRegexp1 = /Video for Windows/;

var videoTemplateRegexp1 = /PAL DV/;

var videoRendererRegexp2 = /Windows Media Video/;

var videoTemplateRegexp2 = /Klipp till webben/;

var StretchToFill = true;

try {


    var renderStart = new Timecode();

    var renderLength = Vegas.Project.Length;

    if (Vegas.SelectionLength > new Timecode()) {

        var msgBoxResult = MessageBox.Show("Render selection only?", "Region Selected", MessageBoxButtons.YesNo);

        if (msgBoxResult == DialogResult.Yes) {

            renderStart = Vegas.SelectionStart;

            renderLength = Vegas.SelectionLength;
           

        }

    }



    var projDir, projName, videoOutputFile1a, videoOutputFile1b, videoOutputFile2;



    var projFile = Vegas.Project.FilePath;

    if ((null == projFile) || (0 == projFile.length)) {

        projDir = "d:/";

        projName = "name_class_yymm_type";

    } else {

        projDir = Path.GetDirectoryName(projFile) + Path.DirectorySeparatorChar;

        projName = Path.GetFileNameWithoutExtension(projFile);

    }

// //Output avi

    videoOutputFile1a = projDir + projName;
    videoOutputFile1b = videoOutputFile1a + "_class_yymm_DV.avi";
    videoOutputFile1b = ShowSaveFileDialog("DV-AVI Files (*.avi)|*.avi", "Render AVI ( _DV ) File", videoOutputFile1b);

    if (null == videoOutputFile1b)

        throw "operation canceled";



    var aviRenderer = findRenderer(videoRendererRegexp1);

    if (null == aviRenderer)

        throw "failed to find AVI renderer";



    var videoTemplate1 = findTemplate(aviRenderer, videoTemplateRegexp1);

    if (null == videoTemplate1)

        throw "failed to find video template";



// //Output wmv

    videoOutputFile2 = videoOutputFile1a + "_class_yymm_Webb.wmv";

    videoOutputFile2 = ShowSaveFileDialog("WMV Files (*.wmv)|*.wmv", "Render WMV ( _Webb ) File", videoOutputFile2);


    //if (null == videoOutputFile2)

    //    throw "operation canceled";



    var wmvRenderer = findRenderer(videoRendererRegexp2);
 
    if (null == wmvRenderer)

        throw "failed to find WMV renderer";



    var videoTemplate2 = findTemplate(wmvRenderer, videoTemplateRegexp2);

    if (null == videoTemplate2)

        throw "failed to find video template";
       
   


// //Render status

    var renderStatus = Vegas.Render(videoOutputFile1b, videoTemplate1, renderStart, renderLength);

    if (renderStatus != RenderStatus.Complete)

        throw "render not complete";
       

    var renderStatus = Vegas.Render(videoOutputFile2, videoTemplate2, renderStart, renderLength);

    if (renderStatus != RenderStatus.Complete)

        throw "render not complete";
       
       
} catch (e) {

    MessageBox.Show(e);

}


// find a renderer that matches the given regular expression.

function findRenderer(re) {

    var rendererEnum = new Enumerator(Vegas.Renderers);

    while (!rendererEnum.atEnd()) {

        var renderer = rendererEnum.item();

        if (null != renderer.FileTypeName.match(re)) {

            return renderer;

        }

        rendererEnum.moveNext();

    }

    return null;

}



// find a render template that matches the given regular expression.

function findTemplate(renderer, re) {

    var templateEnum = new Enumerator(renderer.Templates);

    while (!templateEnum.atEnd()) {

        var template = templateEnum.item();

        if (null != template.Name.match(re)) {

            return template;

        }

        templateEnum.moveNext();

    }

    return null;

}



// an example filter: "PNG File (*.png)|*.png|JPEG File (*.jpg)|*.jpg"

function ShowSaveFileDialog(filter, title, defaultFilename) {

    var saveFileDialog = new SaveFileDialog();

    if (null == filter) {

        filter = "All Files (*.*)|*.*";

    }

    saveFileDialog.Filter = filter;

    saveFileDialog.Title = title;

    saveFileDialog.CheckPathExists = true;

    saveFileDialog.AddExtension = true;

    if (null != defaultFilename) {

        var initialDir = Path.GetDirectoryName(defaultFilename);

        if (Directory.Exists(initialDir)) {

            saveFileDialog.InitialDirectory = initialDir;

        }

        saveFileDialog.DefaultExt = Path.GetExtension(defaultFilename);

        saveFileDialog.FileName = Path.GetFileName(defaultFilename);

    }

    if (System.Windows.Forms.DialogResult.OK == saveFileDialog.ShowDialog()) {

        return Path.GetFullPath(saveFileDialog.FileName);

    } else {

        return null;

    }

}
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Thu Dec 06, 2007 2:13 pm    Post subject: Reply with quote

These lines must be changed:

var renderStatus = Vegas.Render(videoOutputFile1b, videoTemplate1, renderStart, renderLength);


var renderStatus = Vegas.Render(videoOutputFile2, videoTemplate2, renderStart, renderLength);


You're doing a straight render here and can't set any parameters. Instead, you need to change both of these to use the renderargs instead. Here's a sample:

Code:
// C# example
RenderArgs args = new RenderArgs();
args.OutputFile = fileName;
args.RenderTemplate = rndrTemplate;
args.Start = start;
args.Length = length;
args.IncludeMarkers = IncMarkers;
args.StretchToFill = SetStretch;

RenderStatus status = Vegas.Render(args);

//JScript example
var args : RenderArgs = new RenderArgs();
args.OutputFile = fileName;
args.RenderTemplate = rndrTemplate;
args.Start = start;
args.Length = length;
args.IncludeMarkers = IncMarkers;
args.StretchToFill = SetStretch;

var status = Vegas.Render(args);


To simplify things, I put all the rendering code into a separate function and then call that function whenever I need to render. I let that function take care of a lot of the details. That way I can still have a single rendering line in my code even though it takes many lines to complete that task.
Back to top
View user's profile Send private message Send e-mail
Svempa



Joined: 31 May 2006
Posts: 6
Location: Sweden

PostPosted: Thu Dec 06, 2007 3:28 pm    Post subject: Reply with quote

Wow! That was fast! Very Happy
Ok, I tried to change the lines with what you wrote. I fell like I'm really missing something here, like a general understanding of how scripting works... Wink

Anyway, the only error i get is:
Code:

Eget script.js(281) : Expecting more source characters


The full script:


Code:
/**

 * The following script renders a project in two stages for use in DVD

 * Architect.  The first stage renders the video as MPEG-2 (NTSC),

 * second renders the audio as either AC-3 or 48KHz Wave.

 *

 * Revision Date: Feb. 10, 2003

 **/



import System;

import System.IO;

import System.Windows.Forms;

import Sony.Vegas;


var videoRendererRegexp1 = /Video for Windows/;

var videoTemplateRegexp1 = /PAL DV/;

var videoRendererRegexp2 = /Windows Media Video/;

var videoTemplateRegexp2 = /Klipp till webben/;

var StretchToFill = true;

try {


    var renderStart = new Timecode();

    var renderLength = Vegas.Project.Length;

    if (Vegas.SelectionLength > new Timecode()) {

        var msgBoxResult = MessageBox.Show("Render selection only?", "Region Selected", MessageBoxButtons.YesNo);

        if (msgBoxResult == DialogResult.Yes) {

            renderStart = Vegas.SelectionStart;

            renderLength = Vegas.SelectionLength;
           

        }

    }



    var projDir, projName, videoOutputFile1a, videoOutputFile1b, videoOutputFile2;



    var projFile = Vegas.Project.FilePath;

    if ((null == projFile) || (0 == projFile.length)) {

        projDir = "d:/";

        projName = "name_class_yymm_type";

    } else {

        projDir = Path.GetDirectoryName(projFile) + Path.DirectorySeparatorChar;

        projName = Path.GetFileNameWithoutExtension(projFile);

    }

// //Output avi

    videoOutputFile1a = projDir + projName;
    videoOutputFile1b = videoOutputFile1a + "_class_yymm_DV.avi";
    videoOutputFile1b = ShowSaveFileDialog("DV-AVI Files (*.avi)|*.avi", "Render AVI ( _DV ) File", videoOutputFile1b);

    if (null == videoOutputFile1b)

        throw "operation canceled";



    var aviRenderer = findRenderer(videoRendererRegexp1);

    if (null == aviRenderer)

        throw "failed to find AVI renderer";



    var videoTemplate1 = findTemplate(aviRenderer, videoTemplateRegexp1);

    if (null == videoTemplate1)

        throw "failed to find video template";



// //Output wmv

    videoOutputFile2 = videoOutputFile1a + "_class_yymm_Webb.wmv";

    videoOutputFile2 = ShowSaveFileDialog("WMV Files (*.wmv)|*.wmv", "Render WMV ( _Webb ) File", videoOutputFile2);


    //if (null == videoOutputFile2)

    //    throw "operation canceled";



    var wmvRenderer = findRenderer(videoRendererRegexp2);
 
    if (null == wmvRenderer)

        throw "failed to find WMV renderer";



    var videoTemplate2 = findTemplate(wmvRenderer, videoTemplateRegexp2);

    if (null == videoTemplate2)

        throw "failed to find video template";
       
   


// //Render status

//    var renderStatus = Vegas.Render(videoOutputFile1b, videoTemplate1, renderStart, renderLength);

//    if (renderStatus != RenderStatus.Complete)

//        throw "render not complete";
       

//    var renderStatus = Vegas.Render(videoOutputFile2, videoTemplate2, renderStart, renderLength);

//    if (renderStatus != RenderStatus.Complete)

//        throw "render not complete";
       
       
//} catch (e) {

//    MessageBox.Show(e);

//}
    var args : RenderArgs = new RenderArgs();
    args.OutputFile = videoOutputFile1b;
    args.RenderTemplate = videoTemplate1;
    args.Start = renderStart;
    args.Length = renderLength;
    //args.IncludeMarkers = IncMarkers;
    args.StretchToFill = False;

    var status = Vegas.Render(args);
   
   
    var args2 : RenderArgs = new RenderArgs();
    args2.OutputFile = videoOutputFile2;
    args2.RenderTemplate = videoTemplate2;
    args2.Start = renderStart;
    args2.Length = renderLength;
    //args.IncludeMarkers = IncMarkers;
    args2.StretchToFill = True;

    var status = Vegas.Render(args2);


// find a renderer that matches the given regular expression.

function findRenderer(re) {

    var rendererEnum = new Enumerator(Vegas.Renderers);

    while (!rendererEnum.atEnd()) {

        var renderer = rendererEnum.item();

        if (null != renderer.FileTypeName.match(re)) {

            return renderer;

        }

        rendererEnum.moveNext();

    }

    return null;

}



// find a render template that matches the given regular expression.

function findTemplate(renderer, re) {

    var templateEnum = new Enumerator(renderer.Templates);

    while (!templateEnum.atEnd()) {

        var template = templateEnum.item();

        if (null != template.Name.match(re)) {

            return template;

        }

        templateEnum.moveNext();

    }

    return null;

}



// an example filter: "PNG File (*.png)|*.png|JPEG File (*.jpg)|*.jpg"

function ShowSaveFileDialog(filter, title, defaultFilename) {

    var saveFileDialog = new SaveFileDialog();

    if (null == filter) {

        filter = "All Files (*.*)|*.*";

    }

    saveFileDialog.Filter = filter;

    saveFileDialog.Title = title;

    saveFileDialog.CheckPathExists = true;

    saveFileDialog.AddExtension = true;

    if (null != defaultFilename) {

        var initialDir = Path.GetDirectoryName(defaultFilename);

        if (Directory.Exists(initialDir)) {

            saveFileDialog.InitialDirectory = initialDir;

        }

        saveFileDialog.DefaultExt = Path.GetExtension(defaultFilename);

        saveFileDialog.FileName = Path.GetFileName(defaultFilename);

    }

    if (System.Windows.Forms.DialogResult.OK == saveFileDialog.ShowDialog()) {

        return Path.GetFullPath(saveFileDialog.FileName);

    } else {

        return null;

    }

}
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Thu Dec 06, 2007 3:54 pm    Post subject: Reply with quote

You commented out way too much code including this section:


} catch (e) {

MessageBox.Show(e);

}



While you properly used the new code, that new code should have ONLY replaced those two lines. The rest of the lines should have remained untouched! More like this:


Code:
 ...........

   var videoTemplate2 = findTemplate(wmvRenderer, videoTemplateRegexp2);

    if (null == videoTemplate2)

        throw "failed to find video template";
       
   


// //Render status

    var args : RenderArgs = new RenderArgs();
    args.OutputFile = videoOutputFile1b;
    args.RenderTemplate = videoTemplate1;
    args.Start = renderStart;
    args.Length = renderLength;
    //args.IncludeMarkers = IncMarkers;
    args.StretchToFill = False;

    var renderStatus = Vegas.Render(args);

    if (renderStatus != RenderStatus.Complete)

        throw "render not complete";
       

    var args2 : RenderArgs = new RenderArgs();
    args2.OutputFile = videoOutputFile2;
    args2.RenderTemplate = videoTemplate2;
    args2.Start = renderStart;
    args2.Length = renderLength;
    //args.IncludeMarkers = IncMarkers;
    args2.StretchToFill = True;

    var renderStatus = Vegas.Render(args2);

    if (renderStatus != RenderStatus.Complete)

        throw "render not complete";
       
       
} catch (e) {

    MessageBox.Show(e);

}


........
Back to top
View user's profile Send private message Send e-mail
Svempa



Joined: 31 May 2006
Posts: 6
Location: Sweden

PostPosted: Thu Dec 06, 2007 4:24 pm    Post subject: Reply with quote

Ok. I'm beginning to get it...
I copied and pasted your code and now I get a new error:
Code:
D:\-=Download=-\Vegas scripts\Eget script.js(148) : Variable 'False' has not been declared
D:\-=Download=-\Vegas scripts\Eget script.js(163) : Variable 'True' has not been declared

Thank's buy the way for your help. You're an incredible resource!!!
Code:
    var videoTemplate2 = findTemplate(wmvRenderer, videoTemplateRegexp2);

    if (null == videoTemplate2)

        throw "failed to find video template";
       
 


// //Render status

var args : RenderArgs = new RenderArgs();
    args.OutputFile = videoOutputFile1b;
    args.RenderTemplate = videoTemplate1;
    args.Start = renderStart;
    args.Length = renderLength;
    //args.IncludeMarkers = IncMarkers;
    args.StretchToFill = False;

    var renderStatus = Vegas.Render(args);

    if (renderStatus != RenderStatus.Complete)

        throw "render not complete";
       

    var args2 : RenderArgs = new RenderArgs();
    args2.OutputFile = videoOutputFile2;
    args2.RenderTemplate = videoTemplate2;
    args2.Start = renderStart;
    args2.Length = renderLength;
    //args.IncludeMarkers = IncMarkers;
    args2.StretchToFill = True;

    var renderStatus = Vegas.Render(args2);

    if (renderStatus != RenderStatus.Complete)

        throw "render not complete";
       
       
} catch (e) {

    MessageBox.Show(e);

}
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Thu Dec 06, 2007 4:44 pm    Post subject: Reply with quote

Change "False" and "True" to "false" and "true". The "T" and "F" must be lower case. JScript is case sensitive.
Back to top
View user's profile Send private message Send e-mail
Svempa



Joined: 31 May 2006
Posts: 6
Location: Sweden

PostPosted: Fri Dec 07, 2007 9:43 am    Post subject: Reply with quote

Great! That works! Thanks a million!
I've changed the code a bit more to try and make the second (and eventually a third) render automatically get the filename from the first save file dialog and add _Webb before the extension. I know what is missing but not what to add to make it work.
Any ideas?

Thanks
Code:
////Output avi

    videoOutputFile = projDir + projName + "_class_yymm_lang";
    videoOutputFile1 = videoOutputFile + "_DV.avi";
    videoOutputFile1 = ShowSaveFileDialog("DV-AVI Files (*.avi)|*.avi", "Render AVI ( _DV ) File", videoOutputFile1);

    if (null == videoOutputFile1)

        throw "operation canceled";



    var aviRenderer = findRenderer(videoRendererRegexp1);

    if (null == aviRenderer)

        throw "failed to find AVI renderer";



    var videoTemplate1 = findTemplate(aviRenderer, videoTemplateRegexp1);

    if (null == videoTemplate1)

        throw "failed to find video template";



////Output wmv

    videoOutputFile2 = videoOutputFile + "_Webb.wmv";

//    videoOutputFile2 = ShowSaveFileDialog("WMV Files (*.wmv)|*.wmv", "Render WMV ( _Webb ) File", videoOutputFile2);


    if (null == videoOutputFile2)

        throw "operation canceled";



    var wmvRenderer = findRenderer(videoRendererRegexp2);
 
    if (null == wmvRenderer)

        throw "failed to find WMV renderer";



    var videoTemplate2 = findTemplate(wmvRenderer, videoTemplateRegexp2);

    if (null == videoTemplate2)

        throw "failed to find video template";
       
   


// //Render status

    var args : RenderArgs = new RenderArgs();
    args.OutputFile = videoOutputFile1;
    args.RenderTemplate = videoTemplate1;
    args.Start = renderStart;
    args.Length = renderLength;
    //args.IncludeMarkers = IncMarkers;
    args.StretchToFill = false;

    var renderStatus = Vegas.Render(args);

    if (renderStatus != RenderStatus.Complete)

        throw "render not complete";
       

    var args2 : RenderArgs = new RenderArgs();
    args2.OutputFile = videoOutputFile2;
    args2.RenderTemplate = videoTemplate2;
    args2.Start = renderStart;
    args2.Length = renderLength;
    //args.IncludeMarkers = IncMarkers;
    args2.StretchToFill = true;

    var renderStatus = Vegas.Render(args2);

    if (renderStatus != RenderStatus.Complete)

        throw "render not complete";
       
       
} catch (e) {

    MessageBox.Show(e);

}
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Fri Dec 07, 2007 2:19 pm    Post subject: Reply with quote

videoOutputFile2 = videoOutputFile + "_Webb.wmv";

should be:

videoOutputFile2 = Path.GetdirectoryName(videoOutputFile) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(videoOutputFile) + "_Webb.wmv";

This will get the directory name, append the "\", then add the original file name WITHOUT the extension added, and then add the new part to the file name PLUS the new extension.
Back to top
View user's profile Send private message Send e-mail
Svempa



Joined: 31 May 2006
Posts: 6
Location: Sweden

PostPosted: Fri Dec 07, 2007 3:19 pm    Post subject: Reply with quote

Thanks.
When I insert your code i get
Code:
D:\-=Download=-\Vegas scripts\Eget script2.js(115) : Type 'System.IO.Path' does not have such a static member


Code:
////Output wmv

//    videoOutputFile2 = videoOutputFile + "_Webb.wmv";
//    videoOutputFile2 = ShowSaveFileDialog("WMV Files (*.wmv)|*.wmv", "Render WMV ( _Webb ) File", videoOutputFile2);
   
    videoOutputFile2 = Path.GetdirectoryName(videoOutputFile) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(videoOutputFile) + "_Webb.wmv";

    if (null == videoOutputFile2)

        throw "operation canceled";
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Fri Dec 07, 2007 3:56 pm    Post subject: Reply with quote

I misspelled this: GetdirectoryName

Should be: GetDirectoryName

It's that old upper/lower case thing again and I ended up with a lowercase d instead of an uppercase D.
Back to top
View user's profile Send private message Send e-mail
Svempa



Joined: 31 May 2006
Posts: 6
Location: Sweden

PostPosted: Fri Dec 07, 2007 4:17 pm    Post subject: Reply with quote

Yes!!! It works! Thanks! Very Happy

I have an idea to make the rendering faster. How hard would it be to make the script render out the project to an avi and then let the wmv render from the resulting avi file, to make it quicker if you have a project with a lot of effects on? What I mean is:
Render to avi -> Render wmv from that avi.
Back to top
View user's profile Send private message
Edward Troxel
Site Admin


Joined: 14 Jul 2004
Posts: 5475

PostPosted: Fri Dec 07, 2007 4:26 pm    Post subject: Reply with quote

It would not be too difficult. After rendering the AVI file, you would then need to start a new project via the script, load that AVI file onto the timeline, and then continue rendering as needed. You might want to make sure the original project was SAVED first, though. In fact, after rendering you could even open the original file back up!
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    www.jetdv.com Forum Index -> Scripting FAQ All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.11 © 2001, 2002 phpBB Group