Skip to main content
Participating Frequently
November 23, 2025
Answered

how to get a number value that reflects the difference (screen mode) between 2 video layers

  • November 23, 2025
  • 6 replies
  • 196 views

hi all, 

i have a distorted (glitchy effect) video. (displace pro plug-in , the displacement map is taken from  a "old glitchy VHS video" resource, it alters the video by luminance/hue)

i would like that the sound also be "glitchy" as well, in sync with the glitched video.

 

want to use the Modulation effect on the audio layer, but i need a number value to link it to the parameters of the effect so the sound is altered when the video is slightly/very glitchy.

 

so i figured - if i can get a number value from an expression that calculates the difference between the original video footage and the final glitchy video footage - i could link that number to the Modulation parameters and the desired effect would be obtained.

 

so, can anyone tel me how to write that expression?

 

number = orig_layer - glitched_layer ?

 

would so much appreciate this.

 

i mean the internet is filled with "how to make video react to sound" but not 1 answer about the other way around.

ai provides some weird answers sometimes, it makes it seem like it can be don but it's way over my head / weird phrasing - cannot get it to work.

 

of course, if there's a way easier way to glitch the audio - i am open to suggestions.

 

thansk!!

Correct answer frigider5FF3

OK so i got it working i think, the slider gets a value 🙂

so you add a slider control to the layer (my case the layer with the hue/luminnace glitches - whitish pixels) then add this expression to the slider.

 

next step is to link audio distort effect to this slider value so audio is also glitchy.

 

// -- SETTINGS —
var threshold = 0.95;     // how “white” must a pixel be? (0–1)
var sampleRadius = [thisLayer.width/2, thisLayer.height/2]; 
// ———------
 
// Sample the entire layer
var avgColor = thisLayer.sampleImage(
    //thisLayer.sourceRectAtTime(time, false).center,
    position,
    sampleRadius,
    true,
    time
);
 
// Convert the average RGB to luminance (perceptual brightness)
var luminance = 0.2126*avgColor[0] + 0.7152*avgColor[1] + 0.0722*avgColor[2];
 
// Estimate % white based on luminance relative to threshold
var whiteness = clamp(luminance / threshold, 0, 1);
 
// Return percentage
whiteness * 100;

6 replies

frigider5FF3AuthorCorrect answer
Participating Frequently
November 27, 2025

OK so i got it working i think, the slider gets a value 🙂

so you add a slider control to the layer (my case the layer with the hue/luminnace glitches - whitish pixels) then add this expression to the slider.

 

next step is to link audio distort effect to this slider value so audio is also glitchy.

 

// -- SETTINGS —
var threshold = 0.95;     // how “white” must a pixel be? (0–1)
var sampleRadius = [thisLayer.width/2, thisLayer.height/2]; 
// ———------
 
// Sample the entire layer
var avgColor = thisLayer.sampleImage(
    //thisLayer.sourceRectAtTime(time, false).center,
    position,
    sampleRadius,
    true,
    time
);
 
// Convert the average RGB to luminance (perceptual brightness)
var luminance = 0.2126*avgColor[0] + 0.7152*avgColor[1] + 0.0722*avgColor[2];
 
// Estimate % white based on luminance relative to threshold
var whiteness = clamp(luminance / threshold, 0, 1);
 
// Return percentage
whiteness * 100;
Participating Frequently
November 26, 2025

initial code was like this:

 

// -- SETTINGS —

var threshold = 0.95;     // how “white” must a pixel be? (0–1)

var sampleRadius = [thisLayer.width/2, thisLayer.height/2]; 

// ———------

 

// Sample the entire layer

var avgColor = thisLayer.sampleImage(

    thisLayer.sourceRectAtTime(time, false).center,

    sampleRadius,

    true,

    time

);

 

// Convert the average RGB to luminance (perceptual brightness)

var luminance = 0.2126*avgColor[0] + 0.7152*avgColor[1] + 0.0722*avgColor[2];

 

// Estimate % white based on luminance relative to threshold

var whiteness = clamp(luminance / threshold, 0, 1);

 

// Return percentage

whiteness * 100;

 

but it gave the error that sampleimage's first 2 parameters must be numbers..

so i googled some more and ended up with the form in the post above,

as you can see i am fumbling in the dark blindfolded.

Participating Frequently
November 26, 2025

asked chat gpt for some help, i got something like this:

 

// -- SETTINGS —
var threshold = 0.95; // how “white” must a pixel be? (0–1)
// not used: var sampleRadius = [thisLayer.width/2, thisLayer.height/2];
// ———------

// Sample the entire layer
var avgColor = thisLayer.sampleImage(position, radius = [.5, .5], postEffect = true, t = time)[0];

// Convert the average RGB to luminance (perceptual brightness)
var luminance = 0.2126*avgColor[0] + 0.7152*avgColor[1] + 0.0722*avgColor[2];

// Estimate % white based on luminance relative to threshold
var whiteness = clamp(luminance / threshold, 0, 1);

// Return percentage
whiteness * 100;

 

but at this last line it says "couldn't turn result into a numeric value" 

luminance looks like a number to me, whiteness looks like a number as well..

omg.

 

Participating Frequently
November 24, 2025

i found this other post here

https://community.adobe.com/t5/after-effects-discussions/how-can-i-get-high-and-low-value-of-a-histogram/m-p/6802660 

 

there's a solution there and i don't even know what to do with it, overly complex.

was really hoping for an expresison that just gets me a number 😞 

 

tried googling "how much of a layer is white in %" and to not much avail.

Participating Frequently
November 24, 2025

from what i can see in that link it gets the average color in a certain area.

i need a hard number.

 

currently googling for ways to count in % how much of a layer is of a certain color (white) - so i can work on the distortion layer directly, no more complicated operations between 2 different layers.

i hope.

ShiveringCactus
Community Expert
Community Expert
November 24, 2025

I take it the glitchy effect doesn't include keyframes?

 

I think the simplest approach would be to use sample image().  This can return colour and alpha values from a layer at a specific point.  So if you glitch always makes part of the screen white, you should be able to get a value from that.

 

As always Dan Ebberts has a good write up: https://www.motionscript.com/design-guide/sample-image.html

Participating Frequently
November 24, 2025

hi and thank you for the reply.

 

yes, no keyframes, the displacer pro takes the displace map from the hue/luminance of the VHS video resource.

^that is where the white resides. (white glitches on black background)

the glitchy video is not getting white added in the "glitches", it just gets distorted (stretched/moved etc.).

 

maybe this "measure the white" can actually work  - i can take it from the VHS distort video.

 

i will look into it, i have 0 knowledge of expressions other than wiggle() 🙂 

but i will give it a read and see where it takes me.

really sounds like a solution.

 

thanks again!