Skip to content
streamneo.
Troubleshooting12 min read

How to Fix FFmpeg Looping Only the First Video in a YouTube Stream

Check FFmpeg input-option placement, build an ordered concat playlist, and test where a YouTube live stream stops.

sn.
StreamNeoPublished 7 October 2026
Worth sharing?

If FFmpeg only loops the first video, inspect the command before changing it: -stream_loop applies to the input it precedes, but that does not prove option placement is the cause. For several local clips that should play in order and repeat as a sequence, a concat-demuxer playlist can present them to FFmpeg as one input.

The fix depends on what your command actually reads and how it sends the stream to YouTube. Check the inputs, playlist, output mapping and ingest method first; then test the sequence and its repeat before relying on it overnight.

Check what the command is actually looping

Start by getting the complete command, with the YouTube stream key removed or replaced by a placeholder. Also note the FFmpeg version, source file formats and whether the output is a continuous RTMP-style stream or direct HLS upload. A stream key is a credential: do not paste it into a public forum, screenshot or support ticket.

Read the command from left to right and mark every -i. Each one introduces an input. Then mark where -stream_loop appears in relation to those inputs. If you have three separate files, you have three inputs, and a loop option placed before one of them is not automatically a loop instruction for the others. The exact command is needed to establish which file, if any, is configured to repeat.

Next, identify what “only the first video” means in your setup. Does FFmpeg keep sending the first file indefinitely, play it once and stop, or play the first file before the stream disconnects? Those outcomes point to different checks. A local playlist may be wrong, the command may map only one input, an output duration option may stop the job, or YouTube may be reporting an ingest problem.

Keep a copy of the original command before editing it. If you share logs, redact the stream key and any private paths. Record the exact point at which the visible output changes or ends, along with the relevant FFmpeg messages. A symptom report is useful, but it cannot substitute for inspecting the actual inputs and output options.

If the question is really how to rotate several prerecorded services rather than diagnose this command, the practical constraints are different; this guide to streaming prerecorded church services from a Windows laptop in India covers that broader operating setup.

Understand -stream_loop as an input option

FFmpeg classifies -stream_loop as an input option. Its value -1 means infinite looping, while 0 means no looping. Input options are read in connection with the input they precede, so option placement matters. The FFmpeg command-line documentation is the primary reference for the option and the way command options are applied.

In plain language, FFmpeg does not treat -stream_loop -1 as a general instruction to repeat every file mentioned anywhere later in the command. It is associated with an input. If there are multiple -i entries, inspect the option immediately before each relevant input rather than assuming the first setting covers the whole command.

That explains one plausible cause of a first-file-only loop, not a confirmed diagnosis. The command might instead use one input and have a separate playlist issue, or a later output option could be limiting the broadcast. The rule is a reason to inspect, not a reason to declare the cause without evidence.

The simplest mental model is: input options describe how FFmpeg reads a particular input; output options describe what it does when writing an output. A command can have several input and output groups, and ordering is meaningful. If you are unsure where a particular option belongs, check the current FFmpeg documentation for that option rather than moving options by trial and error.

Inspect option placement around each input

For separate inputs, annotate the command before you change it. For example, this schematic form has two independent inputs:

ffmpeg -stream_loop -1 -i first.mp4 -i second.mp4 ...

The loop setting precedes first.mp4; it does not, by itself, tell you that second.mp4 is looped. If your intention is to loop both inputs independently, the option needs to be placed before each input that should repeat. But that is not necessarily the right design: two files treated as separate inputs may not play one after another in the way you intend. Output mapping and other options determine what reaches the output.

Look closely at -map, -shortest, and any output duration or stop condition. -map selects streams for output; -shortest can end output when the shortest mapped stream ends. A duration limit can also stop a command even if an input is looped. None of these should be blamed without seeing the full command and the input stream report.

For a playlist, separate inputs may be the wrong representation. They are appropriate when you intentionally handle multiple sources as separate streams or need explicit mapping. If your goal is “play clip one, then clip two, then clip three, then repeat that whole order,” build a single playlist input instead. This makes the desired order explicit and gives the loop option one input to act on.

Keep a small troubleshooting record: command with credentials redacted, FFmpeg version, file names and order, input stream details, and the first relevant error or transition. That information helps distinguish a placement mistake from incompatible files or an output issue. It is more useful than repeatedly adding flags without knowing which part of the command changed behaviour.

Build one ordered input with the concat demuxer

The concat demuxer reads a script listing files in order and exposes the sequence as one input. For local clips, make a plain text playlist such as:

ffconcat version 1.0
file '/path/to/clip-01.mp4'
file '/path/to/clip-02.mp4'
file '/path/to/clip-03.mp4'

The signature must be at the start of the first line exactly as shown, with no leading whitespace or byte-order mark, if you want automatic format recognition. Each file line names one media file. Use paths that are valid from the directory where FFmpeg runs. Paths containing spaces or special characters need correct quoting or escaping; check the concat demuxer documentation if a path is not being read as expected.

A command can then treat the playlist as a single input and loop that input:

ffmpeg -re -stream_loop -1 -f concat -safe 0 -i playlist.txt \
  -c:v libx264 -c:a aac -f flv 'rtmp://a.rtmp.youtube.com/live2/STREAM_KEY'

This is a shape to adapt, not a verified recipe for every machine or channel. Replace the paths, codecs, output format and destination with settings suitable for your sources and YouTube ingest configuration. Never publish a real stream key. The FFmpeg documentation for the concat demuxer describes its playlist format and constraints.

The -safe 0 flag permits paths that the concat demuxer would otherwise reject as unsafe; use it only when you control the playlist and understand its paths. A playlist from an untrusted source should not be allowed to point FFmpeg at arbitrary local files. The -re option reads at the input's native rate, equivalent to -readrate 1, which can be useful for file-based streaming. FFmpeg cautions against using it with an actual capture device or live stream, where throttling may cause packet loss.

The concat demuxer is not the same as joining files into a new rendered video. It reads them in order during playback, without first producing a combined file. That can save a preparation step, but it also means input compatibility matters at the transitions. Do not assume that -c copy will fix mismatched streams: stream copying preserves the existing encoded streams rather than normalising them.

Check compatibility before relying on the playlist

Concat demuxing expects compatible streams across the files: matching stream layouts, codecs and time bases are important. If one clip has video and audio while another has only video, or the clips use different encoding parameters, playback may fail or show errors at a boundary. Inspect FFmpeg's input stream report for every file before treating the playlist as ready.

Duration metadata matters as well. The demuxer uses file durations when adjusting timestamps across the sequence. Incorrect metadata or a truncated file can therefore create timestamp jumps, gaps or other boundary artefacts. The concat script supports a duration directive to override an inaccurate duration where you have established the correct value; do not guess a duration merely to silence a warning.

When the clips differ, consider re-encoding them to a common set of video and audio parameters before streaming. That takes time and processing capacity, but can make the sequence more predictable. Stream copying avoids re-encoding, yet it cannot make incompatible codecs, time bases or stream layouts match. Choose based on actual file properties and test the result.

A helpful way to separate problems is to test the playlist locally without sending it to YouTube. Confirm that each clip appears in the expected order and that the transition to the next clip is clean. If it fails there, changing YouTube's ingest settings is unlikely to repair the local sequence. If the local sequence is sound but the YouTube output fails, move on to output and ingest checks.

For broader output-quality decisions, use a relevant guide to changing the quality of a 24/7 recorded lesson stream without stopping it. The key point here is to settle the source sequence first, rather than changing bitrate or resolution to solve an input-order problem.

Test the playlist sequence and repeat

Test with a short, recognisable playlist before scheduling a long broadcast. Give each clip an obvious visual or audio cue, so you can tell whether the order is correct without relying only on filenames. Watch the last clip return to the first. A sequence that plays correctly once has not yet demonstrated that its repeat behaves as intended.

Check at least three stages: FFmpeg opening the playlist, playback across each boundary, and the transition from the final entry back to the first. Look at the console for file-open failures, timestamp warnings, missing streams or an unexpected end. Save enough of the log to diagnose a failure, but remove the stream key and other sensitive details before sharing it.

If the order is wrong, verify the playlist lines rather than assuming FFmpeg sorts filenames. The concat script uses the order in which its file directives appear. If a clip is missing, verify the exact path and permissions. If a transition is broken, compare the involved files' stream layout, codec, time base and duration metadata before changing the loop option.

Once the local test passes, test the actual streaming path with a private or otherwise controlled broadcast where appropriate. Confirm that YouTube receives a continuous feed and that the visible transition and return to the beginning match the local test. This checks the entire path, including output encoding and ingest, not just the playlist parser.

If the stream stops after the first file despite a correct playlist test, inspect -map, -shortest, output duration settings and FFmpeg's final log messages. A clean local sequence narrows the search; it does not prove the output command is correct. Change one relevant variable at a time so you can see which adjustment affected the result.

Verify the YouTube output and ingest path

Most file-to-YouTube workflows send a continuous encoded output to an ingest endpoint. In that arrangement, the main branches are local file looping, output encoding and muxing, network delivery, and YouTube's ingest status. A loop setting does not guarantee that every later stage is healthy. Check the live control room and FFmpeg output alongside the local playback test.

Do not apply HLS playlist advice to a continuous RTMP output unless you are actually using HLS. Direct HLS ingestion has a different workflow: YouTube's HLS ingestion documentation describes media playlists and segments, including ordering and sequence requirements. It says the HLS ingest uses media playlists and ignores master playlists. If you upload HLS segments directly, inspect the generated media playlist, segment names and order, sequence numbers, and server acknowledgements against the current official requirements.

The choice between continuous output and direct HLS is not a way to paper over a malformed local playlist. First establish which ingest path your command uses. Then check the requirements for that path, including the endpoint and protocol currently configured for your channel. Exact ingest settings and FFmpeg behaviour can vary with the version and setup, so treat examples as starting points rather than guarantees.

If the command is running on a home PC, the machine and network also become part of the operating risk: power interruptions, sleep settings or a changing connection can stop a stream even when the playlist is correct. A guide to keeping an OBS shop-promotion playlist running after a Windows update covers a related continuity problem, though it is not a substitute for diagnosing this FFmpeg command.

For a long-running channel where the specific burden is keeping the computer on and recovering a file-based broadcast after a drop, StreamNeo removes that particular operational task: you upload the video, provide your YouTube stream key, and the broadcast runs with your own computer switched off. It is for YouTube streams, not a general-purpose FFmpeg repair tool, so first verify that your files and channel are ready.

Before committing, compare the operating options on the pricing page. When the file and channel are ready, start free — 24-hour trial, no card.

FAQ

Why does FFmpeg only loop the first video?

One possible reason is that -stream_loop precedes one input but not the others. It is an input option, so inspect the full command before treating that as the cause; output mapping, stop conditions, file compatibility or ingest can also explain the symptom.

How do I loop a playlist of videos on YouTube Live?

For ordered local clips that should repeat together, list them in a concat-demuxer script and use that script as one input with the loop option placed before its -i. Check that the clips have compatible streams and test the sequence and repeat locally before sending it to YouTube.

Why does my FFmpeg stream stop after the first file?

Check whether the playlist actually contains the later files, whether each path is readable, and whether the command maps the intended streams. Also inspect -shortest, duration limits and the final FFmpeg log messages; without the command and logs, the exact cause cannot be confirmed.

Should I use RTMP or HLS?

Use the ingest path your YouTube setup is configured for, and follow its current official requirements. HLS media-playlist and segment rules are separate from local FFmpeg file looping, so they are relevant only when you are directly sending HLS segments.

YOU’VE REACHED THE END

Keep the ideas coming.

More guides, useful tools and a little help for your next broadcast.

Back to the journal ↗
YOUR NEXT READ

A little more to explore.

More Troubleshooting guides ↗ · All topics ↗