Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Time remapping random frames between the value of keyframes

  • Time remapping random frames between the value of keyframes

    Posted by Bill Porter on August 6, 2013 at 4:29 pm

    Hi

    Is there a way to make a time remap expression that goes to random frames between the values of it’s keyframes?

    So, say I put a time remap keyframe every 25 frames on some footage at 25fps, the expression will pick random frames beween 0 and 25 for the first second. Then for the second second it’ll pick random frames between 25 and 50. Third second 50 – 75, and so on and so forth…

    Hope that makes sense.

    To throw into the mix! Is there a way to combine the ‘boil’ random frame expression so you don’t get two of the same frames next to each other. I’ve seen good posts about it before but not sure how it would combine wit the above.

    I wish I could fathom it myself but I’m a ninny at grasping code. Any help would be much appreciated.

    Bill Porter replied 12 years, 9 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    August 6, 2013 at 5:54 pm

    See if this does what you want:


    if ((numKeys > 1) && (time >= key(1).time) && (time < key(numKeys).time)){
    k = nearestKey(time);
    if (time < k.time){
    k1 = key(k.index-1);
    k2 = k;
    }else{
    k1 = k;
    k2 = key(k.index+1);
    }
    f1 = timeToFrames(k1.time);
    f2 = timeToFrames(k2.time);
    a = [];
    for (i = f1; i <= f2; i++) a.push(i);
    seedRandom(index,true);
    for (i = 0; i < a.length; i++){
    idx = i + Math.floor(random(a.length - i));
    temp = a[i];
    a[i] = a[idx];
    a[idx] = temp;
    }
    f = timeToFrames(time);
    framesToTime(a[f-f1]);
    }else
    value

    Dan

  • Bill Porter

    August 6, 2013 at 6:20 pm

    Hi Dan,

    Thank you for looking at this!

    It works perfectly between the first and second keyframes when I scrobble through. But when I go past the second keyframe, or ram preview, it disables, saying

    ‘Class ‘Array’ has no property or method named ‘1’
    Error occured at line 22…

    I’m using cs5.5 – not sure if it’s anything to do with it?

  • Dan Ebberts

    August 6, 2013 at 8:55 pm

    I couldn’t reproduce the problem, but I did discover a couple of errors in the code. This should work better:


    if ((numKeys > 1) && (time >= key(1).time) && (time < key(numKeys).time)){
    k = nearestKey(time);
    if (time < k.time){
    k1 = key(k.index-1);
    k2 = k;
    }else{
    k1 = k;
    k2 = key(k.index+1);
    }
    f1 = timeToFrames(k1.time);
    f2 = timeToFrames(k2.time);
    a = [];
    if (f2 > f1)
    for (i = f1; i <= f2; i++) a.push(i)
    else
    for (i = f2; i <= f1; i++) a.push(i);
    seedRandom(index,true);
    for (i = 0; i < a.length; i++){
    idx = i + Math.floor(random(a.length - i));
    temp = a[i];
    a[i] = a[idx];
    a[idx] = temp;
    }
    f = timeToFrames(time);
    valueAtTime(framesToTime(a[f-f1]));
    }else
    value

    If it still fails for you, please provide more details about your keyframe values and times (maybe a screenshot).

    Dan

  • Bill Porter

    August 7, 2013 at 4:35 pm

    Aaaamazing. Works flawlessly, Dan. Thank you so much for the fast and expert response, it really helped me out. You are an angel!

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