I accidentally left quantize off, and now my video is off by part of a frame. How do I get the frames of the clip lined back up to the frames of the timeline?
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.
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.
// 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;
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?)
// 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);
// 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;
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).
// 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;
}
// 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;
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);
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.