-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
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
Loop under a song, to an exact length
-1loops forever, so-t 30ends 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.mp4The loop filter
looprepeats frames it has buffered:sizeframes fromstart,loopmore times. It only handles video, so-androps 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.mp4Loop 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
| Flag | What it does | Used here |
|---|---|---|
-stream_loop 2 | Reads the input 2 more times; goes before -i | 3 plays, re-encode |
-stream_loop -1 | Loops forever; end it with -t | Under a song |
-c copy | Copies the streams without decoding | 3 plays |
-t 30 | Ends the output at 30 s | Under a song |
-map 1:a | Takes the audio from the second input | Under a song |
loop=2 | Repeats the buffered frames 2 more times | Loop filter |
size=320 | How many frames the filter buffers; our clip has 320 | Loop 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.
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"]
}'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.
- Video to GIF with ffmpegMake a clean GIF from a video with palettegen and paletteuse, then shrink it with frame rate, size, colours or a different format.
- Reverse a video with ffmpegPlay a clip backwards with reverse and areverse, keep memory down on long clips, and make a boomerang loop.
- Speed up or slow down video with ffmpegChange playback speed with setpts for the picture and atempo for the sound, from timelapse to smooth slow motion.
- Concatenate videos with ffmpegJoin clips with the concat demuxer and -c copy when they match, or with the concat filter when their size, frame rate or codec differ.
- Replace the audio in a video with ffmpegSwap a video's soundtrack for another file with -map and -shortest, keep the picture untouched, and pad audio that runs short.
- Add music to videoMix a looped music track under a video's own audio with ducking and a fade-out in one ffmpeg call, for a fraction of a cent.
- FFmpeg onlineRun your own ffmpeg command on your files in the browser, free and without installing or uploading anything.
- ffmpeg exited with code 1: Conversion failed!fluent-ffmpeg reports only ffmpeg's exit code and last line. The real cause is in stderr: print it, or use -v error to see it alone.
- ReelSDK vs self-hosted FFmpegTranscoding a minute of 1080p to 720p takes about 24 seconds of compute: about 0.8 cents on ReelSDK, about a tenth of a cent on a busy 4 vCPU box. Below about 11,000 minutes a month, the API costs less than an always-on box.
Sources, checked November 2026
Ready to build?
Ship video from your app today
Your first $0.50 is free, and one key covers every endpoint.
