Sony Vegas Script to Change the Pixel Aspect Ratio of Images

Posted by Stephen on April 21st, 2008 at 11:04 PM

I spent far too long getting this to work again because I forgot to transfer the script from one computer to another, and all of the web references to this technique are, shall we say, broken like a character on Battlestar Galactica. So for anyone else who might need this, I give you a Sony Vegas script to change the pixel aspect ratio of all images in your media pool, written in C#.

/**
 * This script sets the Pixel Aspect Ratio of all images to be 0.9091.
 *
 * Author: Stephen Granade      Date: 21 April 2008
 **/

using System.Text.RegularExpressions;
using Sony.Vegas;

public class EntryPoint {
  public void FromVegas(Vegas vegas) {
    foreach (Media media in vegas.Project.MediaPool) {
      Match m = Regex.match(media.FilePath, "(jpe?g|png|gif)");
      if (m.Success) {
        VideoStream vs = media.GetVideoStreamByIndex(0);
        vs.PixelAspectRatio = 0.9091;
      }
    }
  }
}

Related posts

4 Comments »

Comment by Mirko

Hey this sounds extremely useful, but I tried this in Vegas 6 with a bunch of photos on my timeline but it gives the following error:
Compilation errors:

‘System.Text.RegularExpressions.Regex’ does not contain a definition for ‘match’
‘Sony.Vegas.Media’ does not contain a definition for ‘GetVideoStreamByIndex’

System.ApplicationException: Failed to compile.
at Sony.Vegas.CodeDomScriptManager.Compile()
at Sony.Vegas.ScriptHost.RunScript(Boolean fCompileOnly)

Do you know a quick fix? I have zero experience with scripts in Vegas…
Cheers, Mirko

Posted on April 24, 2008 at 6:32 am

Comment by Stephen

Sorry, Mirko, I don’t. I’m running 8 here.

Posted on April 24, 2008 at 8:09 pm

Comment by Robert

Hi Stephen

This looks exactly what I need! But I need it to change the p.a.r. on a video file.

Could it be modified to work with a .MP4 file?

See link above for more info.

Also, do I need to compile it in Visual c#??

Thanks a lot,

Posted on May 9, 2008 at 12:20 am

Comment by Stephen

You should be able to modify it to find .mp4 files instead of still images. Try changing “(jpe?g|png|gif)” to “mp4″ in the script. And Vegas 8 should do the compilation for you. You shouldn’t need to compile it yourself.

Posted on May 9, 2008 at 10:31 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Comments are moderated according to our moderation policy. Sometimes comments are delayed by our spam filter. We try to release them as soon as possible.