Smoothing Animation Curves

Written by Frank Rueter on .

Smoothing an animation curve can be done through the animation curve's “Edit/Filter” option.
However, this will move the original keyframes which seems a little destructive and doesn't allow a nice fine tuning workflow (other than jumping up and down on the undo button and trying again with a different value).

So here is an expression based solution that uses a user knob value to smooth the curve “live”:

In my Tracker node I have this animation curve:

I have also created two floating point sliders called “smooth” and “smoothedCurve”, one to adjust the amount of smoothing and the other to hold the resulting smooth curve respectively:

The magic in this whole smoothing business is using the integral of the knob that holds the animation (in this case it's track1.x) over a certain range. In other words we want to use something like integrate(a,b). Let's do this just for the range of three frames (previous frame to last frame). Dividing the whole thing by (b-a) will give the average value and thus a box filter (thanks to Bill Spitzak for posting this solution on the nuke ailing list once, I never paid enough attention at high school to even know what this is exactly doing). I do know however, that the next frame minus the previous frame always equals 2, so here we go:

The resulting curve:

This is hard coded to a 3 frame range though (from previous to the next frame of each frame), so let's hook it up to our custom “smooth” knob to make it more interactive:

And that is all. Now you can drive the smoothness of the custom curve by cranking the "smooth" knob:


0 # Todd Groves 2010-07-28 13:38
How do you create the user sliders?
0 # Frank Rueter 2010-07-28 15:42
right click in the panel and chose "Manage User Knobs". Check out the gizmo cookbook entry "SwitchMatte" and the manual for more info no how to do this,
+1 # Mortimer Warlimont 2011-01-13 05:53
hi there,
i thought it could be useful for others that i let you know the flaw i found in your final formula.
at higher smoothing values i had the case that the smoothed curve started to get "bumpy" again.
this is due to the "smooth" value being used in the frame+/- section.
giving those 2 a fixed value lets you smooth your track or curve down without any resonance problems. i just increased the value to 1.5, 2 is fine as well, depends on how many steps you want in the smooth slider until you get a flat line ;-)

0 # Matt Mustermann 2011-02-05 10:52
i don't know where to ask the following question - but i guess u guys have an answer ;-)

actually i don't want to smooth or filter my animation curves. i just want to delete every 2nd keyframe - simplify curve is that called within maya. how to achieve that effect within
0 # Matt Mustermann 2011-02-05 10:53
.... within nuke

br mayanic
0 # Frank Rueter 2011-02-05 14:37
thanks for the heads up Mortimer!
Matt, sounds like a job for python rather than expressions. For general questions and help try the nuke user mailing lists, very helpful people there!
0 # Dennis Tsoi 2011-03-28 05:17
Hi Frank!
As I can understand this expression drives a filtering algorithm but with more flaxability. Isn't it?
0 # Frank Rueter 2011-03-28 13:39
yes. It does what the "filter" option doe in the right click menu but in a non-destructive way
0 # Frank Rueter 2011-10-19 23:03
Mortimer, I'm not sure what exactly you mean by "giving those two a static value". WIf you do that you can't repeatedly filter the curve anymore, right?! Maybe I'm misunderstandin g. Do you have a working example? I'd like to update this cookbook entry to yield better results.
-2 # Mortimer Warlimont 2011-10-20 03:19
hi Frank,
i have a tool based on your formular in our pipeline to smooth out unwanted camera jittering or swaying. the formula for the x and y values is : egrate(frame-1. 5, frame+1.5)/(2*smooth)
i can smooth as much as ia like with this, back and forth.
i can send you a little test script, if you like ;-)
0 # Mortimer Warlimont 2011-10-20 03:54
ps: guest is me, mortimer.
dunno why my name isnt displayed.....
0 # Frank Rueter 2011-10-25 23:37
mortimer, but your formula loses correlation to the original data and will become a flat line at 0 when "smooth" grows infinity large, when it should become a flat line at the curves average value. I also still see the jaggies in the resulting curve. I wonder if this is a problem with floating point precision in Nuke.
0 # francesco cadoni 2017-05-23 14:29
Hi Frank! Is there a way to avoid the jagging in the resulting curve? The smooth knob in the tracker doesn't seem to suffer the same issue. Does the smooth knob use a different math?
0 # Tommaso Malaisi 2015-12-08 16:38
Hi, I'm working on a stabilization footage gizmo called VIDEOTRAVOLTA STABILIUZ (already uploaded but under review at the moment) and I've used Frank Rueter expression.
I can't exclude it's my mistake but I've found important differences between Frank expression and edit/filter workflow. Probably is the same issue Mortimer was talking about.
Those are results with Frank expression for value, 5, 10 and 20
And those are edit/filter results for value 5, 10, 20 and 1000

I'm trying to recreate an un-distructive way to filter curves but results are lacking until now!
0 # Tommaso Malaisi 2015-12-08 22:32
VT STABILIUZ is visible now
0 # smsm cxxjj 2016-05-05 16:45
how I connect the gizmo to scanline render camera to get the smooth result?
0 # G. Scott Scribner 2019-01-15 03:59
How can I apply this to a camera track. I've tried everything expression-wise and I can't get it.

You have no rights to post comments

We have 2370 guests and 127 members online