Sony Vegas Script to Change the Pixel Aspect Ratio of Images

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

4 Comments

  1. Mirko
    on April 24, 2008 at 6:32 am | Permalink

    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

  2. on April 24, 2008 at 8:09 pm | Permalink

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

  3. on May 9, 2008 at 12:20 am | Permalink

    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,

  4. on May 9, 2008 at 10:31 am | Permalink

    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.

Post 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.

Your email is never published nor shared. Required fields are marked *

*
*