Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Opacity based on RGBA from sampleImage

  • Opacity based on RGBA from sampleImage

    Posted by Royce Jacobs on February 11, 2019 at 2:27 am

    So I have a video layer with only 2 rgba states, back and forth at various times.. and I want to use the rgba change to trigger the opacity on and off for another layer. As a test, I made a text layer and put the following on the source text:

    videoLayer = thisComp.layer(“Video-01”);//Layer to read rgba values from.
    videoDetect = videoLayer.sampleImage(transform.position, [width, height]/2, true, time);//Reading rgba values.
    if(parseInt(videoDetect*100) > 77){100 + “\r” + parseInt(videoDetect*100)}else{0 + “\r” + parseInt(videoDetect*100)}

    On the one video layer state I get:
    0
    74

    On the other I get:
    100
    79

    Seems good so far.. I originally was using Math.floor(videoDetect) but it returned as NaN, so I used parseInt() to convert it. I think that’s right…. right?
    So now on the layer to trigger turning off, I have the following on the Opacity parameter; same as above, but with simply the opacity values for the “if” results:

    videoLayer = thisComp.layer(“Video-01”);//Layer to read rgba values from.
    videoDetect = videoLayer.sampleImage(transform.position, [width, height]/2, true, time);//Reading rgba values.
    if(parseInt(videoDetect*100) > 77){100}else{0}

    But the opacity stays at 0 regardless of the video changing. Why isn’t my true state checking out, even though it seems to do so on the text layer? I very much appreciate any input!

    – Royce

    videoLayer = thisComp.layer("Video-01");//Layer to read rgba values from.
    videoDetect = videoLayer.sampleImage(transform.position, [width, height]/2, true, time);//Reading rgba values.
    if(parseInt(videoDetect*100) > 77){100}else{0}

    Dan Ebberts replied 7 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Royce Jacobs

    February 11, 2019 at 2:45 am

    So, quick update, I actually made a slider on the text layer and copy/pasta’d the opacity code onto it, and the slider changed from 0 & 100 at the correct times. Then I simply erased the code on the opacity, and pickwhipped it to the slider on the text layer and it works great!

    What a bizarre work-around.. and honestly I still want to figure out why the same exact code wouldn’t work on the opacity parameter. Anyone have any thoughts?

  • Dan Ebberts

    February 11, 2019 at 3:52 am

    I’m surprised that it works at all, because videoDetect should be an array of rgba values, so I would have guessed that parseInt() would have returned NaN if you feed it an array, but apparently it finds the first element of the array (the red channel, in this case). You learn something every day.

    Dan

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