Skip to content
streamneo.
Tools11 min read

FFmpeg Command to Loop Several Videos in Sequence for YouTube Live

Build an FFmpeg concat playlist, check file compatibility, loop the sequence and verify YouTube Live ingest before relying on it.

sn.
StreamNeoPublished 4 October 2026
Worth sharing?

To play several videos in order on YouTube Live, put their paths in an FFmpeg concat playlist and loop that playlist as the input. This approach is suitable only when the listed files have compatible streams, codecs and time bases; if they do not, prepare matching files or use a re-encoding workflow instead.

The command below is a starting template, not a tested result. Your installed FFmpeg build, media files, output profile and YouTube stream settings all need checking before a broadcast. The important distinction is that looping the input repeats the complete sequence, while the encoder settings govern the stream sent to YouTube.

Put the videos in the order you want

The concat demuxer reads a list of files in sequence. Make a text file called playlist.ffconcat and add one file line for each video, in the order you want viewers to see them:

ffconcat version 1.0
file 'video-01.mp4'
file 'video-02.mp4'
file 'video-03.mp4'

The playlist is the running order: move a line to change the sequence, remove one to omit a video, or add a line for another file. A devotional channel, for example, might place an opening image first, then a set of bhajans, then a closing visual. The demuxer moves to the next listed input after the previous one; it does not randomise, cross-fade or select items based on a schedule.

Keep the file names and ordering deliberate. If a filename contains spaces or punctuation, quote it as shown, and make sure the path resolves from the working directory where you start FFmpeg. When you edit a playlist, save it before restarting the process: FFmpeg reads its input list for the run rather than acting as a channel scheduler that watches a folder for changes.

For a single-file alternative, a desktop workflow, or a more general explanation of keeping a continuous broadcast alive, see the VLC method for looping a video. That is a different route from this multi-file command, but it can suit you if you prefer a graphical player to maintaining a playlist file.

Use the header and paths correctly

The first line must be exactly ffconcat version 1.0, with no blank line or other text before it. FFmpeg uses that header for automatic recognition of this playlist format. Do not turn the file into a Markdown document or add explanatory comments above the header.

Simple relative paths are usually the least troublesome. Put the playlist beside its media and use names such as video-01.mp4, or use a consistent subfolder such as media/video-01.mp4. Paths are interpreted in the context of the process and playlist; if FFmpeg reports that a file cannot be opened, check both the spelling and the directory from which the command is being run.

The command template uses -safe 0, which allows broader path forms. That setting is not a general repair switch: only use it with a playlist you control, because a less restrictive list can refer to paths outside the expected simple-file pattern. Prefer paths accepted under the default safe mode when practical. The FFmpeg formats documentation explains the concat demuxer and its safe-path behaviour; consult it alongside the options available in your installed FFmpeg version.

Do not expose a YouTube stream key in a public script, screenshot, or shared log. The key is part of the destination configuration, not a value to copy from an example. Retrieve your own ingest details from YouTube Studio or the relevant live setup, and keep them private.

Check stream and time-base compatibility

The concat demuxer is not a general-purpose format converter. For the straightforward, no-re-encode route, inputs need compatible streams, codecs and time bases. Differences in resolution, frame rate, pixel format, audio layout or stream presence are reasons to investigate rather than assume the files will join cleanly. A playlist that opens is not by itself evidence that transitions will be correct.

Probe every file before committing to the sequence. Compare the video and audio streams, their codec and timing information, and whether each file has the same kinds of streams. If one clip has no audio and the others do, or a clip was exported at a different frame rate or with another codec, the list may fail or produce timestamp, sound or picture artifacts. The demuxer adjusts timestamps so each listed input follows the preceding one, but that does not make unlike inputs identical.

Choice When it fits Main trade-off
Concat demuxer Inputs have matching stream structure, codecs and time bases Can avoid re-encoding, but compatibility must be checked
Concat filter with re-encoding Inputs need normalising or filtering before they can be joined Adds an encoding step and requires a deliberate output profile

FFmpeg's concat FAQ describes the demuxer as the route that can avoid re-encoding when the inputs support it, and the concat filter for cases where re-encoding is needed. If files do not match, do not claim this template will work as-is. First normalise them to a common format or construct a filter workflow that handles the differences, then test the output. A more elaborate filter command depends on the actual files, so it should not be filled in with guessed settings.

This check is particularly worthwhile when clips come from different cameras, phones, editing exports or archive sources. For a channel running from a dedicated machine, the FFmpeg and VPS workflow covers a broader operating context; it does not remove the need to make the media compatible.

Loop the whole playlist

A practical command pattern for a compatible playlist is:

ffmpeg -re -stream_loop -1 -f concat -safe 0 -i playlist.ffconcat \
  -c:v libx264 -preset veryfast -b:v 4500k -maxrate 4500k -bufsize 9000k \
  -g 60 -keyint_min 60 -sc_threshold 0 \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv 'rtmps://YOUR_INGEST_HOST/YOUR_STREAM_KEY'

In this pattern, -stream_loop -1 appears before the concat input, so the input sequence is intended to repeat indefinitely. It is not a separate loop setting for each file. -re paces file input for live output rather than sending a stored programme as fast as the machine can process it. Option availability and exact syntax can vary with the installed build, so check ffmpeg -h full on the machine you intend to use and test the command there. This article does not assert that the template has been run successfully against your build or files.

The output path shown is a placeholder, not a usable YouTube address. Replace it with the RTMPS ingest address and stream name/key supplied in your own YouTube live setup. The YouTube Live Streaming API documentation describes the primary ingest address and the way encoder interfaces may request the URL and stream name separately or together. Follow the values and field layout shown by your current setup; never substitute a fabricated or shared key.

If you run a process yourself, it depends on the host machine, network connection and FFmpeg process continuing to operate. A small computer that sleeps, loses power or reboots can interrupt the stream. If your actual problem is keeping a process alive on a particular machine, the continuous-stream guide for a Mac mini addresses that separate operational question.

Set the live encoder and ingest deliberately

The example encodes video as H.264 with libx264 and audio as AAC, then packages the output as FLV for RTMP-family ingest. Its numeric values are illustrative starting values from the supplied template, not universal recommendations. Select bitrate, output resolution, frame rate and keyframe interval for the mode you intend to send, the available upload capacity and YouTube's current guidance.

YouTube's current live encoder guidance covers supported ingest and encoder settings, including RTMP/RTMPS, codecs and keyframe intervals. It recommends a two-second keyframe interval and says it should not exceed four seconds; check the current YouTube encoder settings page for the profile you plan to use. The page gives different bitrate recommendations for different output modes. For example, its H.264 recommendation for 1080p at 30 fps is 10 Mbps, as listed in the current guidance accessed in 2026. Do not apply that figure to every resolution and frame rate, or treat it as a required command value.

The sample's -g 60 and -keyint_min 60 represent a frame-count style GOP setting, not a universal two-second interval. The time represented by sixty frames depends on the output frame rate. Likewise, do not use the sample bitrate merely because it appears in a command: compare your chosen output mode with YouTube's table and the capacity of the connection carrying the stream. If you need to reason through the trade-offs between available upload capacity, bitrate and stability, use the live bitrate and stability guide.

YouTube recommends RTMPS, the encrypted extension of RTMP. Use the address provided in your own live setup and confirm whether FFmpeg expects one combined destination or separate URL and stream-name fields in your workflow. This matters because an otherwise valid encode can still fail to ingest if the destination is malformed, the stream key is stale, or the broadcast is not configured as expected in YouTube.

Test transitions and diagnose artifacts

Do a controlled test before relying on the playlist overnight. Include motion and audio similar to the planned broadcast, then inspect the transition from the end of one file to the start of the next and the transition from the final file back to the first. YouTube advises testing before a live event and monitoring stream health; its live encoder guidance is the place to confirm current requirements.

Watch and listen through several boundaries. A brief black frame, jump in sound, silence, unexpected aspect ratio or timestamp warning can point to incompatible inputs or an export problem. If only one boundary is wrong, compare the two files on either side rather than changing every command option at once. If every transition drifts or breaks, re-check stream structure and time bases across the full playlist.

Use the symptom as a diagnostic clue, not proof of one cause. A missing file usually points to a path or permissions issue; a decode error calls for inspecting the media; a rejected live destination calls for re-checking the URL, key and YouTube setup. Keep the terminal output from the test and note which playlist version was used, but remove or redact the stream key before sharing logs.

Also verify stream health in YouTube's live control room after the encoder connects. A command process that continues running does not prove the receiving platform is getting the intended picture, audio or bitrate. Test using the intended network and host where possible: changing from a desk test to a different machine or connection can expose a different failure mode. Do not start an unattended long run until the sequence has completed and returned to its first item in the test.

Choose the operating arrangement around the command

The command answers how compatible files can be sent in a repeated sequence. It does not decide whether your computer should stay on, whether the connection is stable, or how you will recover after a process exits. Those are operating decisions that matter just as much for a 24/7 channel. A local computer gives you direct access to the files and logs, but it remains dependent on local power, network and settings such as sleep prevention.

A VPS can keep a process away from a home computer, but adds remote administration and file transfer work. If you are weighing those approaches, consider which machine you can monitor, how you will update the playlist, and how you will notice a disconnected stream. The VPS options guide for prerecorded streams is useful for that broader decision; it is not a substitute for verifying your media or ingest settings.

If the pain is maintaining a computer and restarting the broadcast after a drop, StreamNeo removes that specific operating burden by turning an uploaded video into a YouTube live stream that can keep running while your computer is off. The playlist-command route remains useful when you want to control FFmpeg and the sequence directly; a hosted workflow is a different way to handle the always-on process, not a fix for mismatched source files.

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

Does -stream_loop -1 repeat each video or the complete list?

Placed before the concat input as in the template, it is intended to repeat that input, which is the playlist sequence. The listed files play in order and the sequence starts again after the last one. Verify this behaviour with your installed FFmpeg build and a test playlist rather than assuming a command copied from elsewhere matches your version.

Can I use files with different codecs or frame rates?

Do not assume the concat demuxer will handle mismatched inputs cleanly. Its simple route depends on compatible streams, codecs and time bases, and unlike files can fail or produce artifacts. Normalise the media first or use a concat-filter workflow with re-encoding when the inputs need conversion.

Why does the command include -safe 0?

It permits broader path forms in the playlist, but it is not needed for every list and should only be used with a playlist you control. Simple relative paths under the default safe behaviour are preferable when they work. Check FFmpeg's documentation if you need paths beyond that pattern.

Can I copy the destination URL and stream key from this example?

No. The destination is only a placeholder; use the ingest URL and stream name/key from your own YouTube Live setup, and keep the key private. Test the stream and inspect YouTube's health information before relying on it for a continuous broadcast.

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 Tools guides ↗ · All topics ↗