Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Accumulate values

  • Posted by Simon Francois on April 14, 2015 at 3:03 am

    Hi all,
    I’m kind of beginning with expressions in After Effects, and most of its grammar is still quite foggy to me.

    I’ve been successing to achieve something I’ve been trying to do with a video I’m working on, up to a point, where I figured that what I needed in my script was a sort of accumulation of values request.

    I’ve been reading here and there on the Cow forums solutions to do so, but could never translate it into my own needs. Here is my problem:

    I’m working on very slow motion video that should speed up and slow down according to the audio that accompanies it.

    In a very basic fashion, I started with that piece of code, which I thought was a start, but obviously doesn’t drive me toward what I’m aiming:
    time+((thisComp.layer(“Amplitude audio”).effect(“Les deux couches”)(“Curseur”))

    (for non-french speakers: “Les deux couches” means “the two layers”, and “curseur” is “slider” meaning I guess the audio level indicator)

    The thing is, with this segement, when the audio spectrum lowers in value, in goes back in “time” (or what is added to the time lowers, and thus goes back to the “normal” curse of time).

    I think what is need here is something that sums up the audio value throughout the whole, frame after frame, and that keeps adding that to the time. In that sense, it will be like only the speed is chaging.

    Can someone help? I’ve seen many of Dan Hebberts around that topic, but by lacking deeper knowledge, couldn’t really handle the solutions provided.

    Thanks for your help

    Simon Francois replied 11 years, 3 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    April 14, 2015 at 5:57 am

    Unfortunately, at each frame, your expression will have to accumulate the value of all the previous frames, so if your comp is very long, the processing can get very slow. The accumulator code should look something like this (sorry for the mixture of French and English, but you get the idea):

    s = thisComp.layer(“Amplitude audio”).effect(“Les deux couches”)(“Curseur”);
    accum = 0;
    for (i = timeToFrames(inPoint); i <= timeToFrames(time); i++){
    accum += s.valueAtTime(framesToTime(i));
    }

    Then I assume you’ll need to translate the accumulator value to a time remapping value, probably by multiplying by some constant.

    Dan

  • Simon Francois

    April 14, 2015 at 6:13 pm

    Thanks a lot Dan! It works just fine.

    Could you just explain me what each of the segements of the third and fourth lines stand for?
    I’ve been looking for explanations around, but can not find for example what is the purpose of += or ++…

    Thanks again for your great help.

  • Dan Ebberts

    April 14, 2015 at 6:25 pm

    Those are just JavaScript operators.

    i++;

    is the same as:

    i = i +1;

    accum += s.valueAtTime(framesToTime(i));

    is the same as:

    accum = accum + s.valueAtTime(framesToTime(i));

    Dan

  • Simon Francois

    April 14, 2015 at 6:34 pm

    Thanks!

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