RapidRAW Logo RapidRAW
Verified in v1.7.2
Documentation Menu

Motion, Tracking & Stabilization

Many video tools need to know how things move from one frame to the next. RapidRAW measures motion in two ways:

  • Optical flow on the GPU gives a motion vector for every pixel between two frames. It runs live while a frame renders, for frame interpolation, temporal noise reduction and shutter blur, and in the background to carry AI results from frame to frame.
  • Feature tracking on the CPU follows distinct points (corners in the picture) from frame to frame. It drives stabilization and the object and surface trackers, which run once and store their result.

This page explains how each tool works. To use them, see Timeline Editing for speed and interpolation, Grading & Effects for stabilization, tracking, noise reduction, motion blur and Auto Reframe, and Exporting Video for higher frame rates. The rest of the frame path is described in the Video Pipeline.

The code is in src-tauri/src/video/ in the RapidRAW source: the GPU tools in engine/ (flow.rs, temporal.rs, shutter.rs) with the shader optical_flow.wgsl, and the CPU vision code (points, trackers, stabilization, reframing) in vision/.

Tool Motion it uses When it runs
Frame interpolation Flow between the two source frames around the wanted moment Live, for each frame
Temporal noise reduction Flow to two frames before and two after Live, for each frame
Shutter blur on footage Flow to the previous and the next frame Live, for each frame
Stabilization One shift, rotation and scale per pair of frames, from tracked points In the background, once per source
Object and surface tracking Points and a template inside the box or surface When you click Track
Depth maps and Auto Reframe AI on key frames, carried along the flow In the background

Optical flow

RapidRAW's optical flow is a GPU version of Dense Inverse Search (Kroeger and colleagues, 2016), a method built for speed:

  1. Pyramid. Each frame becomes a grey image of at most 960 pixels on the long side, plus smaller copies halving down to about 16 pixels, with the brightness gradients of each.
  2. Patch search. Starting at the smallest copy, the frame is covered with 8 × 8 pixel patches every 4 pixels. For each patch, a few Gauss-Newton steps find the shift that makes it match the other frame best, starting from the result of the coarser level. Patches are compared with their average brightness removed, so a small exposure change doesn't look like motion.
  3. Dense field. Every pixel averages the shifts of the patches that cover it, each weighted by how well that shift fits at this pixel. Then the next, finer level starts from this field.

The flow is always computed in both directions at once. Where going forward and then back doesn't return close to the starting point, that pixel is hidden in the other frame, for example background that a passing subject covers. If fewer than a fifth of the pixels agree, frame interpolation and shutter blur treat the two frames as different shots (a cut) and don't blend across them.

A frame's pyramid and its flows are kept while the clip plays, so frame interpolation, noise reduction and shutter blur share them.

Key frames and in-between frames

AI models are too slow to run on every frame of a video. For the depth and normal maps of depth effects (Relight, Fog, Lens Blur) and for Auto Reframe, the background analysis runs the model on key frames only and carries the result to the frames in between: each in-between frame takes the maps of the key frames before and after it, moves them along the flow, and blends them by distance. A new key frame is made at every cut, when too much of the picture has moved or been uncovered, and at least every half second for depth maps and every second for Auto Reframe. Depth maps are analyzed in blocks of 4 seconds around the part you are looking at, and every block is cached.

Frame interpolation and speed ramps

A clip needs frames that were never filmed whenever it moves by less than one source frame per timeline frame, that is when the footage's frame rate times the clip's slowest speed is below the project's frame rate:

  • slow motion beyond what the footage covers: 120 fps footage at 25% in a 30 fps project still has a real frame for every timeline frame, 30 fps footage at 50% doesn't;
  • footage with a lower frame rate than the project, such as 24 fps footage in a 60 fps project;
  • an export at a higher frame rate, such as 30 fps footage exported at 120 fps. The export re-times the whole project to the new rate.

What fills the gaps is the Frame Interpolation setting of the clip, or of the project if the clip has none:

  • Off shows the nearest source frame, so frames repeat.
  • Frame Blend crossfades the two source frames around the wanted moment, weighted by how close each one is.
  • Optical Flow builds a new picture from the motion.

Two charts of a clip whose speed ramps from 100% down to 25% and back. Left: source time against timeline time, flattening during the slow part. Right: twelve timeline frames of the slow part, where Off repeats each source frame four times and Optical Flow places three new frames between every two source frames

Optical Flow makes each new frame in four steps:

  1. Flow in both directions between the source frame before and the one after.
  2. Splat. Every pixel of both frames is pushed along its motion to the wanted moment. Where several pixels land on the same spot, the one that matches the other frame best and isn't hidden there wins. So a moving subject stays in front of the background instead of mixing with it.
  3. Fill. Spots nobody landed on (background that the subject uncovers) take the motion of the neighbour whose two frames agree best.
  4. Build the frame. Each output pixel is sampled from both frames along its motion, weighted by distance in time and by whether it is visible in each frame. Overlays that don't move, such as burned-in text, logos or a timestamp, are detected and kept still. On a cut, the nearer frame is used as it is.

Speed ramps. The Speed Curve (10% to 1600%) is turned into a source time for every timeline frame by adding up speed × frame duration, frame by frame. From that list RapidRAW knows exactly which source frames the clip will show and tells the decoder to skip the others, which keeps fast parts of a ramp quick to play. In the slow parts, the frames in between are interpolated as above.

Sound of speed changes. At a constant speed, FFmpeg's atempo filter changes the speed and keeps the pitch. A speed ramp changes speed on every frame, so RapidRAW stretches the sound itself: it cuts it into overlapping windows of 1/24 s and places each one where it continues the previous one best (the WSOLA method), so voices keep their pitch. The stretched sound is cached as a WAV file.

Temporal noise reduction

On video clips, the Noise Reduction sliders (Luminance and Color in the Details panel) also average each frame with its neighbours: up to two frames before and two after. Noise is different in every frame while the scene isn't, so averaging five frames removes far more noise than smoothing a single frame, and it doesn't blur fine detail.

  1. Flow from the current frame to each neighbour. The flow to the second neighbour is the flow to the first one chained with the step after it.
  2. Compare. For every pixel, a 3 × 3 patch around it is compared with the neighbour twice: at the same spot, and moved along the flow. The better of the two is used, so still areas keep the unmoved pixel and don't pick up small errors in the flow.
  3. Weigh. A neighbour pixel counts more the closer its patch is to the current one, measured against the noise level the sliders set, and less where the forward and backward flow disagree. Where something is hidden or changes, the weights drop and the current frame dominates.
  4. Average. The weighted mean replaces the pixel's luminance and color, as far as Luminance and Color allow.

After that, the normal noise reduction of a single frame runs as usual, but weaker: its strength is divided by the number of frames averaged (a fifth with four neighbours). At the start and end of a clip fewer neighbours are available, and across a cut in the footage the neighbours don't match, so they get no weight.

Shutter blur

A real camera blurs whatever moves while its shutter is open. The shutter angle says for how much of each frame's time it is open: 180° means half the frame time, 1/50 s at 25 fps. RapidRAW can add this blur in two places.

Shutter angle chart: for 90, 180, 360 and 720 degrees, a bar shows how long the virtual shutter is open around one frame, from a quarter of a frame to two frames, with exposure times of 1/100, 1/50 and 1/25 s at 25 fps, and blur streaks of 10, 20, 40 and 80 pixels for a layer moving 40 pixels per frame

Layer motion. A layer that moves on the canvas (keyframed position, scale or rotation, an animation, or a track it follows) is blurred along that movement. RapidRAW places the layer at the moment the virtual shutter opens and at the moment it closes, turns the difference into a shift, a zoom and a turn, and streaks the layer along that path. Titles and colors have their own Motion Blur switch with a Shutter angle (up to 360°, 180° by default). Clips use the Shutter Angle of their Motion Blur effect.

Footage motion. With Motion Blur set to Shutter and Footage Motion on, the movement inside the picture is blurred too:

  • The flow to the previous and the next source frame gives every pixel its motion.
  • The blur length starts from the same rule as for layers, motion times Shutter Angle / 360 (up to 720°). Very small movements get less blur, so grain and slight jitter don't smear, and fast ones get more, so real motion reads clearly.
  • The blur is the light-preserving blur of the photo Motion Blur, and it looks the same in a small preview, zoomed in and in the export.
  • The motion is measured per timeline frame. A clip slowed down to 25% moves a quarter as far per frame and gets much less blur. Sped-up clips and timelapses get longer blur, so they look less choppy.
  • With stabilization on, the shake the stabilizer removed is taken out of the motion first, so only the movement you still see is blurred.

Stabilization

Stabilization works in three steps. The slow part, measuring the camera's motion, runs once in the background and is cached. Everything after it is fast, so changing the level or trimming the clip updates right away.

Analysis CPU, background, cached
Grey frames at 640 px→Corners→Lucas-Kanade tracking→RANSAC fit
One shift, rotation and scale for each pair of frames, only for the parts of the source that clips use.
Camera path CPU, per clip
Fill gaps→L1-optimal path in 8 s windows→Blend the windows→Zoom
Render GPU, per frame
Each frame is moved, turned and zoomed by its correction when it's placed on the canvas. Vignette and shutter blur follow the steadied frame.

Analysis. The source is decoded as small grey frames (640 pixels on the long side), only for the parts the clips use, and again if you extend a clip. In each frame, about 160 corners spread over the picture are followed into the next frame with Lucas-Kanade tracking. RANSAC then finds the shift, rotation and scale that most of them agree on, ignoring points on moving people or cars. Frames where too few points agree are filled in from their neighbours.

Camera path. Adding up these motions gives the path the camera took. RapidRAW then looks for the smoothest path the frame can follow while the crop still covers it, following the L1-optimal camera paths of Grundmann, Kwatra and Essa (2011). Smoothing with absolute (L1) instead of squared terms gives a path of still stretches, steady pans and smooth changes between them, like a camera on a tripod or a dolly, instead of a gently wobbling average. The path is solved in overlapping windows of about 8 seconds.

Three charts of one horizontal axis of a handheld walk with a slow pan, at Low, Mid and High: the filmed path wobbles by several percent of the frame width, and the stabilized path inside a grey band gets smoother from Low to High, from a gently wobbling line to a still start and an even pan

The Stabilize level sets two things: how strongly the path is pulled back toward the real camera, and how far the crop may zoom in. Low stays close to the camera and zooms at most 1.06 ×, Mid 1.12 × and High 1.25 ×. After solving, RapidRAW zooms in only as far as this clip's path needs, so a steady clip on High may need less than 1.25 ×.

Render. Every frame gets its correction (shift, rotation and scale) when it is placed on the canvas, interpolated between source frames for slow motion. Clips with stabilization are decoded a bit larger, so the zoom doesn't soften them. Vignette and other centered effects are measured from the visible, steadied frame, and the shutter blur ignores the shake that was removed.

Tracking

The trackers follow one thing you point at: a box around an object (Object) or the four corners of a flat surface (Surface). Their results move masks, clone and heal spots, and layers attached with Follow Object.

Start frame under the playhead
The box or the four corners become the template. Surface corners snap to strong corners in the picture.
Every next frame CPU
Predict from the last motion→Track points inside→RANSAC fit→Align to the template→Score
Found
The pose is stored for this frame. If the object's look has changed a little, the template is refreshed.
Not found
A wider search around the predicted spot. If that fails too, the box keeps moving with slowing speed and the tracker tries again on the next frame.

Object tracking follows the box's position, size and rotation. Each frame, points inside the box are tracked with Lucas-Kanade and fitted with RANSAC, and that guess is then refined by aligning the box's content directly to the template, with compensation for changing light. If the match is too weak, a wider search looks for the object around the predicted spot.

Surface tracking follows a perspective plane (a homography) instead of a box, on larger frames, because the four corners have to sit precisely. It works the same way, but refines all four corners against the template.

Both trackers keep the first template next to the refreshed one and go back to it when they lose the match, so small changes can't add up and make the track drift away. Tracking stops after a second without finding the object.

Direction. Forward tracks from the playhead to the end of the clip, Back to its start, Both does both. Video can only be decoded forward, so tracking back decodes 48 frames at a time and hands them to the tracker in reverse.

Leaving the frame. When an object leaves the picture, the track continues the motion it had in its last 0.3 s, with scale and rotation easing out over about half a second. A title attached to a passing car slides out with it instead of stopping at the edge.

Using the track. Between tracked frames the pose is interpolated. Attach decides what a layer or mask takes from it: Move only the position, Transform also scale and rotation, Perspective the whole plane of a surface, and Pin puts the layer's corners exactly on the surface's corners (with Fill, Fit or Stretch for layers of another shape). Masks and clone or heal spots are moved point by point, so with Transform or Perspective their shape turns and tilts with the object.

Auto Reframe

Auto Reframe fits a clip into a canvas of another shape, for example landscape footage on a 9:16 canvas, and pans to keep the subject in view, like a camera operator would.

  1. Find the subject. The BiRefNet foreground model (the one behind the Foreground mask) runs on key frames at 1024 pixels and gives a small map of what stands out. Between key frames the map is carried along the flow (see Key frames and in-between frames).
  2. Split into shots. Every cut starts a new path, so the frame jumps with the cut instead of panning across it.
  3. Aim. For every frame, RapidRAW finds the crop position that covers the most of the subject, favoring the upper part of a tall subject (usually the head), and switches to another subject only when it is clearly bigger. When nothing stands out for a while, the crop drifts back to the center.
  4. Smooth. The aims are averaged over 0.15 s, then a camera path is solved with the same L1 method as stabilization: the crop stays still or pans evenly, keeps the subject inside a margin, and never shows past the edge of the clip.

See also

  • Video Pipeline for decoding, the look on every frame, compositing and export.
  • Grading & Effects to use stabilization, tracking, noise reduction and motion blur.
  • Timeline Editing for speed, speed ramps and frame interpolation.
  • Depth Effects for the photo Motion Blur that the shutter blur builds on.