Zero Smoothness Script by James Trietsch

Trichome wrote on 4/5/2006, 1:44 PM
/**********
* Zero Smooth - Sets all video keyframe smoothness properties to zero
* by James Trietsch
* (A modification of match_aspect_ratio.js)
**********/

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

var tCount = Vegas.Project.Tracks.Count;

for (var i=0; i < tCount; i++) {
var track = Vegas.Project.Tracks[i];

if (!track.IsVideo())
continue;

var events = new Enumerator(track.Events);

while (!events.atEnd()) {
var tEvent = events.item();
var mStream = GetActiveMediaStream(tEvent);

if (mStream) {
var vStream = VideoStream(mStream);
var keys = VideoEvent(tEvent).VideoMotion.Keyframes;
var kCount = keys.Count;

for (var j=0; j<kCount; j++) {
keys[j].Smoothness = 0;
}
}

events.moveNext();
}
}


// Copied from Match Aspect Ratio script
function GetActiveMediaStream (trackEvent : TrackEvent)
{
try
{
if ( ! trackEvent.ActiveTake.IsValid())
{
throw "empty or invalid take";
}

var media = Vegas.Project.MediaPool.Find (trackEvent.ActiveTake.MediaPath);

if (null == media)
{
throw "missing media";
}

var mediaStream = media.Streams.GetItemByMediaType (MediaType.Video, trackEvent.ActiveTake.StreamIndex);

return mediaStream;
}
catch (e)
{
//MessageBox.Show(e);
return null;
}
}

Comments

jetdv wrote on 4/5/2006, 1:57 PM
This same functionality has already been available both as a free script at VASST and as part of Excalibur 4.6.x for quite some time.
JohnnyRoy wrote on 4/5/2006, 3:23 PM
Thanks for sharing, but I don't understand what is going on with getting the media stream? It’s not being used for anything in that script and takes up half of the code. It seems to just be overhead with no real benefit.

I don’t mean to offend but this is the Script forum and people come here for code examples and I would hate for them to use that as an example of what to do to solve that particular problem. That whole Script could be more efficiently written in just 5 lines of code (not counting the imports)
for (var track : Track in Vegas.Project.Tracks)       // for each track in the project
{
if (!track.IsVideo()) continue; // if not a video track, skip it
for (var videoEvent : VideoEvent in track.Events) // for each video event on the track
{
for (var keyframe : VideoMotionKeyframe in videoEvent.VideoMotion.Keyframes) // for each keyframe
{
keyframe.Smoothness = 0; // set smoothness to zero
}
}
}
Please don’t take this the wrong way as I’m sure the script is being offered with the best intent (and I realize you didn't write it); but for the benefit of those trying to learn scripting, simple is always better.

~jr
johnmeyer wrote on 4/5/2006, 4:09 PM
JohnnyRoy,

I posted a link to your script in the crosspost on this subject over in the Vegas forum because I didn't want anyone to try to use the one posted here.

I briefly looked at the script listed in this thread, and it is pretty screwed up, with the catch/try buried down in the function call, and no catch/try in the main code. There are other problems as well. I've never been critical of other's programming because, goodness knows, I've posted a few turkeys, but this one doesn't seem to be quite right.
JohnnyRoy wrote on 4/5/2006, 4:19 PM
Yea, I saw that John. Thanks. I didn’t want to be critical in the Vegas forum ‘cuz I realize people are honestly trying to help each other, but when I saw it here I just wanted to reflect that it was not, shall we say, a “model program”. It’s good that people contribute and I wouldn’t want to discourage anyone from posting scripts.

What I really want to know is, How does Edward answer these posts just minutes after they show up? He beats me every time! I mean there isn’t a post for days and days and then something gets posted and Edward has a post within minutes. How does he do that? Does he get email notification or something? ;-)

~jr
jetdv wrote on 4/5/2006, 7:21 PM
How does Edward answer these posts just minutes after they show up? He beats me every time! I mean there isn’t a post for days and days and then something gets posted and Edward has a post within minutes. How does he do that? Does he get email notification or something? ;-)

Just dumb luck this time. I just happened to hit refresh at just the right time :-)