ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Time Remap controlled by SampleImage

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
jay ingles
Time Remap controlled by SampleImage
on Jun 3, 2011 at 10:52:49 pm

How would i use sampleimage to change a layers "timeRemap" value from between 0 to 5?

I've precomposed a timeline that is 5 frames long and 400x400 pixels, each frame with a different shape. Duplicating that precomp to create a grid (image 1) i want the Black & White Luma matte (image 2) to control the time remap value. Ie Black = 0f, grey = 3f, White = 5f.

I've used sample image with affecting scale but can't wrap my head around accomplishing it for this use.

Image 1:


Image2:


In the past i've used the code below to do so with the Scale parameter.

Any help is appreciated, Thanks a lot!

size = thisComp.layer("luma").sampleImage([transform.position[0],transform.position[1]], [1,1] ,posteffect = true);

transform.scale = [size[3]*100,size[3]*100,100];


Return to posts index

Dan Ebberts
Re: Time Remap controlled by SampleImage
on Jun 3, 2011 at 11:27:29 pm

I haven't tested this, but it's probably going to look like this:

s = thisComp.layer("luma").sampleImage(transform.position,[.5,.5],true);
luma = rgbToHsl(s)[2];
maxFrame = 5;
f = Math.round(maxFrame*luma);
framesToTime(f)



Dan



Return to posts index

jay ingles
Re: Time Remap controlled by SampleImage
on Jun 4, 2011 at 12:28:23 am

Wow, quick at responding, Thanks Dan.

I'll give that a shot!


Return to posts index


jay ingles
Re: Time Remap controlled by SampleImage
on Jun 4, 2011 at 10:35:47 pm

Hi Dan,

Seems to work but i keep running into hundreds of "unsafe operation attempted" errors. I found this article that explains SampleImage has a flaw in it that can create this scenario.

http://forums.adobe.com/thread/693859

It suggest to add layer space transforms such as .toComp() for such operations. Likewise, when dealing with colors, always make sure to use the correct syntax to conatin all color components in arrays.

Adding that statement in creates an error and turns the expression off. I'm sure i'm doing it incorrectly but interested if you have experienced this.

Attempted this: framesToTime.toComp((f))

Thanks so much!


Return to posts index

Dan Ebberts
Re: Time Remap controlled by SampleImage
on Jun 4, 2011 at 10:56:26 pm

Try it this way:

L = thisComp.layer("luma");
p = L.fromComp(toComp(transform.anchorPoint));
s = L.sampleImage(p,[.5,.5],true);
luma = rgbToHsl(s)[2];
maxFrame = 5;
f = Math.round(maxFrame*luma);
framesToTime(f)



Dan



Return to posts index

leif falk
Re: Time Remap controlled by SampleImage
on Jul 8, 2012 at 3:46:26 pm

Hi Everybody
I am getting the same error and the whole world of google gives only 8 hits:
http://tinyurl.com/d36t5nz

Dan, your last script doesn´t seem to resolve the error, i am getting the same message like before.
Jay, Did you solve it someow?

THanks for the great support here.


Return to posts index


Dan Ebberts
Re: Time Remap controlled by SampleImage
on Jul 8, 2012 at 5:11:04 pm

I can't generate that error, so I'm not sure how to fix it. One thing you want to avoid is using sampleImage() with time remapping in a way where the result of the expression can affect its own input. I don't know if that applies to your case.

Dan



Return to posts index

leif falk
Re: Time Remap controlled by SampleImage
on Jul 9, 2012 at 1:01:55 pm

Hallo Dan
Thank you for your help.
I broke down my project to just two layers, and for every item I deleted, the error-message became more rarely, but it is still there.
I attached a very simple AE file. Have the layer FORM in MAIN selected, go into the FORM Comp, change the inpoint or the outpoint of the shapelayer, or the position of the rotation keyframe. Go Back to the main comp and change the color of the circle in the LUMA Layer. Repeat these steps, or change other things, and the error message will occur. I tested here on CS3 and with CS5 at work, several times.
And the more items are in the composition, the more often the error occurs. I get a little crazy I guess.
Here is the project-file:
4387_unbenanntesprojekt.aep.zip



Return to posts index

leif falk
Re: Time Remap controlled by SampleImage
on Jul 9, 2012 at 1:15:53 pm

Change the in and outpoints of the "Luma" layer also, and repeat the steps. The error will appear.
By the way: The problem isn´t this comp, I could easily live with that rarely appearing error message, but if I use this method to drive a grid of layers like in the first post, and have other things going on in the comp, it really gets annoying.


Return to posts index


jay ingles
Re: Time Remap controlled by SampleImage
on Jul 9, 2012 at 1:22:19 pm

Hey All,

I ended up not resolving this issue and resorted to the Scale based SampleImage code pasted above.

Wish i could help more but not sure how to resolve it. Does precomposing the retimed footage help at all? Or is there any way to precomp it and point the remap to look inside the precomp?

Really not sure if this would work, but am throwing it out there incase it has to do with the order AE is doing it's math.

Good luck! Please post here if you figure it out :)


Return to posts index

leif falk
Re: Time Remap controlled by SampleImage
on Jul 9, 2012 at 3:54:52 pm

Hi again
I couldn´t figure out how to avoid this nasty message. But I found a way to reproduce the error instantly in my example file.
Make a Ram Preview of MAIN. Go into FORM, grab and pull the In-point of the shape-layer forwards, got back to MAIN Comp and the Error will appear. If anyone could help here, It would be so great.


Return to posts index

Dan Ebberts
Re: Time Remap controlled by SampleImage
on Jul 9, 2012 at 4:41:34 pm

I can generate the error immediately in AE CS5, but not in CS5.5 or CS6. I don't know what the problem is, but it looks to me like they may have fixed it.

Dan



Return to posts index


leif falk
Re: Time Remap controlled by SampleImage
on Jul 10, 2012 at 12:51:03 pm

Hi guys
For those who have older versions, here is what I ended up with and I am quite satisfied:

Instead of writing the expression into "timeremap" I used the effect "timewarp" which also has an option for "source frame". For this I wrote Dans expression, (but without the Math.round for smoother results.)

L = thisComp.layer("luma");
p = L.fromComp(toComp(transform.anchorPoint));
s = L.sampleImage(p,[.5,.5],true);
luma = rgbToHsl(s)[2];
maxFrame = 300;
f = maxFrame*luma;
framesToTime(f)

The one problematic difference is, the effect time warp doesn´t look in-between frames in the nested comp, like "time remapping" does, so you will not have the same smoothness, but here is a little trick:
Just use "time-remapping" as well without any expression, and give it a lot of space. For example if your nested comp is 30 Frames long, span this 30 Frames with time Remap over a space of 300 Frames, so the "Time Warp" effect has a lot of real in-between Frames, (not calculated ones through FrameMix or PixelMotion).
Give it a try..


Return to posts index

jay ingles
Re: Time Remap controlled by SampleImage
on Mar 17, 2018 at 7:13:00 pm

Thanks again for previous input, I'm back with an evolved version of this technique.

Imagine there is a dancer with 6 main poses/dances and based on opacity of a base layer we want to transition to a different dance.

In the end this will be a grid wall of dancers. Up until now the thread above allows switching to a SINGLE frame based on an alpha via SampleImage, but doesn't allow that new frame to keep playing out (and looping).

How would I modify the code to achieve this? The dances could be all in one main composition and we jump to a specific range of the sequence, OR a separate shorter comp for each dance (which loops).

12262_dancergrid.aep.zip - example setup

Thanks!

L = thisComp.layer("luma");
p = L.fromComp(toComp(transform.anchorPoint));
s = L.sampleImage(p,[.5,.5],true);
luma = rgbToHsl(s)[2];
maxFrame = thisComp.layer("ref").effect("# Frames")("Slider");
f = Math.round(maxFrame*luma);
framesToTime(f)


Return to posts index

Dan Ebberts
Re: Time Remap controlled by SampleImage
on Mar 17, 2018 at 7:56:04 pm

The problem is, I think, that for this to work, the expression would need to figure out how long the luma has been at its current value. To do that, it would need to work backward in time, frame-by-frame (using the time parameter of sampleImage()) looking for a change in luma. And that would only work well with step changes in luma--fading wouldn't work well. Not impossible, but tricky to set up and maybe cpu intensive if the loops get long.

Dan



Return to posts index


jay ingles
Re: Time Remap controlled by SampleImage
on Mar 17, 2018 at 9:11:05 pm

Hi Dan, thanks for the quick reply.

Assuming all 'dance scenes' are the same duration (lets say 100 frames), would it not be able to do the following...

If base luma = 30%, jump to frame 300 & start playing for 100 frames
if hit frame 399 reverse frame playback.
check on each new frame if base luma has changed, if not continue playing next frame

Seems like its getting complex, but is it feasible? I was really hoping to achieve this in C4D with effectors but haven't been able to get that working. It may turn into manually placing/timing each quadrant ☹

Thanks again for any input.


Return to posts index

Dan Ebberts
Re: Time Remap controlled by SampleImage
on Mar 17, 2018 at 9:15:19 pm

Sure, if you can make that assumption so that you can calculate the current elapsed run time based on the luma level, that makes it pretty straightforward.

Dan



Return to posts index

jay ingles
Re: Time Remap controlled by SampleImage
on Mar 23, 2018 at 3:38:52 pm

Thanks again for your input. I tried to merge 2 portions of code which uses the sampleImage and based on that result triggers a playback. The code is pseuodo code i suppose.

I know i'm missing something especially with regard to getting the scene to play and increment frames once it understands what scene to playback.

Where am I going wrong?

//previous sample image based on layer position
L = thisComp.layer("luma");
p = L.fromComp(toComp(transform.anchorPoint));
s = L.sampleImage(p,[.5,.5],true);
luma = rgbToHsl(s)[2];
//maxFrame = effect("# Frames")("Slider"); //erase?
//f = Math.round(maxFrame*luma); //erase?

//Define "trigger" from our sample results
trigger = luma;

//Define how many scenes in the precomp and how long each will play for
SceneCount = 10; //slider ... how many areas to playback
SceneDuration = 100; //length of each scene in frames

if (trigger == 10){ //start playback at scene 10 which is frame 100
frame = (trigger*SceneCount) ++; // Start playback at frame 100 if luma = 10%

}else if (trigger == 20){
frame = (trigger*SceneCount) ++; // Start playback at frame 200 if luma = 20%
}

}else if (trigger == 30){
frame = (trigger*SceneCount) ++; // Start playback at frame 300 if luma = 30%
}

t = Math.min(t, tMax);
//t = frame * thisComp.frameDuration;
framesToTime(t);


Return to posts index


Dan Ebberts
Re: Time Remap controlled by SampleImage
on Mar 23, 2018 at 5:26:51 pm

I think the issue is still the same. The expression has to be able to calculate how long ago the current luma value was first reached. I'm thinking again, that you'll have to do this by looping back in time, frame by frame until you find when the luma was a different value.

Dan



Return to posts index

jay ingles
Re: Time Remap controlled by SampleImage
on Mar 24, 2018 at 11:46:19 am
Last Edited By jay ingles on Mar 24, 2018 at 12:10:46 pm

That's too bad, but thanks for explaining it.

Do you have any suggestions on how to achieve something similar visually? IE Initiating layer to play in a more automated way OR working with Markers in a more graphic way? There are lots of scripts to choose from but they mostly just appear to slide layers (or markers) on exponential or linear curves.

My only approach I can think of is using your "trigger by markers" approach on 1 horizontal line, then precomping 1 row, repeating, and offsetting all layers.

Unfortunately this largely restricts actions what type of patterns can be created and is quite laborious.
: /


Return to posts index

jay ingles
Re: Time Remap controlled by SampleImage
on Mar 24, 2018 at 1:38:25 pm

Found a massively useful tool! Sharing should others look for this effect:
https://aescripts.com/ae-shader-effector/


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]