Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrPowerGamerBR/d23875fa64c46f6e4908a384a9ae2883 to your computer and use it in GitHub Desktop.
Save MrPowerGamerBR/d23875fa64c46f6e4908a384a9ae2883 to your computer and use it in GitHub Desktop.
// Extracts PiP tracking information to a CSV file
//
// Works with Vegas 17
//
// Based on this script: https://www.vegascreativesoftware.info/us/forum/beta-pin-image-video-to-motion-track--112837/?page=2
// With the help of this documentation: https://walkedby.com/other/VEGASScriptAPI.html
//
// How to Use: (Remember, this is a very hacky script!)
// 1. Select the track event
// 2. Run the script
// 3. Yay!
//
// Don't forget to change the file name of the CSV file!
//
// Made by MrPowerGamerBR
using System.Collections.Generic;
using System.Windows.Forms;
using ScriptPortal.Vegas;
using System.IO;
public class EntryPoint {
Vegas myVegas;
public void FromVegas(Vegas vegas) {
myVegas = vegas;
List<TrackEvent> trackEvents = FindAllSelectedEventsUnderCursor();
VideoEvent trackEvent = trackEvents[0] as VideoEvent;
Timecode trackStart = trackEvent.Start;
Timecode trackLength = trackEvent.Length;
Timecode trackEnd = trackEvent.End;
List<Effect> fxList = new List<Effect>(trackEvent.Effects);
Effect pipFX = fxList.Find(x => (x.PlugIn.UniqueID == "{Svfx:com.vegascreativesoftware:pictureinpicture}"));
bool hasPipFx = pipFX != null;
var csv = "LocationX;LocationY;Angle;Scale;DistortionScaleY\n";
if (hasPipFx) {
MessageBox.Show("Has Pip FX!");
List<OFXParameter> ofxList = new List<OFXParameter>(pipFX.OFXEffect.Parameters);
// MessageBox.Show("Object Type: " + ofx.GetType().Name);
foreach (var ofx in ofxList) {
// MessageBox.Show("Key: " + ofx.Name + " - " + ofx.GetType().Name);
}
OFXDouble2DParameter locationParam = (OFXDouble2DParameter) ofxList.Find(x => (x.Name == "Location"));
OFXDoubleParameter angleParam = (OFXDoubleParameter) ofxList.Find(x => (x.Name == "Angle"));
OFXDoubleParameter scaleParam = (OFXDoubleParameter) ofxList.Find(x => (x.Name == "Scale"));
// Doesn't seem to exist?
// OFXDoubleParameter distortionScaleX = (OFXDoubleParameter) ofxList.Find(x => (x.Name == "DistortionScaleX"));
OFXDoubleParameter distortionScaleY = (OFXDoubleParameter) ofxList.Find(x => (x.Name == "DistortionScaleY"));
Timecode currentTimecode = Timecode.FromFrames(0);
while (trackLength >= currentTimecode) {
// MessageBox.Show("Value: " + currentTimecode + "; " + pipLocation.GetValueAtTime(currentTimecode).X + "; " + pipLocation.GetValueAtTime(currentTimecode).Y);
csv += ("" + locationParam.GetValueAtTime(currentTimecode).X);
csv += ";";
csv += ("" + locationParam.GetValueAtTime(currentTimecode).Y);
csv += ";";
csv += ("" + angleParam.GetValueAtTime(currentTimecode));
csv += ";";
csv += ("" + scaleParam.GetValueAtTime(currentTimecode));
csv += ";";
csv += ("" + distortionScaleY.GetValueAtTime(currentTimecode));
csv += "\n";
currentTimecode = currentTimecode + Timecode.FromFrames(1);
}
/* foreach (var keyframe in pipLocation.Keyframes) {
MessageBox.Show("Key: " + keyframe);
MessageBox.Show("Key: " + keyframe.Value);
MessageBox.Show("Key: " + keyframe.Value.X + " ; "+ keyframe.Value.Y);
} */
using(StreamWriter writetext = new StreamWriter("L:\\LorittaAssets\\chaves\\keyframes.txt")) {
writetext.WriteLine(csv);
}
MessageBox.Show("Done!");
} else {
MessageBox.Show("Missing Pip FX...");
}
}
/// <summary>
/// Returns the first selected event that's under the cursor
/// </summary>
/// <returns>The first selected event or null if no event selected</returns>
List<TrackEvent> FindAllSelectedEventsUnderCursor() {
List<TrackEvent> selectedEventsAcrossTracks = new List<TrackEvent>();
foreach (Track track in myVegas.Project.Tracks)
{
foreach (TrackEvent trackEvent in track.Events)
{
if (trackEvent.Selected && trackEvent.Start <= myVegas.Transport.CursorPosition && trackEvent.End >= myVegas.Transport.CursorPosition)
{
selectedEventsAcrossTracks.Add(trackEvent);
}
}
}
return selectedEventsAcrossTracks;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment