Copying Pan/Crop keyframes question

mat_99 wrote on 6/4/2019, 2:04 PM

Hi everyone,

 

I'm working on a script and I have a little problem with copying/setting Pan/Crop (VideoMotion) keyframes.

The problem is that whenever I try to copy a keyframes bounds it starts to zoom on the picture with each iteration a bit.

For example: I have 2 keyframes, let's call them old1 and new1. Each one of them is added to the same event. Then I do this:

new1.Bounds = old1.Bounds;

This is reapeated in a cycle and it zooms in on the picture with each iteration. What am I doing wrong? Do I understand bounds wrong?

Comments

johnmeyer wrote on 8/22/2019, 3:59 PM

Maybe you can find something useful in the following .js script I wrote a few years ago. It takes the pan/crop settings (all keyframes) from the event under cursor on first selected timeline, and copies its pan/crop settings (but NOT fX settings) to all other selected events on the timeline.

/**
 * This script copies pan/crop from event under cursor on first selected timeline
 * and copies its pan/crop settings (but NOT fX settings) to all other
 * selected events on the timeline.
 *
 * Copyright 2017 - John H. Meyer
 *
 **/import System;
import System.Collections;
import System.Text;
import System.IO;
import System.Drawing;
import System.Windows.Forms;
import Sony.Vegas;var evnt    : TrackEvent;
var dStart  : Double;
var dLength : Double;
var dCursor : Double;try {
  //Find event under cursor
  var track = FindSelectedTrack();
  if (null == track)                                // Must select a track
    throw "no selected track";
  var eventEnum = new Enumerator(track.Events);
  if (track.IsVideo()) {                            // Track must be a video track
    dCursor = Vegas.Cursor.ToMilliseconds();        // Remember the cursor position.
    while (!eventEnum.atEnd()) {                    // Find selected event
      evnt = TrackEvent(eventEnum.item());      // Get the event's start and length timecode, in milliseconds.
      dStart  = evnt.Start.ToMilliseconds();
      dLength = evnt.Length.ToMilliseconds();      if ( (dCursor > dStart) && ( dCursor <= (dLength + dStart) ) ) {
        var selectedevnt = VideoEvent(evnt);
        var keyframes = selectedevnt.VideoMotion.Keyframes;  
        var keyframe = keyframes[0];                // First keyframe
        // myKeyframe stores pan/crop info
        var myKeyframe = new VideoMotionBounds(keyframe.TopLeft, keyframe.TopRight, keyframe.BottomRight, keyframe.BottomLeft);
        var rotation = keyframe.Rotation;
        break; // Found first event on timeline under cursor, so quit looking on timeline.
      } //End if
    eventEnum.moveNext();
    } // End while eventEnum    eventEnum = new Enumerator(track.Events);    while (!eventEnum.atEnd()) {                    
      evnt = TrackEvent(eventEnum.item());      if (evnt.Selected & evnt.IsVideo() ) {      // Only change events that are selected
        var vevnt = VideoEvent(evnt);
        keyframes = vevnt.VideoMotion.Keyframes;  // Get keyframe list for this event
        keyframe = keyframes[0];                  // First keyframe on selected event        // The following is optional; normally set to true.
        vevnt.VideoMotion.ScaleToFill = true;
        keyframe.Bounds = myKeyframe;             // Set first keyframe          
        keyframe.RotateBy (rotation);                                                                          }
      eventEnum.moveNext();
    } // End While eventEnum
  } // End If track.IsVideo  else {
    MessageBox.Show("You must select a video track");
  }
} catch (e) {
    MessageBox.Show(e);
}function FindSelectedTrack() : Track {
  var trackEnum = new Enumerator(Vegas.Project.Tracks);
  while (!trackEnum.atEnd()) {
    var track : Track = Track(trackEnum.item());
    if (track.Selected) {
        return track;
    }
    trackEnum.moveNext();
  }
  return null;
}

 

vkmast wrote on 8/22/2019, 4:27 PM

Thanks to @johnmeyer for contributing again, much appreciated.