forked from viskin/premiere-batch-stabilize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply-warp-effect.jsx
107 lines (82 loc) · 3.6 KB
/
apply-warp-effect.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Apply effect
// https://ppro-scripting.docsforadobe.dev/
// qe.reflect.methods
// qe.reflect.properties
//https://lesterbanks.com/2019/04/how-to-add-effects-in-premiere-with-extendscript/
//https://github.com/qmasingarbe/pymiere/blob/master/example_and_documentation.md - how to export
//https://github.com/yearbook/yearbook.github.io/blob/master/esdocs/source/Premiere/classes/QEProject.json - parameters
//@include "common.jsx"
var effectName = "Warp Stabilizer" // Sadly cannot be a preset name
var smoothness = 9;
var cropLessSmoothMore = 10;
app.enableQE();
var project = app.project;
var projectItems = app.getCurrentProjectViewSelection();
if (!projectItems) throw "Please select some sequences";
var colorLabelEffectAdded = 7; // dark yellow
var colorLabelEffectConfigured = 12; // biege
var colorLabelEffectAnalyzed = 10; // dark green
for (var i = 0; i < projectItems.length; i++) {
var projectItem = projectItems[i];
if (projectItem.type === 1 // CLIP, BIN, ROOT, or FILE
&& projectItem.isSequence()) {
var sequence = projectItemToSequence(projectItem);
app.trace(sequence.name);
var videoTrack = sequence.videoTracks[0]
var clip = videoTrack.clips[0]
var components = clip.components;
//components[0].displayName
var qsequence = sequenceToQSequence(sequence);
var qclip = qsequence.getVideoTrackAt(0).getItemAt(0);
var effectComponent = getComponentByDisplayName(components, effectName);
if (!effectComponent) { // Add effect it not exists
qe.project.getVideoEffectList()
var effect = qe.project.getVideoEffectByName(effectName);
if (!effect.name) throw "Effect now found: " + effectName;
app.trace(effect.name);
qclip.addVideoEffect(effect);
sequence.projectItem.setColorLabel(colorLabelEffectAdded);
effectComponent = getComponentByDisplayName(components, effectName);
}
applyEffectProperties(effectComponent);
sequence.projectItem.setColorLabel(colorLabelEffectConfigured);
app.setSDKEventMessage("Started " + effectName + " to " + sequence.name , "info");
do {
$.sleep(1000);
} while (!sequence.isDoneAnalyzingForVideoEffects());
app.setSDKEventMessage("Completed " + effectName + " to " + sequence.name , "info");
sequence.projectItem.setColorLabel(colorLabelEffectAnalyzed);
}
}
app.setSDKEventMessage("Done", "info");
function projectItemToSequence(projectItem) {
for (var i = 0; i < app.project.sequences.numSequences; i++) {
if (projectItem.nodeId === app.project.sequences[i].projectItem.nodeId) {
return app.project.sequences[i];
}
}
return null;
}
function sequenceToQSequence(sequence) {
for (var i = 0; i < qe.project.numSequences; i++) {
var qsequence = qe.project.getSequenceAt(i);
if (qsequence.guid === sequence.sequenceID) {
return qsequence;
}
}
return null;
}
function applyEffectProperties(component) {
if (!component) return;
for (var i = 0; i < component.properties.length; i++) {
var property = component.properties[i];
switch (property.displayName) {
case "Smoothness":
property.setValue(smoothness, 1); // 1 means update gui
break;
case "Crop Less <-> Smooth More":
property.setValue(cropLessSmoothMore, 1); // 1 means update gui
break;
}
}
}