---
title: "How to add a motion-tracked text with Claude (tested prompt and script)"
description: "A yellow \"Glass dropper\" tag, tied by a short line to a dot on the bottle's dropper collar, rides up the frame with the collar as the camera pushes in. Install one skill and ask Claude Code, or run the Python script we tested yourself."
url: https://www.recharm.com/effects/motion-tracked-text
---

# How to add a motion-tracked text with Claude

A yellow "Glass dropper" tag, tied by a short line to a dot on the bottle's dropper collar, rides up the frame with the collar as the camera pushes in.

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-tracked text to input.mp4
   Text: Glass dropper
   ```

## 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-tracked text 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                                                                               |
| -------- | ---------------------------- | ------------------------------------------------------------------------------------------ |
| `TEXT`   | `Glass dropper`              | The words on the tag.                                                                      |
| `TARGET` | `(0.40, 0.325, 0.60, 0.405)` | Box round the thing to follow in the first frame, as shares of the frame (x0, y0, x1, y1). |
| `START`  | `0.5`                        | Second the tag appears.                                                                    |
| `OFFSET` | `(0.13, 0.07)`               | Where the tag sits relative to the tracked point, as shares of the frame width and height. |
| `SMOOTH` | `5`                          | Frames averaged to take the jitter out of the track.                                       |
| `COLOR`  | `(255, 214, 0)`              | Tag, line and dot color.                                                                   |

## 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-tracked label to input.mp4 (540x960). Use OpenCV's CSRT tracker (opencv-python-headless) to follow the bottle's metal dropper collar: in the first frame it sits in the box from 40% to 60% across and 32.5% to 40.5% down. Track its center through every frame and smooth the path with a 5-frame moving average. From 0.5 seconds on, draw on each frame, at the tracked point: a yellow (255, 214, 0) dot 1.6% of the frame width in radius with a 3-pixel dark (20, 16, 28) rim; a yellow line 0.6% of the width thick from the dot to a point 13% of the width right and 7% of the height down; and there a yellow (255, 214, 0) pill-shaped tag (fully rounded ends) with its left edge on that point and its vertical center level with it, reading "Glass dropper" in dark (20, 16, 28) bold text 4.5% of the frame width tall, with padding of 60% of the text height. Over the first 0.35 seconds (0.5 to 0.85s) the dot grows from nothing, the line draws out from the dot and the tag fades in, all with an ease-out; after that everything stays locked to the tracked point to the end. Nothing is drawn before 0.5 seconds. Use Python with OpenCV for the tracking and Pillow to draw the dot, line, tag and its text, and ffmpeg to put them on the video (don't rely on ffmpeg's drawtext filter), keep the audio, and save it as output.mp4.
```

## Run it without Claude

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

```
python3 motion-tracked-text.py input.mp4 output.mp4
```

```
#!/usr/bin/env python3
"""Motion-tracked text: a yellow "Glass dropper" tag stays pinned to the bottle's dropper collar as the camera moves.

Usage: python3 motion-tracked-text.py input.mp4 output.mp4
Needs ffmpeg, OpenCV, numpy and Pillow (pip install opencv-python-headless numpy pillow).
"""
import json
import math
import subprocess
import sys
from pathlib import Path

import cv2
import numpy as np
from PIL import Image, ImageDraw, ImageFont

TEXT = "Glass dropper"
TARGET = (0.40, 0.325, 0.60, 0.405)  # box round the thing to follow in the first frame (x0, y0, x1, y1, 0-1)
START = 0.5                          # second the tag appears
POP = 0.35                           # seconds the dot, line and tag take to come in
OFFSET = (0.13, 0.07)                # tag's left edge and center, from the tracked point (shares of width, height)
SMOOTH = 5                           # frames averaged to take the jitter out of the track
COLOR = (255, 214, 0)                # tag and dot color
SIZE = 0.045                         # text height as a share of the frame width
FONTS = ["/System/Library/Fonts/Supplemental/Arial Bold.ttf",     # macOS
         "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",  # Linux
         "C:/Windows/Fonts/arialbd.ttf"]                          # Windows
FONT_FILE = next((f for f in FONTS if Path(f).exists()), None) or sys.exit("No bold font found: add one to FONTS")

def track(src):
    """Center of TARGET in every frame, followed with OpenCV's CSRT tracker and lightly smoothed."""
    cap = cv2.VideoCapture(src)
    _, img = cap.read()
    x0, y0, x1, y1 = TARGET
    tracker = cv2.TrackerCSRT_create()
    tracker.init(img, (round(x0 * w), round(y0 * h), round((x1 - x0) * w), round((y1 - y0) * h)))
    points = [((x0 + x1) / 2 * w, (y0 + y1) / 2 * h)]
    while True:
        ok, img = cap.read()
        if not ok:
            break
        found, (bx, by, bw, bh) = tracker.update(img)
        points.append((bx + bw / 2, by + bh / 2) if found else points[-1])
    pts = np.array(points)
    padded = np.pad(pts, ((SMOOTH // 2, SMOOTH // 2), (0, 0)), mode="edge")
    kernel = np.ones(SMOOTH) / SMOOTH
    return np.stack([np.convolve(padded[:, i], kernel, mode="valid") for i in range(2)], axis=1)

def tag():
    font = ImageFont.truetype(FONT_FILE, round(w * SIZE))
    pad = round(w * SIZE * 0.6)
    x0, y0, x1, y1 = font.getbbox(TEXT)
    img = Image.new("RGBA", (x1 + 2 * pad, round(w * SIZE * 1.1) + 2 * pad))
    draw = ImageDraw.Draw(img)
    draw.rounded_rectangle([0, 0, img.width - 1, img.height - 1], radius=img.height // 2, fill=COLOR)
    draw.text((img.width / 2, img.height / 2), TEXT, font=font, anchor="mm", fill=(20, 16, 28))
    return img

def overlay(i):
    img = Image.new("RGBA", (w, h))
    p = min(max((i / fps - START) / POP, 0), 1)
    if p <= 0:
        return img
    x, y = path[min(i, len(path) - 1)]
    ease = 1 - (1 - p) ** 3
    draw = ImageDraw.Draw(img)
    r = w * 0.016 * ease
    draw.ellipse([x - r - 3, y - r - 3, x + r + 3, y + r + 3], fill=(20, 16, 28))
    draw.ellipse([x - r, y - r, x + r, y + r], fill=COLOR)
    tx, ty = x + OFFSET[0] * w, y + OFFSET[1] * h
    draw.line([(x, y), (x + (tx - x) * ease, y + (ty - y) * ease)], fill=COLOR, width=max(2, round(w * 0.006)))
    card = label.copy()
    card.putalpha(card.getchannel("A").point(lambda a: round(a * ease)))
    img.alpha_composite(card, (round(tx), round(ty - card.height / 2)))
    return img

def probe(path):
    info = json.loads(subprocess.check_output(["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries",
                                               "stream=width,height,r_frame_rate:format=duration", "-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), float(info["format"]["duration"])

def render(src, out):
    """Draw overlay(frame number) on every frame of src and save to out, keeping the audio."""
    ff = subprocess.Popen(["ffmpeg", "-y", "-v", "error", "-i", src,
                           "-f", "rawvideo", "-pix_fmt", "rgba", "-s", f"{w}x{h}", "-r", rate, "-i", "-",
                           "-filter_complex", "[0:v][1:v]overlay=shortest=1,format=yuv420p[v]",
                           "-map", "[v]", "-map", "0:a?", "-c:v", "libx264", "-crf", "18", "-c:a", "copy", out],
                          stdin=subprocess.PIPE)
    for i in range(math.ceil(duration * fps)):
        ff.stdin.write(overlay(i).tobytes())
    ff.stdin.close()
    if ff.wait():
        sys.exit("ffmpeg failed")

src, out = sys.argv[1:3]
w, h, rate, fps, duration = probe(src)
path = track(src)
label = tag()
render(src, out)
```

## More captions and text

- [AI chat reply animation **AI chat reply animation**](https://www.recharm.com/effects/ai-chat-typing)
- [Animated bar chart **Animated bar chart**](https://www.recharm.com/effects/animated-bar-chart)
- [Animated checklist **Animated checklist**](https://www.recharm.com/effects/animated-checklist)
- [Animated line graph **Animated line graph**](https://www.recharm.com/effects/animated-line-graph)
- [Animated pie chart **Animated pie chart**](https://www.recharm.com/effects/animated-pie-chart)

## 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)
