Copy link to clipboard
Copied
I work with a lot of hand-drawn loops and I'm curious about expressions that can randomize the frame playback of image sequences using the time-remapping property.
For example, in traditional hand-drawn animation when you wanted to hold a pose without the animation looking static you would create what's called a traceback, which means you would physically trace at least 8 frames of the same drawing and then shoot them over and over again in a random order for however long you needed to hold the pose. That way you don't get the exact same pattern of frames cycling over and over like you would if you just looped it.
Of course you can manually reorder frames in After Effects, but it's very time-consuming and I'm wondering if an expression could be written that could easily be modified for different sequences at different timings and different lengths. For instance, I found this expression by Filip Vandueren on the Creative Cow website http://forums.creativecow.net/thread/227/12413 It was intended to randomize a 5 frame sequence, however the sequence and the comp have to be at the same frame-rate in order for it to work. Therefore, I have to work at a 12fps sequence in a 12fps comp if I want the animation to look like it was shot on 2s. Usually a 12fps sequence with no time remap expressions will play back on 2s if it's in a 24fps comp and as far as I can tell using time stretch or posterize time doesn't work. Time stretch does nothing and posterize time crashes after effects when I add it to the image squence with the expression applied to the time-remapping property. This probably has something to do with an expressions conflict that happens once time remapping is applied to the image sequence. Anyhow, I'm asking if there's a way to modify this expression so that I could put my footage into a comp at another frame rate and use the expression itself to tell it to play at either 8fps, 12fps or any other frame rate.
This is Filip Vandueren's expression
seedRandom(1,true);
var t=timeToFrames();
var r1=-3;
var r2=-2;
var r3=-1;
for (var i=0;t>=i; i++) {
var r3=Math.floor(random(5));
if (r1==r3 || r2==r3) {
t++;
continue;
}
r1=r2;
r2=r3;
}
framesToTime(r3);
This is an expression based on Vandueren's that I tried to modify for an 8 frame image sequence. It sort of worked but it didn't really achieve what I was looking for.
timeRemap
seedRandom(2,true);
var t=timeToFrames();
var r1=-6;
var r2=-5;
var r3=-4;
var r4=-3;
var r5=-2;
var r6=-1;
for (var i=0;t>=i; i++) {
var r3=Math.floor(random(8));
if (r1==r3 || r2==r3) {
t++;
continue;
}
r1=r2;
r2=r3;
}
framesToTime(r3);
The image sequence played all 8 frames randomly without duplicating them, but I still couldn't figure out how to make it play at 8fps or 12fps without conforming the comp frame rate to the frame rate of the image sequence. Ideally I'd like the expression to determine the frame rate so that I can have it in a comp with other frame rates and not have to worry about disturbing the expression.
Reordering random frames is a common thing for 2D animators to do so I'll also file a feature request asking After Effects to add this feature to an existing plug-in or create a standalone plug-in.
This should work:
fr = 12; // frame rate;
numFrames = 8;
seedRandom(index,true);
seg = Math.floor(time*fr);
f = Math.floor(random(numFrames));
for (i = 0; i < seg; i++)
f = (f + Math.floor(random(1,numFrames)))%numFrames;
framesToTime(f);
Dan
Copy link to clipboard
Copied
Something like this maybe:
fr = 12; // frame rate;
numFrames = 8;
seed = Math.floor(time*fr);
seedRandom(seed,true);
framesToTime(Math.floor(random(numFrames)));
Dan
Copy link to clipboard
Copied
Yeah it's almost there. It's playing on 2s, but I'm guessing it's too random so I'm still getting some points in the sequence where I'll get four of the same frames in a row. What's cool about Vandueren's expression is that it never repeats frames.
Copy link to clipboard
Copied
This should work:
fr = 12; // frame rate;
numFrames = 8;
seedRandom(index,true);
seg = Math.floor(time*fr);
f = Math.floor(random(numFrames));
for (i = 0; i < seg; i++)
f = (f + Math.floor(random(1,numFrames)))%numFrames;
framesToTime(f);
Dan
Copy link to clipboard
Copied
Fantastically useful script. Looks like it works for any frame rate and for any number of frames in the sequence. Thanks Dan.
Copy link to clipboard
Copied
Looks like it's acting funny. For whatever reason I got some expression error that said it timed out and now I get duplicating frames in the expression again every time I insert it.
Copy link to clipboard
Copied
Nevermind I restarted After Effects and it works fine.
Copy link to clipboard
Copied
Dan,
Here is a tutorial I wrote that features the expresssion you wrote. Thanks.
Working With Image Sequences in Photoshop & After Effects CS6
I hope others find this expression useful.
Copy link to clipboard
Copied
Hello,
I am struggling to find a way of applying jump cuts to my composition without repeating any frames clips.
I first precomposed multiple clips and then applied time remapping. It works fine when it comes to jumping from cut to cut randomly, but I would like on top of this to stop it from repeating the clips. Does it make sense?
This is the expression I used:
segDur = .5;// duration of each "segment" of random time minVal = inPoint; maxVal = outPoint - segDur; seed = Math.floor(time/segDur); segStart = seed*segDur; seedRandom(seed,true); startVal = random(minVal,maxVal); endVal = startVal + segDur; linear(time,segStart,segStart + segDur, startVal, endVal);
Copy link to clipboard
Copied
This script was just what I needed, and works great 9 years after this comment. Thank you Dan, whenever I see your name in a thread about expressions, I know everything is going to be okay.
Copy link to clipboard
Copied
Does anyone know of a way to modify this expression so that it's still random, but there are never any repeating frames back to back?
fr = 12; // frame rate;
numFrames = 8;
seedRandom(index,true);
seg = Math.floor(time*fr);
f = Math.floor(random(numFrames));
for (i = 0; i < seg; i++)
f = (f + Math.floor(random(1,numFrames)))%numFrames;
framesToTime(f);
Copy link to clipboard
Copied
I think it's already set up that way. Is that not what you're seeing? If I look at time remapping in the graph editor, I don't see any repeats.
Dan
Copy link to clipboard
Copied
Hi, I have just found this script - it's great thank you, however, I want multiple instances of these random images in the same comp. Is it possible to modify the expression and have a different random seed for each layer? And, I don't know if this is really pushing it too far, would it be possible to modify the expression to add a dissolve between each random image? Apologies if I am not being clear.