Comments

johnmeyer wrote on 11/19/2014, 9:14 AM
Is there a hot key to flip a clip vertical? I wrote a script a long time ago which rotates any selected clip by an arbitrary angle. If you set the angle to 90 degrees, it flips it vertically.

Copy this code to Notebook (but don't include "code"), and save it with the extension ".js" (without the quotes). Put this in the Vegas script folder, and then assign it to a keyboard shortcut. Since I set the rotation angle to 90 degrees, this will let you rotate any and all selected clips with the press of one key.

Note that if no clips are selected, then ALL clips will be rotated.

John



// Vertically flip all selected video events on first selected track.
// No selection = ALL events
// Copyright November 19, 2014, John H. Meyer

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

// Change the following line to get different roations
var RotationDegrees = -90;

var zero : int = 0;
var cSelected = GetSelectionCount (MediaType.Video);
var cTracks = Vegas.Project.Tracks.Count;
var ii;
var Rotation = (RotationDegrees) * (Math.PI)/180;

for (ii = zero; ii < cTracks; ii ++)
{
var track = Vegas.Project.Tracks[ii];

if (! track.IsVideo())
{
continue;
}

var eventEnum : Enumerator = new Enumerator(track.Events);

while ( ! eventEnum.atEnd() )
{
var trackEvent : TrackEvent = eventEnum.item();

if ( !cSelected || trackEvent.Selected )
{
var mediaStream = GetActiveMediaStream (trackEvent);

if (mediaStream)
{
var videoStream = VideoStream (mediaStream);
var MediaAspect = videoStream.PixelAspectRatio
var NewWidth = videoStream.Height / MediaAspect
var NewHeight = videoStream.Width * MediaAspect
var videoEvent = VideoEvent(eventEnum.item());
var keyframes = videoEvent.VideoMotion.Keyframes;
var cKeyframes = keyframes.Count;
var jj;

for (jj = zero; jj < cKeyframes; jj ++)
{
RotateEvent (keyframes[jj], Rotation, MediaAspect, NewWidth, NewHeight);
}
}
}

eventEnum.moveNext();
}
}


Vegas.UpdateUI();



function GetSelectionCount (mediaType)
{
var cTracks = Vegas.Project.Tracks.Count;
var cSelected = zero;
var ii;

for (ii = zero; ii < cTracks; ii ++)
{
var track = Vegas.Project.Tracks[ii];

if (track.MediaType == mediaType)
{
var eventEnum : Enumerator = new Enumerator(track.Events);

while ( ! eventEnum.atEnd() )
{
if (eventEnum.item().Selected)
{
cSelected ++;
}

eventEnum.moveNext();
}
}
}

return cSelected;
}

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

function RotateEvent (keyframe : VideoMotionKeyframe, Rotation, MediaAspect, NewWidth, NewHeight)
{
var rotation = keyframe.Rotation;
var myKeyframe = new VideoMotionBounds(keyframe.TopLeft, keyframe.TopRight, keyframe.BottomRight, keyframe.BottomLeft);
var bounds = new VideoMotionBounds(keyframe.TopLeft, keyframe.TopRight, keyframe.BottomRight, keyframe.BottomLeft);

try
{
//MessageBox.Show(NewWidth); // For debugging
bounds.TopLeft.X = 0;
bounds.TopRight.X = NewHeight;
bounds.BottomLeft.X = 0;
bounds.BottomRight.X = NewHeight;

bounds.TopLeft.Y = NewWidth;
bounds.TopRight.Y = NewWidth;
bounds.BottomLeft.Y = 0;
bounds.BottomRight.Y = 0;

keyframe.Bounds = bounds;
// keyframe.RotateBy (Rotation);

}

catch (e)

{
// restore original settings on error
MessageBox.Show("Rotation failed");
}
}
Multitech wrote on 11/20/2014, 5:19 PM
Choose event pan/crop
Right click on the video frame in new window and choose flip vertical/horizontal

or maybe use track motion to do many clips on one track.
Grazie wrote on 11/21/2014, 12:03 AM
Once you've turned the JM Script into a click-able option, configure a Keyboard Shortcut through:

Options >> Customise Keyboard

And assign the JM Script to a "Hot Key". That's what you were wanting - yes?

However, I do like PEA-ing - that's Paste Event Attributes. It's a method of applying an Event's "look" without the need to remember KB shortcuts or "HotKeys". Though PEAing does sweep or wash all before it. So, PEA for Flip and then add your FX-ing.

Cheers

Grazie