Map Video to Moving Surface with Kdenlive Affine

This guide explains how to use the Affine transition in Kdenlive to map a video clip onto a moving rectangular surface, such as a smartphone screen, television, or billboard, within a background video. By leveraging Kdenlive’s track hierarchy and keyframe animation system, you can scale, rotate, skew, and track the motion of your target surface to create a seamless picture-in-picture effect.

Step 1: Set Up Your Timeline Tracks

To begin, you must arrange your clips on the timeline so that the target background video is positioned below the video you want to insert.

  1. Import both video clips into your Kdenlive project bin.
  2. Drag the background video (the one containing the moving rectangular surface) onto a lower track (for example, V1).
  3. Drag the video you want to map onto the track directly above it (for example, V2).
  4. Trim and align both clips so their durations match the sequence where the mapping occurs.

Step 2: Apply the Affine Transition

While Kdenlive offers several effects, the Affine tool is best applied as a transition (composition) between the two tracks.

  1. Right-click the clip on V2 (the top video).
  2. Hover over Insert an Effect or Add Composition and select Affine from the list.
  3. A yellow transition block will appear beneath your top clip, connecting it to the bottom track. Expand this transition block so it spans the entire length of the overlapping clips.

Step 3: Align the Video to the Target Surface

Now you must resize and orient the top video to match the position, scale, and angle of the rectangular surface at the start of your shot.

  1. Select the Affine transition block on your timeline to open its settings in the Properties panel.
  2. Ensure your playhead is at the very first frame of the transition.
  3. In the Properties panel, locate the adjustment parameters: X, Y (for positioning), Width, Height (for scaling), Rotate (for orientation), and Shear (to skew the perspective to match angled surfaces).
  4. Adjust these sliders, or use the on-screen red selection box in the Project Monitor, to drag and warp the video until it perfectly aligns with the corners of the moving rectangular surface.

Step 4: Track the Motion with Keyframes

Because the target surface is moving, you must animate the Affine transition parameters using keyframes to track the motion.

  1. In the Affine properties timeline, click the Add Keyframe (plus icon) button to lock in your starting position.
  2. Move the timeline playhead forward a few frames to a point where the background surface has visibly moved.
  3. Adjust the Affine settings (position, scale, rotation, and shear) in the Properties panel to realign the insert video with the new position of the background surface. Kdenlive will automatically generate a new keyframe at this position.
  4. Repeat this process throughout the clip. For fast or complex movement, add keyframes closer together. For slow, linear movement, you may only need a few keyframes at key intervals.

Step 5: Fine-Tune and Render

Once the rough tracking is complete, preview your timeline to ensure the mapped video does not drift from the target boundaries.

  1. Play back the sequence in the Project Monitor.
  2. If you notice drifting between two keyframes, stop the playhead at the drift point, adjust the coordinates, and a corrective keyframe will be added.
  3. If the movement of the background surface is smooth, right-click your keyframes in the Affine timeline and change the interpolation type from Linear to Smooth for more natural tracking.
  4. Once satisfied, render your project to lock in the final composited video.