Skip to content
streamneo.
Tools14 min read

How to Create a Looping Video Playlist for a YouTube Livestream with FFmpeg

Build a looping FFmpeg playlist for YouTube Live, match files and encoder settings, protect your stream key, and diagnose interruptions.

sn.
StreamNeoPublished 4 October 2026
Worth sharing?

A looping FFmpeg playlist can play local videos in a defined order and send the result to YouTube Live repeatedly. The reliable part is not the loop flag alone: your files must be compatible, the output must match YouTube’s ingest settings, and the stream needs a test before you depend on it.

You will create a text playlist, ask FFmpeg to read it in real time and repeat it, then publish the encoded output through YouTube’s server URL and stream key. The commands below are a starting point, not a guarantee that every collection of files or every host will behave identically.

Confirm YouTube access and create the stream

Before troubleshooting FFmpeg, make sure the channel can use live streaming. YouTube says the channel must be verified and must not have had live-streaming restrictions in the previous 90 days. Access can still take time to become available after verification, so check the current requirements in YouTube’s live-streaming help rather than assuming that a verified channel is ready immediately.

In YouTube Studio, open the Live Control Room and create or select the stream you want to use. YouTube provides the server URL and stream key there. Copy both into a secure note or password manager, and do not put the key in a public tutorial, screenshot, shell history that other users can read, or shared script.

A stream key is a credential. If you think it has been exposed, use YouTube’s reset control and update the FFmpeg destination. A reset key means that an older command or process may stop connecting, so check which machine or scheduled task is still using it before restarting.

You should also decide whether you are creating a scheduled event or using a reusable stream setup. The exact controls can change in YouTube Studio. The important distinction for this workflow is that FFmpeg needs the current ingest details from the Live Control Room, not a URL copied from a previous broadcast.

If live access is still pending, resolve that first. Starting FFmpeg repeatedly while access is unavailable creates confusing encoder errors that are not caused by your playlist.

Prepare and order the local video files

Start with a folder containing only the files intended for this broadcast. Give them simple names that show the playback order, such as 01-opening.mp4, 02-bhajan.mp4, and 03-closing.mp4. This is not required by FFmpeg, but it makes it easier to inspect the folder and generate a playlist without accidentally swapping two items.

Check each file before you combine it with the others. Confirm that it opens from beginning to end, has the expected audio, and does not stop early in a normal media player. A truncated file or inaccurate duration metadata can create a damaged transition, a gap, or an FFmpeg message when the process advances to the next item.

The concat demuxer is appropriate when the inputs have the same streams and compatible properties. FFmpeg’s documentation says the files need matching stream structures, codecs and time bases. In practical terms, a playlist made from several 1080p H.264 files with the same audio arrangement is a better candidate than one mixing a vertical phone recording, a screen capture without audio, and a 4K file with a different frame rate.

Use this comparison before choosing a method:

Source files Suitable approach Main trade-off
Same video and audio layout, compatible codecs and properties Concat demuxer with a playlist file Less processing, but transitions depend on compatible inputs
Different resolutions, frame rates, codecs or audio layouts Normalise or re-encode first, or use the concat filter More preparation and CPU use, with a more consistent output
One file has no audio while the others do Add or create a consistent audio stream before concatenation Avoids changing stream structure at a transition
Files have uncertain durations or damaged sections Repair or replace them before streaming Takes time, but avoids discovering the fault during a live broadcast

If your sources differ materially, do not expect the concat demuxer to act as a normaliser. FFmpeg’s FAQ distinguishes the concat filter for cases where the inputs need re-encoding. A filter-based workflow gives you more control over scaling, frame rate and audio, but it also means encoding work that the demuxer can avoid.

For a devotional channel, for example, you might prepare every clip as the same landscape resolution, frame rate, video codec and audio format before building the playlist. For a local news loop, you might also check that each segment begins and ends cleanly, because a one-second flash or missing audio becomes repetitive when the sequence returns to the start.

Build the looping playlist with FFmpeg

Create a plain-text file called playlist.txt in a known folder. Put one entry on each line, in the order viewers should see them:

file '/path/to/01-opening.mp4'
file '/path/to/02-main-programme.mp4'
file '/path/to/03-closing.mp4'

The syntax belongs to FFmpeg’s concat demuxer. Use the actual local paths, not web addresses. If a path contains spaces or special characters, quote or escape it according to the concat demuxer’s documented syntax. A simpler filename such as 02-main-programme.mp4 reduces the chance of a quoting mistake.

On Windows, use paths in a form supported by your FFmpeg build and shell, and test one entry before assembling the whole list. On Linux or macOS, an absolute path removes ambiguity when the command later runs from a different working directory. The -safe 0 option in the example below permits paths that FFmpeg would otherwise reject as unsafe, so use it only with a playlist you created and checked yourself.

A starting command is:

ffmpeg -re -stream_loop -1 -f concat -safe 0 -i playlist.txt \
  -c:v libx264 -preset veryfast -b:v 5M -maxrate 5M -bufsize 10M \
  -r 30 -g 60 -keyint_min 60 -sc_threshold 0 \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv 'rtmps://SERVER_URL/STREAM_KEY'

Replace SERVER_URL and STREAM_KEY with the exact destination details shown in YouTube Live Control Room. Never publish a real key in a command example or commit it to a public repository.

Here, -re asks FFmpeg to read the file input at approximately its native playback rate rather than consuming it as quickly as the computer can decode it. -stream_loop -1 requests indefinite repetition of the input. Because the input is the concat playlist, it is intended to repeat the playlist rather than merely one selected file. It is an input option, so it appears before the -i it affects.

The command is illustrative. FFmpeg builds, operating systems and source files can behave differently, so inspect the logs during a test. If you only want to verify the sequence once, remove -stream_loop -1 while testing. That lets you confirm file order and transitions without leaving a process running indefinitely.

You can also use a separate local output test before sending anything to YouTube. For example, run the playlist without the streaming destination and inspect whether FFmpeg reports a missing file, a timestamp issue or a codec problem. The exact local test command depends on the output you want to examine, but the principle is simple: separate playlist faults from network and ingest faults.

Match the output to YouTube’s ingest requirements

The sample uses H.264 video, AAC audio and RTMPS in an FLV container as a common SDR starting point. YouTube’s current encoder guidance covers supported protocols and codec combinations, and its requirements can depend on the selected protocol and stream settings. Check the current encoder settings and bitrate guidance before choosing a final profile.

The sample’s -b:v 5M aligns with YouTube’s currently displayed H.264 recommendation for 1080p at 30 frames per second. The same table lists 14 Mbps for 1080p at 60 frames per second. These figures are recommendations for those settings, not universal targets for every stream. A lower resolution or frame rate may call for a different value, while a higher setting requires a connection and machine that can sustain it.

The command requests 30 frames per second with -r 30. The GOP-related options request a keyframe every 60 frames, which is approximately two seconds at that frame rate. YouTube currently recommends a two-second keyframe frequency and says it should not exceed four seconds. If you change the frame rate, review the relationship between -r, -g and -keyint_min rather than copying the same numbers without thought.

-maxrate 5M and -bufsize 10M are included to give the encoder a defined bitrate and buffer shape. YouTube’s guidance recommends constant bitrate for live encoding. The network connection still has to carry the selected video bitrate, audio bitrate and protocol overhead consistently. A speed test is useful, but a preflight stream is more informative because it exercises the complete path from your files through FFmpeg to YouTube.

If the source files are already encoded appropriately, you may still choose to re-encode them for a stable live output. That uses CPU or hardware encoding capacity, but it gives the stream one predictable resolution, frame rate and codec. If your computer cannot encode and upload the selected profile comfortably, lower the output demands or move the workload to an environment you can monitor.

For more background on how pre-recorded material is treated in a live workflow, see this guide to YouTube live-stream video encoding requirements for pre-recorded content. Treat it as supporting reading and confirm platform settings on YouTube’s current documentation before publishing.

Connect FFmpeg using the stream URL and key

The final argument in the example is the destination. YouTube normally presents a server URL and stream key separately, while FFmpeg needs a complete output address. Combine them only in the form required by the Live Control Room and the protocol you selected.

Use RTMPS where it is available and appropriate. YouTube describes RTMPS as the secure extension to RTMP. Do not substitute a watch-page URL, channel URL or scheduled-event page URL for the encoder destination. Those addresses identify pages for viewers, not the ingest endpoint that accepts your encoded feed.

Keep credentials out of reusable public scripts. On a shared machine, consider a protected environment variable or a permissions-restricted configuration file, while remembering that a process list, shell history or verbose log may still reveal command arguments depending on the operating system. The safest arrangement depends on who can access the host.

If you are running from a home computer, confirm that the machine will not sleep, disconnect the network adapter or apply an unexpected restart during the planned broadcast. If you are using a remote host, confirm that you can reach its console and retrieve FFmpeg logs. A command that works in an interactive terminal may fail later because it uses a relative playlist path or depends on a mounted drive that is no longer available.

If the problem you are solving is power loss rather than playlist construction, compare the operational choices in this guide to keeping a 24/7 forest ambience stream live during power cuts. The same principle applies to devotional, study and local-information channels: the playback process and the machine hosting it are separate failure points.

For people who do not want to keep a computer running and monitored, StreamNeo removes the need to install and supervise an FFmpeg process locally by letting you upload a video, provide the YouTube stream key and run the broadcast from the cloud with automatic monitoring and restart behaviour.

Test playback and check the live preview

Do not make the first run your overnight run. Start with a short test using representative material: include a normal transition, a clip with speech or music, and the point where the playlist returns to its first file. YouTube recommends testing before going live with audio and video movement similar to the planned stream.

Open the Live Control Room preview and check several things at once:

  • The preview receives video rather than showing a black or stalled frame.
  • Audio is present, at a sensible level, and continues through transitions.
  • The first file changes to the next file in the intended order.
  • The loop returns to the opening file without a long pause or corrupted frame.
  • YouTube’s stream-health messages do not show an ingest, bitrate or connection warning.
  • FFmpeg continues to report normal input, encoding and output activity.

Watch the computer’s CPU, memory, disk and network usage while the test runs. A machine may handle one short file but struggle when decoding several high-resolution sources and encoding them at the same time. A disk that fills with logs or temporary files can also stop a process that was otherwise configured correctly.

Use a wired connection if it is practical, particularly when the wireless connection is inconsistent, but do not treat an Ethernet cable as a guarantee against dropped frames. YouTube’s advice is to select a quality your connection can sustain and test the upload bitrate. What matters is the stability of the complete connection during the test, not only the headline speed at one moment.

If the preview is healthy but the eventual watch page behaves differently, check that you are looking at the correct event and that the stream has been started or scheduled as intended in YouTube Studio. Keep the test private or unlisted when appropriate, and follow the current controls shown in the Live Control Room.

Troubleshoot playlist and stream interruptions

Start by identifying where the failure occurs. A missing file, concat syntax error or decoder warning points to the playlist or source media. A steady FFmpeg process with no YouTube preview points more towards the destination, key, protocol or network. A preview that starts correctly and later stops may involve bandwidth variation, a host restart, a damaged file at a later position, or a process that has exited after an error.

The playlist does not start

Check that playlist.txt exists in the command’s working directory, or replace it with an absolute path. Verify every filename character by character. A path with spaces, apostrophes or other special characters needs the quoting and escaping expected by the concat demuxer.

Run a short test with one known-good file. If that works, add the remaining files until the failure returns. This binary-style check is usually faster than staring at the complete command. Also inspect whether the playlist is saved as ordinary text and whether its lines begin with the required file directive.

A transition shows a black frame, glitch or missing audio

Compare the affected files’ stream layouts, codecs, resolution, frame rate, sample rate and channel arrangement. The concat demuxer does not reliably normalise those differences. A file without an audio stream is especially likely to create a mismatch when the other files contain audio.

Preprocess the sources to a common profile, or use the concat filter and re-encode them into a consistent output. This costs preparation time and processing capacity, but it is more controlled than asking the demuxer to join incompatible inputs. If only one file is damaged, replacing that file may be simpler than changing the whole workflow.

YouTube reports an ingest or bitrate problem

Confirm that the server URL and stream key are current and copied without an extra character. If the key was reset, update the command. Confirm that the chosen bitrate is sustainable for the upload connection and that FFmpeg is not falling behind while encoding.

Review the output resolution, frame rate, codec, audio codec and keyframe interval against YouTube’s current guidance. A setting that is valid for one protocol or frame rate may not be the right setting for another. Lowering the output complexity can help diagnose the issue, but it does not explain why the original profile failed unless you also examine the encoder and network logs.

The stream stops after a while

Do not assume that -stream_loop -1 provides process supervision. It asks FFmpeg to repeat the input; it does not repair a damaged source, restore a broken network path or restart a host after a power cut. Check the last log lines and determine whether FFmpeg exited, lost the input, or remained active while the connection failed.

A longer-running setup needs an operating-system restart plan, disk-space monitoring, access to logs and a way to verify stream health. The exact solution depends on whether you are using a desktop, VPS or another host. If you schedule a restart, avoid creating two FFmpeg processes that use the same stream key at the same time.

For a different approach to sequencing files, compare this FFmpeg workflow with automating a YouTube live playlist with OBS. OBS may suit readers who need a visible scene-based interface, while FFmpeg is more direct when the input is a known set of files and the command can be tested carefully.

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

Can I loop several videos without re-encoding them?

Yes, when the files have compatible streams, codecs and time bases, the concat demuxer can read them as one ordered input. If the files differ in resolution, frame rate, codecs or audio layout, normalise them first or use a filter-based re-encoding workflow.

What does -stream_loop -1 do in this command?

It requests indefinite repetition of the input, which is the concat playlist in the example. It does not guarantee that a damaged file, failed network connection or stopped FFmpeg process will recover. Check the behaviour against your installed FFmpeg version during a short test.

Where do I get the YouTube stream URL and key?

YouTube provides them in the Live Control Room after you create or select a stream. Treat the key as a password, keep it private, and reset it through YouTube if it may have been exposed.

Why does the playlist work locally but fail on YouTube?

Local playback proves that the files can be read, but it does not prove that the encoded bitrate, keyframe interval, upload connection, protocol or stream credentials are suitable for YouTube ingest. Use the Live Control Room preview, inspect YouTube’s stream-health messages and read the FFmpeg output during a representative test.

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 ↗