To loop local video clips in order to YouTube Live, create a text playlist and pass it to FFmpeg’s concat demuxer, then use input looping and real-time pacing before sending the output to your current YouTube ingest address. The command below is a template, not a tested command: its paths, encoding settings and destination must be adapted and checked against your files and YouTube’s current encoder guidance.
The concat demuxer does not scan a folder or choose a useful order for you. It reads the files you name, one after another; a reliable setup starts with a deliberate playlist, compatible inputs, and a private test in Live Control Room before you rely on it for a long broadcast.
Prepare a playlist text file
Create a plain-text file, often named playlist.txt, with one file directive for each clip. Put the entries in the order viewers should see them. This is the playlist: adding another file to the folder does not add it to the broadcast unless you also add a line to the text file.
For example, if the clips sit beside the playlist file, its contents could be:
file 'video-01.mp4'
file 'video-02.mp4'
file 'video-03.mp4'
Save the file as plain text rather than a word-processing document, and check that its extension is actually .txt. The FFmpeg concat demuxer documentation describes this script format and the demuxer’s other directives. It reads the listed files in sequence and presents their packets as a continuous input. That is not the same as a visual crossfade: a cut, pause, or audio change can still be noticeable at a boundary.
It is worth keeping a short test playlist separate from the long-running one. Use a few representative clips, including the file with the most unusual picture or audio properties, to expose compatibility problems before the full sequence is involved. If your goal is a playlist-based channel rather than a command-line workflow, see this guide to streaming a video playlist on YouTube in India.
Set paths and playback order
The file paths in the playlist are interpreted by FFmpeg when it opens the playlist. A relative path such as video-01.mp4 is convenient when you run FFmpeg from the directory containing both the playlist and clips. If you run the command from another directory, use paths that resolve from that working directory, or choose absolute paths.
You may see -safe 0 in concat examples. It allows broader path forms than the default safe-path behaviour, which can be needed for absolute paths or certain path characters. Only use it with a playlist you control: an untrusted playlist can point FFmpeg at files you did not intend to read. If relative paths work for your layout, leaving the option out is simpler. If you use it, make sure the playlist itself is not writable by someone else.
Use a consistent quoting style in the text file and check the exact path spelling, including spaces and capitalisation where the operating system distinguishes them. A line naming Video 01.mp4 does not necessarily refer to video 01.mp4. Avoid relying on a wildcard such as *.mp4: the concat demuxer takes an explicit script, not an instruction to sort every matching file in a directory. Explicit entries make playback order visible and repeatable.
Before sending a long playlist, open every entry and verify that it is the intended clip. A missing file can stop the input from being read, while an accidental duplicate may be harder to notice during an overnight run. If files are moved, update the playlist and test it again. For another view of how a prerecorded stream depends on local playback and power, read what happens to a YouTube VOD stream during Indian power cuts.
Build the concat input
The basic input form is -f concat -i playlist.txt. The -f concat option tells FFmpeg which demuxer to use; -i identifies the playlist input. Input options apply to the input that follows them, so keep options such as real-time pacing and looping before -i playlist.txt in a command template.
For paths needing the relaxed safe-path mode, the input portion can be written as:
-re -stream_loop -1 -f concat -safe 0 -i playlist.txt
This expresses the intended mechanics: read the playlist at the file’s native rate, repeat the input, and open it as a concat script. It is not a promise that any collection of files will behave as a single suitable live input. FFmpeg’s concat demuxer expects the inputs to have matching streams, codecs, and time bases. A set of MP4 files can still differ in those details even when they share a filename extension.
For a compatible set, stream copy (-c copy) avoids decoding and re-encoding. It can be less demanding on the computer and does not introduce a new encode generation, but it cannot convert a source codec or repair incompatible stream layouts. Re-encoding can produce a common output format from varied inputs, at the cost of processor work and another lossy encode if the output codec is lossy. If clips are mixed, test a representative sequence and inspect the output; do not assume copy mode will suit an arbitrary folder. The separate guide to streaming MP4 files with FFmpeg without re-encoding covers the narrower case where copy is appropriate.
Loop the sequence for continuous playback
-stream_loop -1 asks FFmpeg to loop the input indefinitely. Here, the input is the concat playlist, so after the last listed file FFmpeg starts the sequence again. -re reads the input at its native rate rather than consuming a local file as fast as the machine can process it. These are input options in the command pattern; they do not by themselves make a stream stable, repair a source file, or guarantee that YouTube will keep a broadcast active.
The loop boundary deserves its own test. Watch the transition from the final clip back to the first, and listen for abrupt changes in loudness, silence, or mismatched audio. The demuxer’s timestamp handling is not an editing tool, and it does not create a seamless join. If timing drifts or a transition is unexpectedly rough, first check that the source files’ duration metadata is sensible and that their streams are compatible. FFmpeg provides a duration directive for special cases where a duration needs correction, but it is better treated as an advanced adjustment than a routine line to add without diagnosis.
For a real 24/7 channel, also decide what should happen if FFmpeg exits, the computer sleeps, or the network drops. A looping input only repeats while the process continues to run. A guide about automatically restarting a YouTube bhajan stream after disconnection is relevant if recovery after a process or connection failure is part of your operating plan.
Configure YouTube Live output
Create or open the live event in YouTube Live Control Room and use the encoder settings shown there. The ingest URL and stream key are event configuration details; copy the current values rather than guessing a format from an old command. YouTube’s encoder settings and bitrates guidance recommends RTMPS, its secure extension of RTMP. Use the exact RTMPS endpoint supplied for your event and do not place a real key in a public example, shared script, screenshot, or support message. If a key is exposed, follow YouTube’s guidance to reset it.
Output container and codec options in FFmpeg must suit the ingest requirements. The illustrative command below uses H.264 video, AAC audio, and FLV output, but the bitrate, resolution, frame rate, preset, and keyframe interval are editable inputs, not universal settings. YouTube’s current guidance should be checked when you publish or revisit a stream. As a concrete reference, its table lists H.264 1080p30 at a 5 Mbps minimum and 14 Mbps recommended, and 720p30 at a 3 Mbps minimum and 8 Mbps recommended. These are platform table values, not evidence that a particular internet connection can sustain them.
YouTube currently recommends a two-second keyframe frequency and says not to exceed four seconds. The sample -g 60 below corresponds to two seconds only at 30 frames per second; if you choose another frame rate, calculate a GOP value that yields approximately two seconds. YouTube’s guidance also describes CBR and supports up to 60 fps in the listed encoder settings. Match the selected output to the event, the source material, the current platform table, and measured upload capacity. Leave headroom for normal network variation rather than setting an output rate that consumes every bit of available upload bandwidth.
The command is a template, not a tested recipe:
ffmpeg -re -stream_loop -1 -f concat -safe 0 -i playlist.txt \\
-c:v libx264 -preset veryfast -tune zerolatency \\
-b:v 4500k -maxrate 4500k -bufsize 9000k -g 60 \\
-c:a aac -b:a 128k -f flv \\
'rtmps://CURRENT_INGEST_URL/CURRENT_STREAM_KEY'
Replace playlist.txt with the actual path, and replace the destination placeholder with the current URL and key from Live Control Room. The sample encode values are illustrative placeholders, not recommendations for every resolution or frame rate. In particular, the 4.5 Mbps target should not be treated as YouTube’s stated recommendation for any arbitrary output. Choose an appropriate value from the current table and your measured connection. Keep the credentials private; shell history, process listings, and logs may expose command arguments depending on how you launch and record the process.
Run FFmpeg and inspect the result
Before relying on the command, run it with a short representative playlist and an event that is not yet public. Watch the preview and inspect stream health in Live Control Room. YouTube’s encoder guidance recommends testing with audio and motion similar to the intended event and monitoring health messages. That matters for a still devotional image with music just as it does for clips with movement: a stream can appear connected while audio, cadence, or image quality is unsuitable.
FFmpeg’s console output can help locate an input or encoding error, but do not treat a clean-looking log as proof that viewers see the right result. Confirm that the first clip begins, later clips appear in the expected order, the playlist returns to the first clip, and the audio continues as intended. Check that the stream key is the one associated with the event and that the event receives the signal before making it public. This is also a good point to test a YouTube RTMP stream key before a 24/7 broadcast.
If you see a missing-file error, check the working directory and each playlist path. If FFmpeg reports stream or timestamp problems at a boundary, compare the source stream layouts and duration metadata rather than changing several output settings at once. If encoding cannot keep up, simplify the output or use compatible sources for stream copy, then test again. A successful local preview is useful evidence about this run, but it is not an uninterrupted-stream guarantee; the computer, power, network, and YouTube ingest can still fail later.
For a computer-hosted workflow, include practical checks in the run plan: prevent sleep, keep the playlist files in place, protect the stream key, and know how to recognise a stopped process or an unhealthy ingest. If the computer is also the only connection to the stream, a local power interruption ends that path. Decide in advance whether a person will restart it or whether your operating arrangement includes a suitable recovery mechanism.
Decide whether this command fits your channel
This method fits when you already have local clips, can keep a computer and connection available, and want explicit control over sequence and encoding. It also makes the workflow inspectable: the playlist is a readable record of playback order, and the command exposes the destination and output choices. The trade-off is that you own file compatibility, process supervision, key handling, and recovery when the machine or connection stops.
If your clips have mixed codecs or time bases, preprocess them to a consistent format or test a re-encode path before committing to the full playlist. If all streams are compatible with each other and with the output container, stream copy may be a simpler load on the computer. If you want to upload the file once and avoid leaving your own computer running to keep a prerecorded broadcast going, StreamNeo addresses that specific operating burden by turning an uploaded video into a YouTube live stream that can run with your computer switched off.
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 the concat demuxer automatically play every video in a folder?
No. It reads the explicit file entries in your playlist text file. You choose the order and add or remove entries yourself; a wildcard or a new file in the folder does not update the playlist automatically.
Can I use -c copy for every MP4 playlist?
No. MP4 is a container, and files with that extension may contain different codecs, stream layouts, or time bases. Copy mode is suitable only when the inputs are compatible with one another and with the output; otherwise, test and consider normalising or re-encoding.
Why include both -re and -stream_loop -1?
-stream_loop -1 repeats the playlist input indefinitely, while -re paces reading at the input’s native rate for a live output. Neither option restarts FFmpeg after it exits or prevents an internet, power, or ingest failure.
Where do I find the correct YouTube URL and stream key?
Use the encoder settings in the current event in YouTube Live Control Room. Do not use a key copied from an unrelated event or publish it in a script or screenshot, and reset it if it is compromised.