Copy link to clipboard
Copied
I've been trying to create a script with ChatGPT and it's very buggy. What I've tried to do is render a video in black and white, at 1/4 resolution, cropped so that it's just the center, and only rendering 1 frame every 300 frames, in order for me to get a rapid render so I can roughly know which part of the video is the darkest.
Not only have I not been able to get that script to work the way I want it to, but I have no clue how to get it to scan the video for the lightest and darkest frame after render.
Any ideas?
Something like this, basically:
function getLightestAndDarkest(){
var fO = 300; // frame offset
var sR = 25; // sample radius
var comp = app.project.activeItem;
if (comp && comp instanceof CompItem){
var layer = comp.layer(1);
var pt = [layer.width/2,layer.height/2];
var lightExpr = "s = sampleImage([" + pt[0] + "," + pt[1] + "],[" + sR + "," + sR + "],false,time);\rrgbToHsl(s)[2];";
var slider = layer.property("Effects").addProperty("ADBE Slider Control");
slider.property("ADBE Sl
...
Copy link to clipboard
Copied
Scripting doesn't have the tools to evaluate luminance like that. Your script would have to apply a sampleImage() expression and harvest the result. And if you're going to do that, there's no need to render anything out--you could just put your comp in another comp and apply sampleImage() to the comp layer and harvest the result at whatever interval you want.
Copy link to clipboard
Copied
I'm new to After Effects. How would I go about doing that?
Copy link to clipboard
Copied
Something like this, basically:
function getLightestAndDarkest(){
var fO = 300; // frame offset
var sR = 25; // sample radius
var comp = app.project.activeItem;
if (comp && comp instanceof CompItem){
var layer = comp.layer(1);
var pt = [layer.width/2,layer.height/2];
var lightExpr = "s = sampleImage([" + pt[0] + "," + pt[1] + "],[" + sR + "," + sR + "],false,time);\rrgbToHsl(s)[2];";
var slider = layer.property("Effects").addProperty("ADBE Slider Control");
slider.property("ADBE Slider Control-0001").expression = lightExpr;
var sliderMin = 1;
var sliderMax = 0;
var frameMin = 0;
var frameMax = 0;
var f = 0;
var t = 0;
var curVal;
while (t < comp.duration){
curVal = slider.property("ADBE Slider Control-0001").valueAtTime(t,false);
if (curVal > sliderMax){
sliderMax = curVal;
frameMax = f;
}
if (curVal < sliderMin){
sliderMin = curVal;
frameMin = f;
}
f += fO;
t = f*comp.frameDuration;
}
slider.remove();
alert ("Lightest frame = " + frameMax + "\nDarkest frame = " + frameMin);
}else{
alert("No comp active.");
}
}
getLightestAndDarkest();
Copy link to clipboard
Copied
Oh wow. Did you write that? If so, thanks so much!
So how would I use it? I just ran the script and it instantly printed "Lightest Frame = 0, Darkest Frame = 0".
Copy link to clipboard
Copied
Oh, I got it working. This is amazing, and so much better than I could have expected, seriously, thank you. I have been working on this for days!
Really really appreciate that you did this, especially when you didn't have to.
Copy link to clipboard
Copied
It's just a demo of how I'd approach it. It could be fleshed out to make it a lot more user friendly, possibly with a UI to let you enter the various parameters, rather than having to hard code them into the script. But UIs are another story...
Copy link to clipboard
Copied
It's okay. This is just created for a base template for future videos. I've used ChatGPT to add some additional functions to the script. But do you know if there's any way of making it only sample from a set radius, if it could instead sample the brightness from a mask?
I want it to scan the brightness of my strangely shaped mask.
Copy link to clipboard
Copied
Hi!
sorry, where do i paste this expression? in "sampled color output"?
thank you so much!
Ines
Copy link to clipboard
Copied
If you're talking about the code I provided, it's a script, not an expression. The script applies an expression to a slider that it creates, but I'm not sure if that's what you're referring to.
Copy link to clipboard
Copied
Hello Dan,
thank you so much for the super fast reply. Yes if got confused, sorry. I guess my question is, how can i use your script. I understand i need to use a program like " Adobe ExtendScript Toolkit (ESTK) or Visual Studio Code" to paste your script and save it in order to save it on the "scripts" folder. Is that correct?
thank you!
Copy link to clipboard
Copied
You can also just copy and paste it into a simple text editor (one that doesn't modify the text--like changing quotes to curly quotes) and save it as a .jsx file (with UTF-8 encoding). Then just navigate to it from File > Scripts > Run Script File...
Copy link to clipboard
Copied
ok great thank you!!