---
title: "How to add a back-and-forth loop with Claude (tested prompt and ffmpeg command)"
description: "Three seconds of the orbit race forward at triple speed, then rewind over the same frames, three times in a row, so the camera swings to and fro around the bottle. Install one skill and ask Claude Code, or run the ffmpeg command we tested yourself."
url: https://www.recharm.com/effects/back-and-forth-loop
---

# How to add a back-and-forth loop with Claude

Three seconds of the orbit race forward at triple speed, then rewind over the same frames, three times in a row, so the camera swings to and fro around the bottle.

Made by the command 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 back-and-forth loop to input.mp4
   Second of the input the slice starts at: 2.0
   Seconds of the input in the slice: 3.0
   ```

## 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 back-and-forth loop 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 command.

| Setting | Default | What it does                                                                          |
| ------- | ------- | ------------------------------------------------------------------------------------- |
| `START` | `2.0`   | Second of the input the slice starts at.                                              |
| `SLICE` | `3.0`   | Seconds of the input in the slice.                                                    |
| `SPEED` | `3`     | How many times faster than real time the slice plays. 3s at 3x makes a 1-second pass. |
| `TIMES` | `3`     | Forward-and-back cycles in the output. Three 2-second cycles make 6 seconds.          |

## Without the skill

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

```
Make a boomerang (back-and-forth loop) from input.mp4 (540x960, 30fps, 6 seconds). Take the slice from input second 2.0 to 5.0 and speed it up 3x so it plays in 1 second (30 frames, keeping every third input frame: input frames 60, 63, 66 ... 147). Play those 30 frames forward, then the same 30 frames in reverse, and repeat that forward-then-backward cycle 3 times, so the output is exactly 6 seconds (180 frames): output 0-1s shows input 2.0s to 4.9s, output 1-2s shows input 4.9s back to 2.0s, and the same again for 2-4s and 4-6s. Don't crop, zoom or add anything to the picture, and don't add any text. For the sound, keep the input's own audio playing normally from 0 to 6 seconds (don't reverse or speed it up). Use ffmpeg, keep the size, frame rate and audio, and save it as output.mp4.
```

## Run it without Claude

This is the exact command we tested. Save it as `back-and-forth-loop.sh` and run:

```
sh back-and-forth-loop.sh input.mp4 output.mp4
```

```
#!/bin/sh
# Back-and-forth loop: a slice of the clip plays forward fast, then backward, three times over, under the clip's own sound.
# Usage: sh back-and-forth-loop.sh input.mp4 output.mp4
set -e
IN="$1"; OUT="$2"
START=2.0     # second of the input the slice starts at
SLICE=3.0     # seconds of the input in the slice
SPEED=3       # how many times faster than real time it plays (3s at 3x = a 1s pass)
TIMES=3       # forward-and-back cycles in the output

FPS=$(ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate -of csv=p=0 "$IN")
PASS=$(awk "BEGIN{print $SLICE / $SPEED}")                 # seconds one forward pass takes
FRAMES=$(awk "BEGIN{print int($PASS * $FPS * 2 + 0.5)}")   # frames in one forward-and-back cycle
LENGTH=$(awk "BEGIN{print $PASS * 2 * $TIMES}")            # output length in seconds
REPEATS=$((TIMES - 1))                                      # cycles after the first

ffmpeg -y -v error -i "$IN" -filter_complex "
  [0:v]trim=start=$START:duration=$SLICE,setpts=(PTS-STARTPTS)/$SPEED,fps=$FPS,split[fwd][back];
  [back]reverse[rev];
  [fwd][rev]concat=n=2:v=1:a=0,loop=loop=$REPEATS:size=$FRAMES,setpts=N/($FPS)/TB[v];
  [0:a]atrim=0:$LENGTH,asetpts=PTS-STARTPTS[a]" \
  -map "[v]" -map "[a]" -r "$FPS" -c:v libx264 -crf 18 -pix_fmt yuv420p -c:a aac "$OUT"
```

## More motion and camera

- [2.5D parallax photo **2.5D parallax photo**](https://www.recharm.com/effects/2-5d-parallax-photo)
- [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)
- [Clone effect **Clone effect**](https://www.recharm.com/effects/clone-effect)

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