ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Add marker everytime a value is detected

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Rodrigo Aben
Add marker everytime a value is detected
on Apr 27, 2020 at 2:18:06 am

I wrote the code below to detect whether opacity value meets a certain threshold and add a marker, except it stops at the first time it finds the value.

I want it to continue finding matches and add multiple markers until it reaches frame 100.

What am I missing?

Thanks!

var comp = app.project.activeItem;
var videoLayer = comp.selectedLayers[0];
var time = comp.time;
var frame = Math.round(time/comp.frameDuration);
var opacityLevel = videoLayer.property("Transform").property("Opacity");
var threshold = 48.0;

above = false;
while (true){
t = frame * comp.frameDuration;
if (above){
if (opacityLevel.valueAtTime(t,true) != threshold){
frame++;
}
}else if (opacityLevel.valueAtTime(t,true) == threshold){
above = true;
var myMarker = new MarkerValue("Cut");
videoLayer.property("Marker").setValueAtTime(t, myMarker);
}
if (frame == 100){
break;
}
frame++;
}


Return to posts index

Andrei Popa
Re: Add marker everytime a value is detected
on Apr 27, 2020 at 7:00:31 am

First of all, never do a while loop with a condition that is always true. You should put your break condition there.

And your above variable does not let the script check again for threshold equality. You must have a situation when that gets back to false.

Haven't tested, but give this a try:


var comp = app.project.activeItem;
var videoLayer = comp.selectedLayers[0];
var time = comp.time;
var frame = Math.round(time / comp.frameDuration);
var opacityLevel = videoLayer.property("Transform").property("Opacity");
var threshold = 48.0;

above = false;
while (frame <= 100) {
t = frame * comp.frameDuration;
if (above) {
if (opacityLevel.valueAtTime(t, true) != threshold) {
frame++;
above = false;
}
} else if (opacityLevel.valueAtTime(t, true) == threshold) {
above = true;
var myMarker = new MarkerValue("Cut");
videoLayer.property("Marker").setValueAtTime(t, myMarker);
}
frame++;
}


Andrei
My Envato portfolio.


Return to posts index

Rodrigo Aben
Re: Add marker everytime a value is detected
on Apr 27, 2020 at 5:59:45 pm

Works like a charm! Thanks Andrei!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]