forked from viskin/premiere-batch-stabilize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-zoom-to-clip.jsx
66 lines (44 loc) · 2.31 KB
/
add-zoom-to-clip.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Adds zoom effect to selected clip
// https://ppro-scripting.docsforadobe.dev/
// https://github.com/Adobe-CEP/Samples/blob/master/PProPanel/jsx/PPRO/Premiere.jsx
//@include "common.jsx"
var zoom = 1.05; // > 1.0
var zoomIn = false;
// setInterpolationTypeAtKey does not work for some reason
//var interpolationType = 5; // 5 = kfInterpMode_Bezier
var project = app.project;
var sequence = project.activeSequence;
if (!sequence) throw "Please select a sequence";
var videoTracks = sequence.videoTracks;
var selectedClips = [];
for (var trackIndex = 0; trackIndex < videoTracks.numTracks; trackIndex++) {
var track = videoTracks[trackIndex];
var clips = collectionToArray(track.clips);
selectedClips.push.apply(selectedClips, getSelectedClips(clips));
}
if (selectedClips.length == 0) throw "Please select some clips";
for (var clipIndex = 0; clipIndex < selectedClips.length; clipIndex++) {
var clip = selectedClips[clipIndex];
var track = getTrackOfClip(videoTracks, clip);
var transitions = track.transitions;
var components = clip.components;
var motionComponent = getComponentByDisplayName(components, "Motion");
var scaleParam = getComponentParamByDisplayName(motionComponent.properties, "Scale");
if (!scaleParam.areKeyframesSupported()) throw "Keyframes are not supported for parameter " + scaleParam.displayName + " of component " + motionComponent.displayName;
var scale1 = zoomIn ? scaleParam.getValue() : scaleParam.getValue() * zoom;
var scale2 = zoomIn ? scale1 * zoom : scale1 / zoom;
var time1 = clip.inPoint;
var time2 = new Time();
time2.seconds = clip.outPoint.seconds - 0.0000001; // to make video frame visible
scaleParam.setTimeVarying(true, 1);
scaleParam.addKey(time1, 1);
scaleParam.setValueAtKey(time1, scale1, 1); // 1 means updateUI
//scaleParam.setInterpolationTypeAtKey(time1, interpolationType, 1)
scaleParam.addKey(time2, 1);
scaleParam.setValueAtKey(time2, scale2, 1); // 1 means updateUI
//scaleParam.setInterpolationTypeAtKey(time2, interpolationType, 1)
app.setSDKEventMessage("Scale effect applied to " + clip.name, "info");
}
function getSelectedClips(clips) {
return clips.filter(function (clip) { return clip.isSelected() });
}