Adobe-CEP / Samples

Code samples for CEP extensions
MIT License
972 stars 551 forks source link

Unable to set Keyframe on In/Out Point #106

Closed FreVsAlpha closed 5 years ago

FreVsAlpha commented 5 years ago

Hi,

Scripting against Premiere Pro - 13.1. Purpose: add a key-frame on the in point, one on the outpoint and 2 in between. The timing is always off. Is this a bug or am I missing something?

My Code:

var seq = app.project.activeSequence;
var ip = seq.getInPointAsTime();
var op = seq.getOutPointAsTime();

var firstVideoTrack = seq.videoTracks[0];
var clipsFromFirstVidTrack = firstVideoTrack.clips;
var theClip;
var clipComponents;

// get the selected clip
for (var i = 0; i < clipsFromFirstVidTrack.numItems; i++) {
  var currentClip = clipsFromFirstVidTrack[i];
  if (clipsFromFirstVidTrack[i].isSelected()) {
    theClip = clipsFromFirstVidTrack[i];
    clipComponents = theClip.components;
  }
}

for(var j = 0; j < clipComponents.numItems; ++j) {
  if(clipComponents[j].displayName == "Motion") {
    var motion = clipComponents[j];
    var motionScale = motion.properties.getParamForDisplayName("Scale");
    var k = motionScale.getKeys();
    if (!motionScale.isTimeVarying()) { motionScale.setTimeVarying(true); }
    motionScale.addKey(ip.seconds);
    motionScale.addKey(ip.seconds + 1);
    motionScale.addKey(op.seconds - 1);
    motionScale.addKey(op.seconds);
    var k = motionScale.getKeys();

    if (motionScale.areKeyframesSupported() == true) {
      var result = motionScale.getValueAtKey(ip);
      motionScale.setValueAtKey(ip.seconds, 100, false); // 100%
      motionScale.setValueAtKey(ip.seconds + 1, 200, false); // 200%
      motionScale.setValueAtKey(op.seconds - 1, 200, false); // 200%
      motionScale.setValueAtKey(op.seconds, 100, true); // 100%
    }
  }
}

The result:

18-06-2019 22-44-15

The result is inconsistent by the way. Sometimes the key-frames are inserted too early, sometimes too late (like in this example).

Best regards, FreVsAlpha

ErinFinnegan commented 5 years ago

@bbb999 is on vacation at the moment! I'm sure he'll get back to you...

bbb999 commented 5 years ago

I can’t test right now, but it’s likely aligning to a frame boundary.

-bbb

On Jun 18, 2019, at 10:52 PM, FreVsAlpha notifications@github.com wrote:

Hi,

Scripting against Premiere Pro - 13.1. Purpose: add a key-frame on the in point, one on the outpoint and 2 in between. The timing is always off. Is this a bug or am I missing something?

My Code:

var seq = app.project.activeSequence; var ip = seq.getInPointAsTime(); var op = seq.getOutPointAsTime();

var firstVideoTrack = seq.videoTracks[0]; var clipsFromFirstVidTrack = firstVideoTrack.clips; var theClip; var clipComponents;

// get the selected clip for (var i = 0; i < clipsFromFirstVidTrack.numItems; i++) { var currentClip = clipsFromFirstVidTrack[i]; if (clipsFromFirstVidTrack[i].isSelected()) { theClip = clipsFromFirstVidTrack[i]; clipComponents = theClip.components; } }

for(var j = 0; j < clipComponents.numItems; ++j) { if(clipComponents[j].displayName == "Motion") { var motion = clipComponents[j]; var motionScale = motion.properties.getParamForDisplayName("Scale"); var k = motionScale.getKeys(); if (!motionScale.isTimeVarying()) { motionScale.setTimeVarying(true); } motionScale.addKey(ip.seconds); motionScale.addKey(ip.seconds + 1); motionScale.addKey(op.seconds - 1); motionScale.addKey(op.seconds); var k = motionScale.getKeys();

if (motionScale.areKeyframesSupported() == true) {
  var result = motionScale.getValueAtKey(ip);
  motionScale.setValueAtKey(ip.seconds, 100, false); // 100%
  motionScale.setValueAtKey(ip.seconds + 1, 200, false); // 200%
  motionScale.setValueAtKey(op.seconds - 1, 200, false); // 200%
  motionScale.setValueAtKey(op.seconds, 100, true); // 100%
}

} } The result:

The result is inconsistent by the way. Sometimes the key-frames are inserted too early, sometimes too late (like in this example).

Best regards, FreVsAlpha

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

bbb999 commented 5 years ago

Yep; frame boundaries.