setting a clips width parameter

Jan Rogowski wrote on 8/15/2012, 12:12 PM
HI all

This has been baking my noodle for a couple of hours now. I'm trying to set the width property of all clips in a project. I presumed I'd have to cycle through all the video events and that the width of the clip, that is the property that controls the width of the clip that is actually visible, would be accessed through the videoevent object.

Does that make sense? You set the video event width parameter through the Video Event FX panel, accessed by right clicking on the video event. So I guess it's actually some kind of generic effect object property but I just can' work out how to get it or set it.

Any help greatly appreciated!

Jan.

Comments

Gary James wrote on 8/16/2012, 11:25 AM
Jan, maybe it would be easier if you explained what is the goal you want to achieve by adjusting the "width" parameter.

Gary
Jan Rogowski wrote on 8/17/2012, 10:29 AM
Hey Gary

The object is to set the width of the crop for each clip.

We work with stereoscopic animated footage that is rendered slightly wider than the movie frame. This allows us to adjust convergence in the edit (sliding left and right eyes in x). Then in the conform we crop the centre out of the frame. Unfortunately this means going through each clip and manually setting the width parameter for the crop.
Gary James wrote on 8/17/2012, 2:25 PM
I guess I didn't make myself clear. What determns the reason for applying the specific width change you are making? For example: Are you trying to change the width parameter to adjust distortion in the clip by unlocking Aspect Ratio dependence?. Or maybe to make the clip appear to fill the width of the screen? In other words what is the end result you are trying to acheive by changing the width parameter?

This is what I was asking.
Jan Rogowski wrote on 8/22/2012, 4:41 AM
Apologies, I've been away. Resuming...

A full 2k frame at 16:9 (1:1) is 2048x1152. This is the resolution of my project.

We want to render a slightly wider frame and then crop the edges off in the edit, allowing a little flexibility to slide the clips in X. Our footage is at 2208x1152

When you import the clip into a Vegas timeline it fits the clip to the width of the project canvas, as the ratios are different this results in letterboxing. By setting the width value to 2048 the clip now fits my project frame, neatly cropping off the edges of my footage.

All I want to do is programmatically set the clip width parameter as accessed through the UI:

Right Click > Video Event Pan/Crop > Position.Width



Gary James wrote on 8/22/2012, 8:05 AM
Oh, OK. This is very simple if ALL your clips are the exact same size. Simply change your Clip width using the Event Pan / Crop dialog. Then, in the Vegas Timeline, right-click on the changed Event and select "Copy". Finally, select all of the Events that you want to change to the same setting; and right-click and select "Paste Event Attributes".

This will copy ALL of the Event attributes that exist in the clip that you copied to the clipboard. So, make sure that you set the clip width first, before making any other changes. Otherwise you may copy more than what you want.
Jan Rogowski wrote on 8/23/2012, 3:54 AM
Thanks Gary, that's a useful tip. I'm still after a way to do it through code though. I want to automate this and a number of other settings for video events as they are built. Essentially creating an augmented 'import clip' command.

I can get the event ID and instance the Video Event. From there I can access the length, start, end, active take, name, etc. I just can't work out how to set the values in the pan/crop.
Gary James wrote on 8/23/2012, 8:37 AM
Jan,

To set the width of a clip programmatically, you must change the Bounds property of the Video Events default Keyframe (Keyframe Zero). Vegas uses an incredibly unintuitive method of setting a clips Size and Position. They use a structure called VideoMotionBounds to set a clips size and position. To change the clips Size, you must reference the current VideoMotionBounds settings, instantiate a new VideoMotionBounds structure based on those current settings, make your changes to the new structure, and finally assign the new structure to the default Keyframes Bounds property.

The following code block is an excerpt from my Timeline Tools utility Property Editor. This represent a Property that takes or returns a .Net SizeF structure containing the Width and Height in pixels for a video clip. The Set property sets the Vegas VideoEvent to the new Size setting.

This should let you make your programmed changes to your Video clips.

Gary ...



// in the code below, the variable "ve" represent a reference to the target Vegas VideoEvent.
get
{
// returns a SizeF struct holding the clips current Width & Height
VideoMotionKeyframe keyframe = ve.VideoMotion.Keyframes[0];
SizeF size = new SizeF ( keyframe.TopRight.X - keyframe.TopLeft.X, keyframe.BottomLeft.Y - keyframe.TopLeft.Y );
return size;
}

set
{
// required by Vegas to programmatically set a parameter.
// this also adds the change to the Vegas Undo stack.
using ( new UndoBlock ( "Undo Keyframe Size" ) )
{
VideoMotionKeyframe keyframe = ve.VideoMotion.Keyframes[0];
SizeF mediasize = value;

// save keyframe roration
double rotation = keyframe.Rotation;

// undo rotation so that we can get at correct aspect ratio.
keyframe.RotateBy ( -rotation );

// get the current Center position of the clip
double centerX = keyframe.Center.X;
double centerY = keyframe.Center.Y;

float halfwidth = mediasize.Width / 2.0f;
float halfheight = mediasize.Height / 2.0f;

VideoMotionBounds bounds = new VideoMotionBounds ( keyframe.TopLeft, keyframe.TopRight, keyframe.BottomRight, keyframe.BottomLeft );

// alter the clip size relative to its current center position
bounds.TopLeft.X = Convert.ToSingle ( centerX - halfwidth );
bounds.TopLeft.Y = Convert.ToSingle ( centerY - halfheight );

bounds.TopRight.X = Convert.ToSingle ( centerX + halfwidth );
bounds.TopRight.Y = Convert.ToSingle ( centerY - halfheight );

bounds.BottomLeft.X = Convert.ToSingle ( centerX - halfwidth );
bounds.BottomLeft.Y = Convert.ToSingle ( centerY + halfheight );

bounds.BottomRight.X = Convert.ToSingle ( centerX + halfwidth );
bounds.BottomRight.Y = Convert.ToSingle ( centerY + halfheight );

// set it to new bounds
keyframe.Bounds = bounds;

// restore previous rotation setting
keyframe.RotateBy ( rotation );
}
}

When you have finished all of your changes to all of your VideoEvents, you should call the Vegas.UpdateUI()
function to force Vegas to refresh the display to reflect ALL the changes you've made.
Jan Rogowski wrote on 8/27/2012, 9:05 AM
Gary, I've only just seen this, will give it a whirl tomorrow. I just couldn't understand why it wasn't a property of the videoevent.!

That looks to be extremely helpful, thankyou.

Jan.