Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions get average hsl value from multiple frames

  • get average hsl value from multiple frames

    Posted by Pierre-alexis Tremblay on June 30, 2009 at 7:38 pm

    I’m not sure how to put this…
    How to set the opacity of a layer based on the average brightness of the underlying layer which is let’s say a movie clip but I need this value to be constant, so the value would be a combination of an average from the image area and from the time range (?)

    P.A.T.

    Dan Ebberts replied 16 years, 10 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    June 30, 2009 at 8:19 pm

    This should get you close:

    L = thisComp.layer(“Your Movie”);
    startRange = L.inPoint;
    stopRange = L.outPoint;
    accum = 0;
    n = 0;
    for (i = timeToFrames(startRange); i < timeToFrames(stopRange); i++){ rgba = L.sampleImage([L.width/2,L.height/2],[L.width/2,L.height/2],true,framesToTime(i)); accum += rgbToHsl(rgba)[2]; n++; } linear(accum/n,0,1,0,100) Dan

  • Pierre-alexis Tremblay

    July 2, 2009 at 3:40 pm

    Works fine, thanks a lot!

    Would it be possible to adapt this so it would get the average brightness of all the underlying layers as if they were a composite?

    P.A.T.

  • Dan Ebberts

    July 2, 2009 at 5:49 pm

    Sure, you’d just need to add an outer loop that cycles through all the layers you’re interested in, adds the result to an accumulator total variable and (at the end) divides by the number of layers. The exact code would depend on which layers you’re after.

    Dan

  • Pierre-alexis Tremblay

    July 2, 2009 at 8:25 pm

    Could I turn the last value (the 100 at the end) into a variable that would get its value from an external text file?

    P.A.T.

  • Dan Ebberts

    July 3, 2009 at 3:01 am

    Sure, just put a valid JavaScript statment in the file, like this:

    maxOpacity = 75;

    Do an eval() of the file, as in the other recent threads, and change the last line to this:

    linear(accum/n,0,1,0,maxOpacity)

    Dan

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy