• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can I find the lightest and darkest frame of a video?

Community Beginner ,
Jun 30, 2023 Jun 30, 2023

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?

TOPICS
Error or problem , How to , Scripting

Views

857

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 01, 2023 Jul 01, 2023

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
...

Votes

Translate

Translate
Community Expert ,
Jun 30, 2023 Jun 30, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2023 Jul 01, 2023

Copy link to clipboard

Copied

I'm new to After Effects. How would I go about doing that?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2023 Jul 01, 2023

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2023 Jul 01, 2023

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".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2023 Jul 01, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2023 Jul 02, 2023

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 05, 2023 Jul 05, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 09, 2024 Jul 09, 2024

Copy link to clipboard

Copied

Hi!

 

sorry, where do i paste this expression? in "sampled color output"?

 

thank you so much!

 

Ines

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2024 Jul 09, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 09, 2024 Jul 09, 2024

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 09, 2024 Jul 09, 2024

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 09, 2024 Jul 09, 2024

Copy link to clipboard

Copied

LATEST

ok great thank you!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines