-stream_loop 2 -i clip.mp4 -c copy plays an 11-second clip 3 times in a 32-second file, written in a fraction of a second with nothing re-encoded. On ReelSDK that job cost under three quarters of a cent, billed per second at $0.02 per compute minute.

Loop a video with ffmpeg

Count carefully: 2 means two extra plays, not two in total, and -1 never stops. ReelSDK's API takes both -stream_loop and the loop filter, but the filter held close to 2 GB of memory for 11 seconds of HD.

GuidesUpdated

3 plays
ffmpeg -stream_loop 2 -i clip.mp4 -c copy looped.mp4

-stream_loop is an input option, so it goes before -i. With -c copy ffmpeg reads the file again and again and writes the packets as they are.

Variations

The other commands you will need

  1. Loop under a song, to an exact length

    -1 loops forever, so -t 30 ends the output. The video is copied and the music re-encoded, so it takes under a second.

    under a song
    ffmpeg -stream_loop -1 -i clip.mp4 -i music.mp3 -map 0:v -map 1:a -t 30 \
      -c:v copy -c:a aac -movflags +faststart under-music.mp4
  2. The loop filter

    loop repeats frames it has buffered: size frames from start, loop more times. It only handles video, so -an drops the sound here.

    loop filter
    ffmpeg -i clip.mp4 -vf loop=loop=2:size=320:start=0 \
      -an -c:v libx264 -crf 20 -preset veryfast -movflags +faststart looped-filter.mp4
  3. Loop and re-encode

    Add any filter and the stream can't be copied. Same loop, encoded again: about 28 seconds instead of a fraction of one.

    re-encode
    ffmpeg -stream_loop 2 -i clip.mp4 \
      -c:v libx264 -crf 20 -preset veryfast -c:a aac -movflags +faststart looped-reencode.mp4

The flags

The options in these commands

The options in these commands
FlagWhat it doesUsed here
-stream_loop 2Reads the input 2 more times; goes before -i3 plays, re-encode
-stream_loop -1Loops forever; end it with -tUnder a song
-c copyCopies the streams without decoding3 plays
-t 30Ends the output at 30 sUnder a song
-map 1:aTakes the audio from the second inputUnder a song
loop=2Repeats the buffered frames 2 more timesLoop filter
size=320How many frames the filter buffers; our clip has 320Loop filter

Sources: ffmpeg documentation: -stream_loop, ffmpeg filters: loop, checked November 2026.

Counting plays

The manual puts it plainly: "Loop 0 means no loop, loop -1 means infinite loop." So the number is extra plays. -stream_loop 2 played our clip 3 times.

With -1 the input never ends, so something else has to: -t with a length, or a shorter input with -shortest. Forget it and ffmpeg keeps writing until the disk or your patience runs out.

-stream_loop or the loop filter

-stream_loop works before decoding: it rewinds the file and reads it again. That is why the copy took a fraction of a second and almost no memory. The loop filter works on decoded frames and must hold every frame it repeats; for our vertical HD clip that meant close to 2 GB of memory and about 24 seconds of work.

Use the filter when you need to repeat a few frames in the middle of a graph, and -stream_loop for whole files.

On the API

-stream_loop and the loop filter are both allowed on POST /v1/ffmpeg. With -1, always set -t: a job without an end keeps writing until it hits a job limit such as timeout_s, at most 600 s. Billing is per compute second; see pricing.

Without installing ffmpeg

The same command as one API call

Send the first command's args to POST /v1/ffmpeg. Each job runs ffmpeg 8.1 on a fresh machine at $0.02 per compute minute, billed per second; this one finished in under 20 seconds and cost under three quarters of a cent, and its file matched our local one to the byte in size.

terminalTry it
curl "https://api.reelsdk.com/v1/ffmpeg?wait=60" \
  -H "Authorization: Bearer $REELSDK_KEY" \
  --json '{
    "inputs": {
      "clip.mp4": "https://api.reelsdk.com/f/lib/demo/clip.mp4"
    },
    "args": ["-stream_loop", "2", "-i", "clip.mp4", "-c", "copy", "looped.mp4"],
    "outputs": ["looped.mp4"]
  }'
looped.mp4 from the API: 3 plays, 32 seconds.Input: 10.667 s input

FAQ

Questions, answered

How do I loop a video 3 times with ffmpeg?

Run ffmpeg -stream_loop 2 -i clip.mp4 -c copy looped.mp4. The 2 means two extra plays; our 11-second clip became 32 seconds long in a fraction of a second.

How do I loop a video to match the length of a song?

Use -stream_loop -1 on the video, add the song as a second input, map its audio and set -t to the length you want.

Does looping with -stream_loop re-encode the video?

Not with -c copy: the packets are written as they are, so the quality stays the same. Adding a filter forces a re-encode.

What is the difference between -stream_loop and the loop filter?

-stream_loop rereads the input file before decoding. The loop filter buffers decoded frames, which needs far more memory: close to 2 GB on our clip, over 50 times what -stream_loop used.

Ready to build?

Ship video from your app today

Your first $0.50 is free, and one key covers every endpoint.

Moonlit lake with a lit cabin under the mountains