---
title: "How to add a motion trail with Claude (tested prompt and script)"
description: "The bottle swings right, then left across the frame, and four fading see-through copies of it trail behind, bunching up and vanishing as it settles back in the middle. Install one skill and ask Claude Code, or run the Python script we tested yourself."
url: https://www.recharm.com/effects/motion-trail
---

# How to add a motion trail with Claude

The bottle swings right, then left across the frame, and four fading see-through copies of it trail behind, bunching up and vanishing as it settles back in the middle.

Made by the script on this page, from our own test clip.

## Get this effect

1. ### Switch to Code in your [Claude Desktop App](https://claude.com/download)

2. ### Install the skill (once)

   ```
   Install the Recharm video effects skill: download https://recharm-growth-staging.s3.us-east-2.amazonaws.com/website/downloads/recharm-video-effects.zip and unzip it into ~/.claude/skills
   ```

3. ### Ask for the effect

   ```
   Add a motion trail to input.mp4
   Second the swing starts: 1.0
   Seconds the swing takes, right, left and back to center: 1.6
   ```

## Several videos, several effects, one ask

Put your clips in the folder, mention them with @, and ask for everything at once. Claude runs one tested script after another on each clip, then joins them.

Add a motion trail to **@clip1.mp4**, put a sale badge on **@clip2.mp4**, give **@clip3.mp4** a VHS look, then join all three with crossfades.

## Settings you can change

Ask Claude to change any of these, or edit them at the top of the script.

| Setting   | Default                  | What it does                                                                  |
| --------- | ------------------------ | ----------------------------------------------------------------------------- |
| `START`   | `1.0`                    | Second the swing starts.                                                      |
| `MOVE`    | `1.6`                    | Seconds the swing takes, right, left and back to center.                      |
| `SWING`   | `0.30`                   | How far the picture travels each way, as a share of the frame width.          |
| `GHOSTS`  | `4`                      | Ghost copies trailing the subject.                                            |
| `GAP`     | `3`                      | Frames between one ghost and the next. More spreads the copies further apart. |
| `OPACITY` | `[0.6, 0.45, 0.3, 0.15]` | Opacity of each ghost, nearest first.                                         |

## Without the skill

Don’t want to install the skill? Paste this prompt into Claude Code and Claude writes the script itself.

```
Add a motion trail to input.mp4. From 1.0 to 2.6 seconds, slide the whole picture sideways: the shift in pixels is 0.30 × frame width × sin(2π p), where p = u²(3 − 2u) and u runs from 0 to 1 over those 1.6 seconds, so the picture swings right, then left, then back to center with eased starts and stops. Fill the edge it uncovers by mirroring the picture at that edge (no black bars). While it moves, from 1.0 seconds until 0.4 seconds after the swing ends (3.0 seconds), give it a trail of 4 ghosts: the shifted frames from 3, 6, 9 and 12 frames earlier, each mixed over the current frame at opacity 0.6, 0.45, 0.3 and 0.15 (nearest first), keeping the darker value at every pixel of the current frame and each mix, so the dark bottle leaves faint copies on the light backdrop. Before 1.0 seconds and after 3.0 seconds the video is unchanged. Use Python with numpy and ffmpeg, keep the size, frame rate and audio, and save it as output.mp4.
```

## Run it without Claude

This is the exact script we tested. Save it as `motion-trail.py` and run:

```
python3 motion-trail.py input.mp4 output.mp4
```

```
#!/usr/bin/env python3
"""Motion trail: the shot swings right, then left, and the subject leaves a line of fading ghost copies behind it.

Usage: python3 motion-trail.py input.mp4 output.mp4
Needs ffmpeg and numpy (pip install numpy).
"""
import json
import math
import subprocess
import sys

import numpy as np

START = 1.0                        # second the swing starts
MOVE = 1.6                         # seconds the swing takes (right, left, back to center)
SWING = 0.30                       # how far the picture travels each way, as a share of the frame width
GHOSTS = 4                         # ghost copies trailing the subject
GAP = 3                            # frames between one ghost and the next
OPACITY = [0.6, 0.45, 0.3, 0.15]   # opacity of each ghost, nearest first

def offset(t):
    """Sideways shift in pixels at time t: one smooth swing right, left and back to center."""
    u = min(max((t - START) / MOVE, 0), 1)
    p = u * u * (3 - 2 * u)  # ease in and out
    return round(SWING * w * math.sin(2 * math.pi * p))

def shift(img, dx):
    """Move the picture dx pixels right, mirroring the edge it uncovers so no black shows."""
    x = np.arange(w) - dx
    x = np.where(x < 0, -x, np.where(x >= w, 2 * w - 2 - x, x))
    return img[:, x]

def trail(history):
    """Lay each earlier frame over the newest at its opacity, keeping whichever is darker at every pixel,
    so a darker subject shows its past positions against a lighter background and nothing else changes."""
    cur = history[-1].astype(np.float32)
    out = cur.copy()
    for k, a in enumerate(OPACITY[:GHOSTS], start=1):
        if k * GAP < len(history):
            past = history[-1 - k * GAP].astype(np.float32)
            out = np.minimum(out, cur * (1 - a) + past * a)
    return out.astype(np.uint8)

def probe(path):
    info = json.loads(subprocess.check_output(["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries",
                                               "stream=width,height,r_frame_rate", "-of", "json", path]))
    s = info["streams"][0]
    num, den = s["r_frame_rate"].split("/")
    return s["width"], s["height"], s["r_frame_rate"], float(num) / float(den)

src, out = sys.argv[1:3]
w, h, rate, fps = probe(src)
reader = subprocess.Popen(["ffmpeg", "-v", "error", "-i", src, "-f", "rawvideo", "-pix_fmt", "rgb24", "-"],
                          stdout=subprocess.PIPE)
writer = subprocess.Popen(["ffmpeg", "-y", "-v", "error", "-f", "rawvideo", "-pix_fmt", "rgb24", "-s", f"{w}x{h}",
                           "-r", rate, "-i", "-", "-i", src, "-map", "0:v", "-map", "1:a?", "-c:v", "libx264",
                           "-crf", "18", "-pix_fmt", "yuv420p", "-c:a", "copy", "-shortest", out],
                          stdin=subprocess.PIPE)
trail_end = START + MOVE + GHOSTS * GAP / fps  # the last ghost catches up this long after the swing stops
history, i = [], 0
while raw := reader.stdout.read(w * h * 3):
    t = i / fps
    frame = shift(np.frombuffer(raw, np.uint8).reshape(h, w, 3), offset(t))
    history = (history + [frame])[-(GHOSTS * GAP + 1):]
    writer.stdin.write((trail(history) if START <= t <= trail_end else frame).tobytes())
    i += 1
writer.stdin.close()
if reader.wait() or writer.wait():
    sys.exit("ffmpeg failed")
```

## More motion and camera

- [2.5D parallax photo **2.5D parallax photo**](https://www.recharm.com/effects/2-5d-parallax-photo)
- [Back-and-forth loop **Back-and-forth loop**](https://www.recharm.com/effects/back-and-forth-loop)
- [Background blur **Background blur**](https://www.recharm.com/effects/background-blur)
- [Bullet time **Bullet time**](https://www.recharm.com/effects/bullet-time)
- [Cinemagraph **Cinemagraph**](https://www.recharm.com/effects/cinemagraph)

## Find 3x _winning ads_

Recharm cuts your ad footage into tagged, searchable clips: hooks, testimonials, product shots. Find the shots that win, add the effect with Claude, and ship 3x more ad edits.

[Start 14-day free trial](https://www.recharm.com/get-started)
