在 extendscript 中移动关键帧时间

shift keyframe time in extendscript

我想将图层上某些关键帧的时间推迟 x seconds/frames。在 Extendsript 文档中有一个 function 用于设置关键帧的值,但是 none 我可以找到用于设置关键帧的时间。

我不想修改图层的 in/out 点,这将需要能够仅对选定的键进行操作,因此仅移动图层并不能作为一种解决方法。

After Effects API 中没有实际的 关键帧 对象。只有属性和一堆方法来获取有关这些属性的关键帧的信息。对于一个所有关于关键帧的程序来说,这似乎……有点像 Adob​​e 做的事情。

所以你要做的就是复制你想要移动的键的所有属性,比如时间缓动、空间切线等等,然后用这些属性创建一个新的键,然后删除原来的键 (这也可能是一个陷阱,因为如果你在旧密钥之前插入新密钥,它的索引就会改变。这真令人恼火)。我写了一个函数来做你可以找到的 here,请随意分叉和改进。

我想如果我更擅长 JS,我会制作一个关键帧对象。

我最终做了这件事,因为我想了解如何使用键盘热键将所有选定的关键帧移动到播放头。 我找不到如何模拟鼠标点击和拖动(如果有人知道,因为这可能更微不足道......),但我最终制作了一个脚本,首先记录所有关键帧,然后将它们全部删除,然后替换他们通过一个移位的值。

是的,它确实涉及创建一个 "keyframe" 对象并将它们存储到一个数组中。 shiftKeyFrames 的顺序将假定您按左右顺序将关键帧记录到数组中。

var records = arrayOfkeyFrameObjects;

function shiftKeyFrames(records, dif){//shifts keyFrames by dif     

    for(i= records.length - 1; i >= 0 ; i--){ //Remove original keyframes.
        records[i].property.removeKey(records[i].index);
    }

    for(i=0; i < records.length;i++){ 
        records[i].replacementIndex = records[i].property.addKey(roundFrame(records[i].time+dif)); //Adds a keyframe with the time difference, rounded to the nearest frame, and stores the replacement index.
        records[i].property.setValueAtKey(records[i].replacementIndex,records[i].value); //Sets the value of the new keyFrame
    }

    for(i=0; i < records.length;i++){
        records[i].property.setSelectedAtKey(records[i].replacementIndex, true); //Re-selects all the created keyframes.
    }
}

function roundFrame(time){
    return Math.round(comp.frameRate*time)/comp.frameRate;
}

function keyFrame(property, index){
    this.property = property;
    this.index = index;
    this.time = property.keyTime(index);
    this.value = property.keyValue(index);
    this.replacementIndex;
}
}());