They're here! More Muvipix.com Guides by Steve Grisetti!
The Muvipix.com Guides to Premiere & Photoshop Elements 2024
As well as The Muvipix.com Guide to CyberLink PowerDirector 21
Because there are stories to tell
muvipix.com

Script to start, render and exit.

Talk about the Sony Vegas line of products.

Script to start, render and exit.

Postby Chris B » Sat Oct 13, 2012 4:41 pm

Hi all,

I'm looking to do a slide show with a "coverflow" style animation. I have a Vegas Pro 11 project which does a single movement and photos numbered from 1 to 10. My intention is to replace the photo files and re-render the project multiple times. I'd like to do this programatically if at all possible. Now - I can move the photos around so all I need to do is fire up Vegas and have it render a project then quit again. I thought there would be a command line option for this - but it appears not - so I think I need to use a script.

So my question (eventually) is - does anyone have - or have advice about - a script that simply renders a project to a pre-defined render then quits Vegas? All advice gratefully received .
Intel Core i7 8700 - 32GB DDR4 - 500GB Evo 970 SSD - 3+2 TB HDD - GTX 1080- MSI Z370 Pro - Win10 64 bit - Cannon HV30 (PAL) - Sony A6000 - GoPro 3 Black
User avatar
Chris B
Moderator
Moderator
 
Posts: 819
Joined: Tue Apr 24, 2007 6:04 pm
Location: UK

Re: Script to start, render and exit.

Postby Paul LS » Sun Oct 14, 2012 2:55 am

Have you looked at JetDV's site he has a bunch of scripts including batch rendering, There might be something there:-
http://www.jetdv.com/vegas/forum/index.php
Paul LS
Super Contributor
Super Contributor
 
Posts: 3064
Joined: Sat Feb 10, 2007 11:21 am
Location: Southampton, UK

Re: Script to start, render and exit.

Postby Chris B » Sun Oct 14, 2012 3:25 am

Thanks Paul - I've figured it out - I've taken a pre existing script and stripped it down. I'll post later after I've cleaned up the code. (Plus an example video :) )
Intel Core i7 8700 - 32GB DDR4 - 500GB Evo 970 SSD - 3+2 TB HDD - GTX 1080- MSI Z370 Pro - Win10 64 bit - Cannon HV30 (PAL) - Sony A6000 - GoPro 3 Black
User avatar
Chris B
Moderator
Moderator
 
Posts: 819
Joined: Tue Apr 24, 2007 6:04 pm
Location: UK

Re: Script to start, render and exit.

Postby Chris B » Sun Oct 14, 2012 7:46 am

OK - here's the script.

Invoke Vegas with a command line similar to the following:
Code: Select all
"C:\Program Files\Sony\Vegas Pro 11.0\vegas110.exe" /OPEN "D:\Video\test.veg" -SCRIPT:"D:\Video\renderquit.js"


Code: Select all
/**
 * This script renders a project to a pre-defined format then quits Vegas.
 * Used to render a file from the command line.
 * Based on scripts from http://s92274348.onlinehome.us/vegas.html
 * Revision Date: Oct 14, 2012.
 **/

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

// The rendererRegexp and templateRegexp variable are regular
// expressions used to match renderer file type names and template
// names.
var rendererRegexp = /Sony AVC\/MVC/;
var templateRegexp = /Blu-ray 1920x1080-50i, 16 Mbps video stream/;

// This section performs the render

try {

    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);

    // Filename for redered output (extension will be determined by render type)
    var outputFileName = "rendered" + newExtension
    // Output path of video file
    var outputPath = Path.Combine("d:/video", outputFileName);

    var status = DoRender(outputPath, renderer, renderTemplate);
    if (status != RenderStatus.Complete) {
        throw "Failed ";
    }

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

// Quit vegas at the end (will only work if no changes made to file)
Vegas.Exit();

// 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) {
    var status = Vegas.Render(fileName, rndrTemplate);
    return status;
}

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;
}
Intel Core i7 8700 - 32GB DDR4 - 500GB Evo 970 SSD - 3+2 TB HDD - GTX 1080- MSI Z370 Pro - Win10 64 bit - Cannon HV30 (PAL) - Sony A6000 - GoPro 3 Black
User avatar
Chris B
Moderator
Moderator
 
Posts: 819
Joined: Tue Apr 24, 2007 6:04 pm
Location: UK

Re: Script to start, render and exit.

Postby Paul LS » Sun Oct 14, 2012 10:51 am

Good job :) I have used scripts in Vegas Pro but haven't "tinkered" with them.
Paul LS
Super Contributor
Super Contributor
 
Posts: 3064
Joined: Sat Feb 10, 2007 11:21 am
Location: Southampton, UK

Re: Script to start, render and exit.

Postby RJ Johnston » Sun Oct 14, 2012 4:44 pm

Oh, yeah. Works like a charm. Thank you, Chris.
Dell XPS 8940 Intel 8-core 10th gen.-i7 10700K (3.8-5.1 GHz); 32GB DDR4 2933 MHz RAM; 512 GB SSD; 2 TB 7200 HD; BDRE-drive; NVIDIA(R) Geforce(R) RTX 2060 SUPER(TM) 8G8 GDDR6
User avatar
RJ Johnston
Premiere Member
Premiere Member
 
Posts: 3143
Joined: Thu Apr 12, 2007 4:33 pm
Location: Northern California, USA

Re: Script to start, render and exit.

Postby Chris B » Tue Oct 16, 2012 4:06 pm

OK - So as mentioned in the showcase thread there was some Python involved. This relies on there being the following in the same directory/folder.

A directory called "photos" that contains all the photos
A file called "files.txt" that contains the filenames of the photos that you want to use in order
a file runvegas.bat that launches Vegas using the above script
A Vegas project file launched by the script that uses files called 1.jpg to 10.jpg to perform the effect.

This code is hard coded to use the output render type that Vegas produces (mp4) and will produce video files video000.mp4 etc.
Here's the Python code (uses python 2.5):

Code: Select all
import fileinput
import shutil
import os.path
import subprocess

photos=[]
for l in fileinput.input("files.txt"):
    if len(l)>2:
        photos.append(l.rstrip())
fileinput.close()

if len(photos)<9:
    print "Too few files in list"
    exit()

v=len(photos)
photos=photos[-4:]+photos+photos[0:5]

for x in range(len(photos)-9):
    print "Video",x+1,"of",v
    for y in range(1,11):
        shutil.copy(os.path.join("photos",photos[x+y-1]),str(y)+".jpg")
    subprocess.call(['runvegas.bat'])
    shutil.copy('rendered.mp4','video'+('000'+str(x))[-3:]+".mp4")
print "Finished!"
Intel Core i7 8700 - 32GB DDR4 - 500GB Evo 970 SSD - 3+2 TB HDD - GTX 1080- MSI Z370 Pro - Win10 64 bit - Cannon HV30 (PAL) - Sony A6000 - GoPro 3 Black
User avatar
Chris B
Moderator
Moderator
 
Posts: 819
Joined: Tue Apr 24, 2007 6:04 pm
Location: UK


Return to Vegas 


Similar topics


Who is online

Users browsing this forum: Google [Bot] and 37 guests