Comments

Serena wrote on 3/6/2009, 8:19 PM
One of John Meyer's scripts will fix this. See this thread: //www.sonycreativesoftware.com/forums/ShowMessage.asp?ForumID=4&MessageID=463326Johnmeyer script[/link]

EDIT: the link given in that thread no longer works. John emailed the script to me and if you wish I can email it to you. You haven't allowed email in your profile, so you must let me know if you want the script.
jimingo wrote on 3/6/2009, 10:28 PM
Serena,

If you could e-mail it to me too, that would be awesome.
Half my work is audio editing and sometimes I forget to hit that switch when working on video projects.

Thanks
-Jim
Serena wrote on 3/7/2009, 3:38 PM
I'm happy to email to you but you'll have to email me an address. No attachments going through the forum contact system.
ShawnLaraSteele wrote on 3/7/2009, 3:42 PM
Searching for the script name, I assume you mean this script?
EDIT: Fixed a bug below

// Quantize all selected video events to frames. Rounds the time to the nearest frame boundry.
//
// To use:
// 1. Select the desired video events
// 2. Run the script
//
// The script looks at each selected video event on every track and quantizes the start and end times.
// There are variables that you can change if you want to quantize audio and video, or all events.
//
// Author: Randall Campbell, info@peachrock.com, www.peachrock.com
// © Copyright 2004, Peach Rock Productions, LLC.
// You are free to use or modify this code as long as the copyright information is not removed.
// This software is provided AS IS, no warranty is expressed or implied

import System;
import System.Windows.Forms;
import System.Collections;
import Sony.Vegas;

// Set to true to only quantize video events
var videoOnly : boolean = true;

// Set to true to only quantize selected events
var selectedOnly : boolean = true;

// Loop through all of the tracks and quantize the desired events
var count : int = 0;
for (var track in Vegas.Project.Tracks)
{
if (!track.IsVideo() && videoOnly)
continue;

for (var videoEvent in track.Events)
{
if (!videoEvent.Selected && selectedOnly)
continue;

var start : Timecode = Quantize(videoEvent.Start);
var end : Timecode = Quantize(videoEvent.Start + videoEvent.Length);
videoEvent.AdjustStartLength(start, end - start, true);
count++;
}
}
MessageBox.Show("Quantized " + count + " events to frame boundries.");

// Round the timecode value to the nearest frame
// Returns the quantized timecode value
function Quantize(timecode : Timecode) : Timecode
{
var newTimecode : Timecode = new Timecode();
newTimecode.Nanos = timecode.Nanos;

var originalNanos : long = newTimecode.Nanos;
newTimecode.FrameCount = newTimecode.FrameCount;
var nano1 : long = newTimecode.Nanos;
newTimecode.FrameCount = newTimecode.FrameCount + 1;
var nano2 : long = newTimecode.Nanos;
var nanoMiddle : long = (long)((nano2 - nano1) / 2);
if (originalNanos < nano1 + nanoMiddle)
newTimecode.FrameCount = newTimecode.FrameCount - 1;

return newTimecode;
}
ShawnLaraSteele wrote on 3/7/2009, 4:12 PM
Actually I got errors because
var nanoMiddle : long = (nano2 - nano1) / 2;
wasn't a long, so I had to cast it to long:
var nanoMiddle : long = (long)((nano2 - nano1) / 2);

And it moves the clips to the nearest frame, however that wasn't exactly my problem :).

My problem is that my media was trimmed by part of a frame, so how do I get the little /\ to match the timeline's frames? (Or does it matter?)
Serena wrote on 3/7/2009, 4:42 PM
/ Quantize all selected events to frames. Rounds the time to the nearest frame boundry.
//
// To use:
// 1. Select the desired events
// 2. Run the script
//
// The script looks at each selected event on every track and quantizes the start and end times and optionally the fade
// times.
// There are variables below that you can change to modify what quantization is applied to.
//
// Author: Randall Campbell, info@peachrock.com, www.peachrock.com
// © Copyright 2004-2005, Peach Rock Productions, LLC.
// You are free to use or modify this code as long as the copyright information is not removed.
// This software is provided AS IS, no warranty is expressed or implied

import System;
import System.Windows.Forms;
import System.Collections;
import Sony.Vegas;

// Set to true to only quantize video events
var videoOnly : boolean = false;

// Set to true to only quantize selected events
var selectedOnly : boolean = false;

// Set to true to also quantize fade times
var fades : boolean = true;

// Loop through all of the tracks and quantize the desired events
var count : int = 0;
for (var track in Vegas.Project.Tracks)
{
if (!track.IsVideo() && videoOnly)
continue;

for (var trackEvent in track.Events)
{
if (!trackEvent.Selected && selectedOnly)
continue;

var start : Timecode = Quantize(trackEvent.Start);
var end : Timecode = Quantize(trackEvent.Start + trackEvent.Length);
trackEvent.AdjustStartLength(start, end - start, true);

if ( track.IsVideo() && fades)
{
// Kill fades less than one frame for video events
if (trackEvent.FadeIn.Length.Nanos > 0 && trackEvent.FadeIn.Length.FrameCount == 0)
trackEvent.FadeIn.Length = Timecode.FromFrames(0);
if (trackEvent.FadeOut.Length.Nanos > 0 && trackEvent.FadeOut.Length.FrameCount == 0)
trackEvent.FadeOut.Length = Timecode.FromFrames(0);

// Quantize the fades
trackEvent.FadeIn.Length = Quantize(trackEvent.FadeIn.Length);
trackEvent.FadeOut.Length = Quantize(trackEvent.FadeOut.Length);
}

count++;
}
}
MessageBox.Show("Quantized " + count + " events to frame boundries.");

// Round the timecode value to the nearest frame
// Returns the quantized timecode value
function Quantize(timecode : Timecode) : Timecode
{
var newTimecode : Timecode = new Timecode();
newTimecode.Nanos = timecode.Nanos;

var originalNanos : long = newTimecode.Nanos;
newTimecode.FrameCount = newTimecode.FrameCount;
var nano1 : long = newTimecode.Nanos;
newTimecode.FrameCount = newTimecode.FrameCount + 1;
var nano2 : long = newTimecode.Nanos;
var nanoMiddle : long = Convert.ToInt64((nano2 - nano1) / 2);
if (originalNanos < nano1 + nanoMiddle)
newTimecode.FrameCount = newTimecode.FrameCount - 1;

return newTimecode;
}
TheHappyFriar wrote on 3/7/2009, 5:05 PM
updated download link: here

just searched for it @ vasst.
ShawnLaraSteele wrote on 3/7/2009, 5:37 PM
I changed it some, this is what I think I want (I'm not sure if this is required or wise). I'm correcting the offsets of the Takes to even frames (I think).

// Quantize all selected video events to frames. Rounds the time to the nearest frame boundry.
//
// To use:
// 1. Select the desired video events
// 2. Run the script
//
// The script looks at each selected video event on every track and quantizes the start and end times.
// There are variables that you can change if you want to quantize audio and video, or all events.
//
// It also moves the offsets for video events to the previous frame
//
// It also leaves only modified tracks selected when done
//
// Author: Randall Campbell, info@peachrock.com, www.peachrock.com
// © Copyright 2004, Peach Rock Productions, LLC.
// You are free to use or modify this code as long as the copyright information is not removed.
// This software is provided AS IS, no warranty is expressed or implied
// Modified 2009 Shawn Steele to ajust offsets of takes as well. (not sure if that's a good idea or not)

import System;
import System.Windows.Forms;
import System.Collections;
import Sony.Vegas;

// Set to true to only quantize video events
var videoOnly : boolean = true;

// Set to true to only quantize selected events
var selectedOnly : boolean = true;

// Loop through all of the tracks and quantize the desired events
var count : int = 0;
var quantizedEvents : int = 0;
var truncatedTakes : int = 0;

for (var track in Vegas.Project.Tracks)
{
if (!track.IsVideo() && videoOnly)
{
// Unselect them
for (var events in track.Events)
events.Selected = false;
continue;
}

for (var videoEvent in track.Events)
{
if (!videoEvent.Selected && selectedOnly)
continue;

// Adjust start & end of event
var stillSelected : Boolean = false;
var start : Timecode = Quantize(videoEvent.Start);
var end : Timecode = Quantize(videoEvent.Start + videoEvent.Length);
if (start != videoEvent.Start || end != videoEvent.Start + videoEvent.Length)
{
videoEvent.AdjustStartLength(start, end - start, true);
quantizedEvents++;
stillSelected = true;
}

// Adjust offset of take (just drop it not average because I don't want
// it to "jump" to the next frame
var take: Take = videoEvent.Takes.Item[0];
if (videoEvent.Takes.Count > 1)
{
// I don't know how multiple takes work
MessageBox.Show("Multiple takes this script doesn't know how to handle");
break;
}

var newOffset : Timecode = take.Offset;
newOffset.FrameCount = newOffset.FrameCount; // truncate
if (take.Offset != newOffset)
{
take.Offset = newOffset;
videoEvent.Takes.Item[0] = take;
truncatedTakes++;
stillSelected = true;
}

videoEvent.Selected = stillSelected;

count++;
}
}
MessageBox.Show("Processed " + count + " events\n" +
"Quantized " + quantizedEvents + " to frame boundries\n" +
"Truncated " + truncatedTakes + " takes to frame start");

// Round the timecode value to the nearest frame
// Returns the quantized timecode value
function Quantize(timecode : Timecode) : Timecode
{
var newTimecode : Timecode = new Timecode();
newTimecode.Nanos = timecode.Nanos;

var originalNanos : long = newTimecode.Nanos;
newTimecode.FrameCount = newTimecode.FrameCount;
var nano1 : long = newTimecode.Nanos;
newTimecode.FrameCount = newTimecode.FrameCount + 1;
var nano2 : long = newTimecode.Nanos;
var nanoMiddle : long = (long)((nano2 - nano1) / 2);
if (originalNanos < nano1 + nanoMiddle)
newTimecode.FrameCount = newTimecode.FrameCount - 1;

return newTimecode;
}
Udi wrote on 3/8/2009, 4:13 AM
This version does not quantize the fades, you should add it from Serena code:

if ( track.IsVideo() && fades)
{
// Kill fades less than one frame for video events
if (trackEvent.FadeIn.Length.Nanos > 0 && trackEvent.FadeIn.Length.FrameCount == 0)
trackEvent.FadeIn.Length = Timecode.FromFrames(0);
if (trackEvent.FadeOut.Length.Nanos > 0 && trackEvent.FadeOut.Length.FrameCount == 0)
trackEvent.FadeOut.Length = Timecode.FromFrames(0);

// Quantize the fades
trackEvent.FadeIn.Length = Quantize(trackEvent.FadeIn.Length);
trackEvent.FadeOut.Length = Quantize(trackEvent.FadeOut.Length);
}

Note:

After running such a script, all events will be quantized but you can get a gap of 1 or 2 frames or overlap frames - you should check all cuts!

Udi
Serena wrote on 3/8/2009, 5:14 AM
Yes, the script provided by John Meyer included closing up those gaps in addition to the quantize function. TheHappyFriar has given above a link to that extra script.