Skip to main content

Smooth Keyframe Interpolation

Did you ever wonder why Kdenlive’s smooth interpolation mode may overshoot between keyframes? And how to tell Kdenlive to avoid such situations?

Let’s start to look behind the scenes and introduce you to the strange world of smoothness. Do not worry, there will not be any mathematics for you to learn and understand. Just watch the figures. We will also show you how to avoid such overshots in those situations you do not want it. And for the really curious who want to know what the mathematics behind “smooth” interpolation are there is some further reading in the Notes section at the bottom of this page.

The Fade-In Ramp

Keyframes in the Intensity effect

Let’s start with a simple ramp, as shown here. We use two keyframes[[1]], one with a low value setting, and the other with a high value setting. The particular values do not matter. We set both keyframes to the interpolation mode smooth.

The effect display inside the timeline clip looks like a straight ramp. But if you watch the interpolated values closely while scrubbing the timeline, you should notice that the slope of the ramp varies. At the end and beginning the slope is smaller than in the middle, where it is higher.

But what exactly is going on here?

There is this online open source tool GeoGebra for trying out the mathematics inside Kdenlive’s MLT engine.

This figure shows two keyframes P1=0 and P2=1, which is a fairly typical ramp up setting. In case you are already wondering: it does not matter at which exact frames the individual keyframes are.

The smooth interpolation that MLT will calculate is drawn as a thick green line. It is bent a little bit like the capital letter S, but then, not really too much.

And if you look closely, then beginning and ending slope of the green line are not horizontal - at least what could be expected at first.

You may wonder what the two other keyframes P0 and P3 are good for? Well, the math underneath always requires four keyframes in order to interpolate segment-wise between any two adjacent keyframes. And if there is no preceding (P0) or trailing (P1) keyframe, then we will simple repeat the left (P1) or right (P2) keyframe.

Ramp-Up, and … Overshoot

Keyframes in the Intensity effect

Now let’s add a third keyframe, so this looks like a ramp with a plateau. This is shown in the screenshots.

And now, the ramp gets a clearly visible bump instead of a sharp bend. Well, this looks smooth, but not exactly what we may have intended? So why is this the way it is?

This is now our ramp with a plateau: P0=0, P1=1, P2=2. Do not worry about the keyframe numbering, though.

Did you expect the plateau to be, well a straight plateau? Of course you did. But you may have already noticed that Kdenlive does not exactly behave like this. Instead, the interpolation math causes the interpolated values to overshoot, as you can easily see in the figure.

What the underlying math does is this: the interpolation is smooth, so that the slope to the left of P1 is the same as to the right of P1. Yeah, that is a slightly different “smooth” from what you might have been expecting.

If you want the plateau to be straight instead, then you must set the interpolation mode of the keyframe P1 to linear instead. By the way, this does not change the previous smooth segment in any way. And this results in a “rough bent” at P1, but luckily you probably will not notice in most situations.

Ramp Up-Flat-Down

Keyframes in the Intensity effect

Let’s add another, fourth keyframe, so we have: ramp-up first, then flat, then ramp-down. A fairly typical fade-in and fade-out keyframe template.

And look, what is happening: we have got a hump, but not a nice and flat middle section.

This time, we look at the middle section P1-P2. To the left, we see the up ramp, to the right, the down ramp.

Again, smooth now means that there is no sharp bend in the segments. Instead, the left and right slopes are continuous at P1 and P2; that is, in the middle section. And this causes our interpolated value to overshoot.

Make Flat Great Again

Smooth keyframes in the Intensity effect

Now, how do we get a flat top? Fortunately, that is easy to achieve, as you can see from the screenshots.

1. keyframe: smooth,

2. keyframe: linear (interpolated!),

3. keyframe: smooth,

4. keyframe: smooth (albeit that does not really matter if there are no further keyframes).

Notes

Further Reading

As you may (or rather may not) remember, Kdenlive’s rendering engine is the MLT Multimedia Framework. While MLT has smooth interpolation since around mid-2013, Kdenlive only later caught up and now supports all three interpolation modes linear, discrete, and smooth. As can be seen from the MLT source code, smooth interpolation is done using a Catmull-Rom spline. In particular, MLT uses the so-called uniform variant, because it is so simple. The downside is that this smoothing sometimes has the unwanted property of overshooting, especially when you least expect it.

Sources

The original text was submitted by user TheDiveO to the now defunct kdenlive.org blog. For this documentation it has been lifted from kdenlive.org, updated and adapted to match the overall style.


[[1]]

You may notice that there are three keyframes: one at frame 0 of the clip, and the two we created for this screenshot. Kdenlive always sets a keyframe at frame 0 of a clip, and we chose to ignore that one for the purpose of this demonstration. *[RGB]: Red Green Blue *[VFX]: Visual Effects *[feathering]: Smoothing or blurring the edges of a feature *[LFO]: Low-Frequency Oscillation *[dB]: decibel *[LUFS]: Loudness Units Full Scale *[AI]: Artificial Intelligence *[LLM]: Large Language Model *[HSV]: Hue, Saturation, Value *[SOP/Sat]: S(lope), O(ffset), P(ower) / SATuration *[CDL]: Color Decision List *[HSL]: Hue, Saturation, Lightness - Using HSL color space is useful for subtle color changes *[px]: pixel *[hh:mm:ss:ff]: hours:minutes:seconds:frames *[Hz]: Hertz *[CIE]: Commission internationale de l'éclairage, French for International Commission on Illumination *[DCI]: Digital Cinema Initiative *[nadir]: direction pointing directly below a particular location *[OS]: Operating System *[decibel]: Unit of measurement (dB) for sound levels *[clipping]: A form of distortion that limits a signal once it exceeds a threshold *[Spectrogram]: Visual representation of the spectrum of frequencies of a signal as it varies with time *[prevent clipping]: Dynamic range compression (DRC)is an audio signal processing operation that reduces the volume of loud sounds or amplifies quiet sounds, thus reducing or compressing an audio signal's dynamic range. *[SNR]: Signal-to-Noise Ratio *[dbFS]: Decibels relative to full scale *[QHD]: Quad-HD *[UHD]: Ultra High Definition *[XML]: Extensible Markup Language *[fps]: frames per second *[NTSC]: National Television Standard Committee - defined the TV system used in the United States, Japan and many other countries *[PAL]: Phase Alternating Line - a colour encoding system for analogue television *[LFE]: Low Frequency Effects *[RAW]: The RAW file format is digital photography's equivalent of a negative in film photography: it contains untouched, raw pixel information straight from the digital camera's sensor *[DSLR]: Digital Single Lens Reflex *[DOF]: Depth of Field *[NDF]: Neutral Density Filter *[AVI]: Audio Video Interleave *[BT.601]: A standard from 1982 defining how RGB color primaries get turned into the YCbCr channels used by modern codecs *[BT.709]: A standard from 1990 which does the same at BT.601 but the transfer coefficients are slightly different *[grep]: A Unix command-line utility for searching plain-text data sets for lines that match a regular expression *[MLT]: Media Lovin' Toolkit - An open source software multimedia framework designed and developed for tv broadcasting