---
title: "How to add a pixel stretch with Claude (tested prompt and script)"
description: "At 1 second the serum bottle's right half shoots out to the edge of the frame as flat horizontal bands of black dropper, purple glass and cream label, all copied from the one column down its middle, then snaps back at 5 seconds. Install one skill and ask Claude Code, or run the Python script we tested yourself."
url: https://www.recharm.com/effects/pixel-stretch
---

# How to add a pixel stretch with Claude

At 1 second the serum bottle's right half shoots out to the edge of the frame as flat horizontal bands of black dropper, purple glass and cream label, all copied from the one column down its middle, then snaps back at 5 seconds.

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 pixel stretch to input.mp4
   Seconds the stretch is on screen: 1.0, 5.0
   Seconds the streaks take to shoot out to the edge, and to pull back at the end: 0.5
   ```

## 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 pixel stretch 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, END` | `1.0, 5.0` | Seconds the stretch is on screen.                                                       |
| `GROW`       | `0.5`      | Seconds the streaks take to shoot out to the edge, and to pull back at the end.         |
| `OFFSET`     | `0.0`      | Where the stretched column sits, as a share of the product's width right of its middle. |
| `FPS`        | `30`       | Output frame rate.                                                                      |

## Without the skill

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

```
Add a pixel stretch effect to input.mp4 using Python with numpy, rembg (session "u2net") and ffmpeg, frame by frame at 30fps. From 1.0 to 5.0 seconds, cut the product out of each frame with rembg, find the middle of its cut-out (the average x of the matte, weighted by its values) and copy that one column of pixels over every pixel to its right, so everything right of the product's middle becomes flat horizontal streaks of that column. The streaks shoot out from the column to the right edge over 1.0 to 1.5 seconds (ease out cubic: reach = 1 - (1 - p)^3) and pull back to the column over 4.5 to 5.0 seconds the same way. Leave frames before 1.0 and from 5.0 seconds on untouched, and leave everything left of the column untouched. There is no text to draw (if you add any, draw it with Pillow, not ffmpeg's drawtext). Keep the audio and save it as output.mp4 (H.264, yuv420p).
```

## Run it without Claude

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

```
python3 pixel-stretch.py input.mp4 output.mp4
```

```
#!/usr/bin/env python3
"""Pixel stretch: the one column of pixels running down the product's middle is dragged out to the right edge in long streaks.

Usage: python3 pixel-stretch.py input.mp4 output.mp4
Needs ffmpeg, numpy, Pillow and rembg to find the product in every frame
(pip install numpy pillow "rembg[cpu]"; rembg downloads its u2net model on first use).
"""
import json
import subprocess
import sys

import numpy as np
from PIL import Image
from rembg import new_session

START, END = 1.0, 5.0    # seconds the stretch is on screen
GROW = 0.5               # seconds the streaks take to shoot out to the edge, and to pull back at the end
OFFSET = 0.0             # where the stretched column sits, as a share of the product's width right of its middle
FPS = 30                 # output frame rate

def reach(t):
    """How far the streaks reach, 0 (none) to 1 (the frame's right edge), easing out and back in."""
    if not START <= t < END:
        return 0.0
    p = min(t - START, END - t, GROW) / GROW
    return 1 - (1 - p) ** 3

def stretch_column(rgb):
    """The x of the column to stretch: the middle of the product's cut-out (rembg), weighted by its matte."""
    matte = np.asarray(session.predict(Image.fromarray(rgb))[0], np.float32)
    weight = matte.sum(axis=0)
    xs = np.nonzero(weight > weight.max() * 0.05)[0]
    middle = (weight * np.arange(w)).sum() / weight.sum()
    return round(middle + OFFSET * (xs[-1] - xs[0]))

def pixel_stretch(rgb, t):
    """Copy the product's middle column over every pixel from it to the streaks' front."""
    x = stretch_column(rgb)
    front = x + 1 + round((w - x - 1) * reach(t))
    img = rgb.copy()
    img[:, x:front] = rgb[:, x:x + 1]
    return img

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

def render(src, out):
    """Read src frame by frame at FPS, stretch the frames inside START-END and save to out, keeping the audio."""
    reader = subprocess.Popen(["ffmpeg", "-v", "error", "-i", src, "-vf", f"fps={FPS}",
                               "-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", str(FPS), "-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)
    i = 0
    while len(raw := reader.stdout.read(w * h * 3)) == w * h * 3:
        rgb = np.frombuffer(raw, np.uint8).reshape(h, w, 3)
        t = i / FPS
        writer.stdin.write((pixel_stretch(rgb, t) if reach(t) > 0 else rgb).tobytes())
        i += 1
    writer.stdin.close()
    if reader.wait() or writer.wait():
        sys.exit("ffmpeg failed")

src, out = sys.argv[1:3]
w, h = probe(src)
session = new_session("u2net")
render(src, out)
```

## More distortion and glitch

- [Anaglyph 3D **Anaglyph 3D**](https://www.recharm.com/effects/anaglyph-3d)
- [Black hole **Black hole**](https://www.recharm.com/effects/black-hole)
- [Bulge and pinch **Bulge and pinch**](https://www.recharm.com/effects/bulge-pinch)
- [Datamosh **Datamosh**](https://www.recharm.com/effects/datamosh)
- [Disintegration **Disintegration**](https://www.recharm.com/effects/disintegration)

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