Skip to content
streamneo.
Setup Guides14 min read

How to Loop Pre-Recorded Videos on YouTube Live with FFmpeg

Use FFmpeg's concat demuxer to loop compatible videos on YouTube Live, test the stream, monitor it and keep a local recording.

sn.
StreamNeoPublished 3 October 2026
Worth sharing?

To loop a pre-recorded video on YouTube Live with FFmpeg, make FFmpeg read the file at its normal speed, repeat it indefinitely, and send the encoded output to the stream URL and key from YouTube Live Control Room. For a playlist, the more reliable method is to prepare compatible files, join them with FFmpeg’s concat demuxer, and loop that playlist input.

The command is only the final part of the setup. Differences in resolution, frame rate, codecs, audio layout and timestamps can make a playlist fail at a boundary, even when every file plays correctly on its own. Prepare and test the media before leaving the channel unattended.

Prepare the playlist files

Start by deciding what one complete cycle should contain. It might be a devotional video followed by a set of bhajans, a sequence of local news segments, several study scenes or a collection of your own highlights. Put the files in one working folder and use simple filenames without unnecessary punctuation.

The concat demuxer reads a text file that lists media files in order. It does not create a new video at this stage. Instead, it presents the listed files to FFmpeg as one logical input. That is useful because you can change the order by editing a small text file rather than rebuilding the media every time.

Before building the list, play every source file from beginning to end. Check for a silent opening, a damaged ending, an unexpected advert, a portrait clip or a different frame rate. A playlist can be technically valid while still producing an awkward transition. If the channel is meant to be calm and continuous, inspect the joins rather than assuming that the player has hidden the differences.

Keep the original files in a separate folder and work from copies. If you later re-encode the playlist, you will still have the source material available. It is also worth keeping a plain note of the order, duration and intended use of each file. That makes it easier to identify which item was playing when a monitoring alert arrives.

If your content includes material made by someone else, check the current YouTube guidance and your rights before streaming it. A file that you can play locally is not automatically cleared for a public live broadcast. The explanation in Does YouTube Allow 24/7 Live Streams of Pre-Recorded Videos? covers the difference between a technical loop and the separate policy and rights questions around it.

Match the stream layout, codecs and time bases

The concat demuxer works best when the files share the same important stream properties. Aim for the same video codec, pixel dimensions, frame rate, pixel format, audio codec, sample rate, channel layout and time-base behaviour. For a practical YouTube output, H.264 video with AAC audio is a common target.

For example, joining two 1920×1080 H.264 files encoded at 30 frames per second with AAC stereo audio is a much more predictable starting point than joining a 1080p30 file, a 720p25 file and a portrait phone recording with mono audio. Each source may play without trouble in a media player, but the joins can expose timestamp or format changes.

The concat demuxer is not a general-purpose format converter. It expects the streams in the listed files to be compatible enough to be treated as one sequence. If they are not, use a preparation step to convert them to a common format before making the playlist. This takes more storage and processing time, but it moves the uncertainty away from the overnight stream.

A consistent output frame rate also makes the keyframe setting easier to reason about. The example below assumes 30 fps and uses -g 60, which requests a keyframe every 60 frames, or roughly two seconds. If you use another frame rate, calculate the group-of-pictures value from that output rate rather than copying 60 without checking.

YouTube’s encoder settings and bitrate guidance recommends a two-second keyframe interval and says not to exceed four seconds. It also lists 14 Mbps as the recommended H.264 video bitrate for 1080p30 and 5 Mbps as the minimum. Those are platform recommendations, not a guarantee that your connection or computer can sustain the output.

For a slower connection, lowering the output resolution and bitrate may be more sensible than allowing repeated congestion. YouTube recommends constant bitrate encoding for live streams. In the command below, equal -minrate, -b:v and -maxrate values create a CBR-style x264 configuration, while -bufsize controls the rate-control buffer.

Audio deserves the same attention. A missing audio stream in one file, an unusual sample rate or a change from stereo to mono can create a discontinuity at the join. Normalising the playlist to AAC audio at 44.1 kHz and a consistent channel layout is a practical starting point, but confirm that the resulting file actually contains the streams you expect.

Build the concat-demuxer input

Create a text file called playlist.txt in the working folder. Use one line for each media file, in the order you want it to play:

file '/media/channel/intro.mp4'
file '/media/channel/programme-01.mp4'
file '/media/channel/programme-02.mp4'

The syntax is deliberately simple. Each line begins with file, followed by the path in quotes. On a system where the files are in the same folder as the playlist, relative paths can be easier to move between machines:

file 'intro.mp4'
file 'programme-01.mp4'
file 'programme-02.mp4'

Use the path format expected by the operating system and FFmpeg build you are using. Spaces and quote characters in filenames can complicate the list, so renaming files to plain names is often quicker than debugging a malformed playlist. If you use paths outside the current directory, check that the FFmpeg process has permission to read them.

Some FFmpeg builds restrict access to paths outside the playlist directory unless you explicitly allow them. If FFmpeg reports a safe-file or permission error, read the documentation for your build and use the relevant option only after confirming the paths are trusted. Do not solve a path problem by placing a stream key, password or unrelated private file in the same command or playlist.

You can inspect the source streams before concatenation with ffprobe, which is installed with many FFmpeg distributions. The exact output varies by build, but you are looking for matching dimensions, frame rates, codecs, sample rates and channel layouts. If one file differs, convert that file first or convert all source files through the same preparation command.

A useful preparation pattern is to produce a directory of normalised files, then make playlist.txt point only to those outputs. That leaves the original recordings untouched and gives you a clear boundary between source media and broadcast media. The concat list should not quietly mix originals and normalised copies, as that can reintroduce the mismatch you were trying to remove.

The concat demuxer joins packets rather than smoothing the picture at every boundary. Even with matching properties, a small transition may be visible or audible. If you need a fade, crossfade or branded transition, create those transitions during an editing or filter stage and then stream the resulting compatible output. Do not expect the demuxer itself to manufacture a seamless changeover.

Repeat the playlist and publish to YouTube

Once the playlist has compatible files, the core command is:

ffmpeg -re -stream_loop -1 -f concat -safe 0 -i "/media/channel/playlist.txt" \
  -c:v libx264 -preset veryfast -b:v 14M -minrate 14M -maxrate 14M -bufsize 28M -g 60 \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv "rtmp://YOUR_INGEST_URL/YOUR_STREAM_KEY"

Replace the playlist path and the final address with your own values. YouTube provides the stream URL and key in Live Control Room. The key authorises the encoder to send the feed, so treat it like a password and do not paste it into a public tutorial, screenshot or shared support message. YouTube explains the encoder connection process in Create a YouTube live stream with an encoder.

Here, -re tells FFmpeg to read the file input at its native pace rather than consuming it as quickly as the computer can process it. That matters when a stored file is being used as a live source. Without it, FFmpeg may process the playlist faster than real time and send data in bursts.

-stream_loop -1 is also an input option. FFmpeg defines -1 as infinite looping. Because input options apply to the following input, both options appear before -i. The -f concat option tells FFmpeg to use the concat demuxer for the playlist text file, while -safe 0 allows the path form commonly used in a local playlist. Use it only with a list you created or checked yourself.

The output is encoded again rather than copied. That is intentional. Re-encoding gives you one consistent H.264 video stream and one consistent AAC audio stream for the complete output, which is usually more reliable than attempting to pass through a playlist whose source properties differ. It also uses more CPU and may create a visible change in quality compared with the source.

The command uses FLV output for an RTMP-style destination. YouTube recommends RTMPS for encrypted transport where supported, so use the secure ingest address supplied or documented for your stream rather than changing an address by guesswork. If your chosen destination uses a different protocol or URL format, the output format and connection settings may need to change.

For one compatible file instead of a playlist, the simpler pattern is to put -stream_loop -1 before that file’s -i and keep -re before the input as well. The playlist method is preferable when you need several files in a fixed cycle, because the content order remains visible and editable.

The sample is a 1080p30 starting point, not a universal answer. If your output is 25 fps, 24 fps, 720p or a different codec profile, adjust the video settings and GOP calculation. Watch the encoder log for dropped frames, repeated connection failures, non-monotonic timestamps or audio errors instead of treating a successful process launch as proof that the broadcast is healthy.

Test before unattended use

Create the live stream in YouTube Studio and confirm that your channel is eligible to stream. YouTube’s live-streaming eligibility guidance covers verification, restrictions and age requirements. Eligibility is separate from whether FFmpeg can connect successfully.

Start with a private or unlisted test. Run FFmpeg and wait for the preview in Live Control Room. Check the first file, the first transition and at least one complete return to the beginning of the playlist. A command can connect correctly while the second pass reveals a timestamp problem or a file that was not included in the list.

Listen with headphones as well as watching the preview. Check that audio starts when expected, does not drift from the picture and does not become silent after a transition. Look for a stretched image, unexpected pillarboxing, a change in frame rate or a sudden quality drop. These are often signs that the sources were not normalised consistently.

YouTube’s stream health indicators are useful, but they do not replace a human check of the content. Confirm that the title, visibility, thumbnail and intended stream selection are correct. A healthy encoder feed does not by itself make the stream public, and starting an encoder does not necessarily complete the separate Go live action in Live Control Room.

Keep the test running long enough to expose the problem you are trying to prevent. If the live channel must run overnight, do not rely only on a five-minute connection check. Test a playlist boundary, temporarily interrupt the network if you are testing recovery, and restart the process deliberately so you know what the recovery procedure looks like.

Allow upload headroom. YouTube’s streaming tips recommend leaving approximately 20% room beyond the total streaming bitrate. Other people or devices using the same connection can remove that margin, and a connection that is adequate for browsing may still be unsuitable for a continuous encoded upload.

Monitor continuous operation

An unattended FFmpeg process needs observation at two levels: the encoder and YouTube. On the computer, watch whether FFmpeg is still running, whether the log shows repeated reconnects or write errors, and whether CPU, memory, disk and network use remain within comfortable limits. On YouTube, inspect stream health, preview availability and any warnings in Live Control Room.

Do not hide the terminal output until the stream has proven stable. Save the log to a file if your operating system and launch method support it, with a rotation policy so a long-running process does not fill the disk. Record the time of each restart and the last playlist item you observed. That history can distinguish a source-file problem from a network interruption.

A restart may reconnect to the existing stream configuration, but the exact viewer experience depends on the stream settings and what YouTube accepts at that moment. Follow the encoder stop and start workflow in YouTube’s documentation rather than repeatedly killing processes at random. The guide on restarting a 24/7 YouTube stream without losing its watch page is useful when you need to plan that procedure.

Protect the stream key while setting up monitoring. An alert can tell you that the process stopped, but it should not include the key in the alert message. If another person needs to help, give them the minimum access they need through the channel’s normal account controls instead of sending credentials in a chat.

Monitoring also includes content checks. A stream can remain technically connected while repeating the wrong file, showing a frozen frame or playing silence. For a channel that runs while you sleep, use periodic preview checks and keep a simple checklist for the first minutes after every restart. If the channel has chat enabled, consider moderation arrangements described in Chat Moderation for Always-On Streams rather than assuming the chat will manage itself.

Record locally if a durable copy matters

A YouTube live stream is not a substitute for your own master recording. YouTube explains that archived live streams are subject to an archive-duration caveat, so do not promise yourself that a very long broadcast will remain available as a complete archive. If a durable copy matters, record locally while you stream or create a separate local capture before publishing.

FFmpeg can write more than one output from the same input. One output can go to YouTube and another can be written to a local file, but recording the complete, endlessly looping output creates a very large file and requires enough disk space for the intended duration. A local recording also stops being useful if the computer loses power, the disk fills or the process fails without an alert.

For a durable source copy, it is often better to retain the original files and the normalised playlist outputs separately. That gives you editable material, a known broadcast version and the playlist order used for the stream. If you need evidence of what was actually broadcast, record the encoded output as well, with clear file rotation rather than one uncontrolled file that grows forever.

The local recording option changes the operating requirements. You now need to monitor disk capacity, write speed and file integrity in addition to upload bandwidth. Use a storage location with enough free space, decide how long recordings should be kept, and test that the resulting files open correctly before deleting the source or previous copy.

A hosted workflow can remove the need to keep your own computer running, but it does not remove the need to preserve content deliberately. StreamNeo turns an uploaded file into a YouTube live stream after you provide the stream key, with the broadcast running while your computer is switched off and automatic monitoring and restarting if it drops. That is useful when the specific pain is leaving a local FFmpeg machine powered and watched through the night, but you should still keep your own source files if the content matters.

What to do before leaving it overnight

Use this order for a dependable handover. First, make a clean folder of source files and a separate folder of normalised broadcast files. Next, inspect the stream properties and build a concat list containing only compatible files. Then run the command against a private or unlisted YouTube stream and watch a complete playlist boundary.

After that, confirm the output bitrate, frame rate, audio and keyframe interval against the current YouTube recommendations. Check that the upload connection has headroom and that no other device is likely to consume it unexpectedly. Keep the stream key private and write down the exact command, playlist path and recovery steps.

Finally, decide what happens if FFmpeg stops, the connection drops or the archive is not available later. A simple restart plan, a local copy of the important media and a way to receive alerts are more useful than assuming an unattended process will correct every failure. If you need to compare approaches before committing to a local machine, the best free software options for a 24/7 YouTube radio stream provide useful context.

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 different videos with one FFmpeg command?

Yes. Put the files in a concat-demuxer text list, use -f concat -i playlist.txt, and add -stream_loop -1 before the input. The files should share compatible stream properties, and you should test the transition before using the command unattended.

Why use -re when the video is already saved on my computer?

A saved file can be read much faster than real time. -re makes FFmpeg read the input at its normal pace, which is appropriate when the output is intended to behave like a live broadcast rather than a fast file transfer.

Do I need to re-encode every file first?

Not always, but re-encoding to a common layout makes concatenation more predictable when the sources differ. If all files already match in codec, dimensions, frame rate, audio and related stream properties, the concat demuxer may work without a separate preparation pass. Test the actual files rather than assuming that similar filenames or resolutions mean they are compatible.

Will YouTube keep the complete archive of a continuous loop?

Do not rely on YouTube as the only durable copy of a very long broadcast. YouTube has an archive-duration caveat for live streams, so keep the original or locally recorded files when preservation matters.

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