To loop a folder of MP4 files to YouTube Live, list the files in the order you want in an FFmpeg concat-demuxer manifest, then use -stream_loop -1 before that playlist input. FFmpeg can send the repeating output to YouTube using the ingest URL and stream key shown for your stream in Live Control Room.
The manifest controls order, but it does not make unlike files compatible or guarantee smooth joins. Check the media, choose output settings that fit YouTube’s current guidance, and test privately before you start a public broadcast.
Check the files and decide their order
Start by deciding what viewers should see, rather than relying on the order your computer happens to show files in. Directory listings can be sorted by name, date, or another attribute; none of these necessarily reflects the intended sequence. Write down the sequence first, for example: opening slate, morning programme, music loop, closing card. The playlist will repeat in that order, so the last file will be followed by the first.
Put the files in a dedicated folder and use stable filenames. Names such as 01-opening.mp4, 02-bhajan-set.mp4, and 03-closing.mp4 are easier to review than names with ambiguous dates or duplicate suffixes. You do not have to rename files if the manifest lists their paths explicitly, but clear names reduce the chance of putting the wrong version in the list. Avoid moving or renaming files after creating the manifest unless you update it too.
Before concatenating, inspect the media. Files that look alike because they all end in .mp4 may still differ in video codec, dimensions, frame rate, audio layout, or time base. The FFmpeg concat demuxer joins encoded packets and expects the files to have matching streams. Differences can cause errors, gaps, timestamp problems, or visible or audible artefacts at a boundary. It is not a general-purpose conversion step.
For a quick inspection, use a media-information tool or FFmpeg’s ffprobe to compare each file’s streams. Check that video and audio are present as expected, that the codecs and stream layouts match, and that durations are plausible. Listen to the start and end of each file as well: a technically readable file may still have an unintended silence or abrupt cut. If you are making a devotional or study channel, confirm that the soundtrack does not disappear in one item simply because its audio stream differs from the others.
If files are not compatible, decide whether to normalise or re-encode them before building the final playlist. That takes extra processing and may alter the source, but it gives you a more consistent set of inputs. An alternative is an FFmpeg filter workflow that decodes and joins media before encoding; it can handle a broader range of differences, but uses a different command structure and also requires careful testing. The packet-concat and re-encode trade-offs are about your files and available computing capacity, not a universal performance advantage. For a long-running feed, also check audio continuity and timestamps; the guide to diagnosing audio drift in a long-running FFmpeg stream covers a related fault that may not be obvious in a short test.
Create the concat-demuxer playlist file
Create a plain-text file named playlist.txt in the folder containing the videos. Save it as UTF-8 text. Put the following header on the very first line, with no blank line or other text before it, then add one file directive for each video:
ffconcat version 1.0
file '01-opening.mp4'
file '02-bhajan-set.mp4'
file '03-closing.mp4'
The listed order is playback order. Use paths relative to the folder from which FFmpeg will run, or provide full paths. Keeping the manifest next to the media and using relative names makes it easier to move the project as a unit, but only if you run FFmpeg from the expected folder. If you run it elsewhere, make the paths unambiguous.
The ffconcat version 1.0 header has to match exactly for automatic format recognition. The FFmpeg concat demuxer documentation describes the manifest syntax and requirements. Paths containing spaces are ordinarily enclosed in single quotes as shown. A filename containing a single quote or other special characters needs escaping according to FFmpeg’s syntax; do not assume that quoting every unusual path will work. If you can, use simple filenames without quotes, backslashes, or other punctuation that needs special handling.
Review the manifest against the folder before starting. Check that each entry points to an existing file, that there are no accidental duplicates, and that the first and last entries produce a sensible loop boundary. The header is not a shell command: it belongs in the text file, not on a command line by itself.
The -safe 0 option in the example below permits paths that the concat demuxer would otherwise reject under its safe-path rules. Use it only when you control the playlist and its file paths. A manifest that refers to unfamiliar or untrusted paths should not be treated as harmless input. If your filenames are simple and paths meet FFmpeg’s safe rules, you may not need this option.
Loop the playlist with FFmpeg
The key option is -stream_loop -1. It tells FFmpeg to repeat the input that follows indefinitely. Place it before the concat input so it applies to the playlist rather than to an output or an unrelated input. The -re option reads local media at approximately its native rate instead of allowing FFmpeg to process it as quickly as the machine can. That is useful when turning stored files into a live feed.
A representative command is:
ffmpeg -re -stream_loop -1 -f concat -safe 0 -i playlist.txt \
-c:v libx264 -preset veryfast -pix_fmt yuv420p \
-r 30 -g 60 -keyint_min 60 -sc_threshold 0 \
-c:a aac -b:a 128k -ar 44100 \
-f flv "YOUR_YOUTUBE_INGEST_DESTINATION"
This is an example shape, not a universal command that has been tested against every MP4, FFmpeg build, or YouTube account. The command re-encodes video and audio to the named codecs, so the installed FFmpeg build must include the requested encoders. Check with ffmpeg -encoders if an encoder is unavailable. The output container, protocol and selected codecs must also agree with the current ingest workflow for your channel.
The example uses a 30-frame-per-second output and a 60-frame GOP, which corresponds to a two-second keyframe interval at that frame rate. Do not copy those values without checking the output mode you actually intend to send. If you choose a different frame rate, revisit the GOP values as well. If the source clips have different frame rates or sizes, consistent output settings may require scaling or other filters; the command above does not add a scaling filter. Test the picture rather than assuming that the encoder settings will fit every source.
On Windows, line continuation syntax differs from the backslash shown for a Unix-like shell. You can put the command on one line or adapt its continuations for the shell you use. Keep the sequence of FFmpeg options intact: input options go before the input they affect, while output encoding and destination options go after the input. If you maintain a changing library rather than a fixed playlist, see whether a video can be added to a VPS playlist without stopping a stream; a static concat manifest does not automatically discover new files.
Choose ingest and encoding settings
Use the stream’s own ingest details from YouTube Live Control Room. YouTube provides a server URL and stream key for the encoder connection. Do not copy an ingest destination from an unrelated tutorial: the values in your Live Control Room are the ones to use. Treat the stream key like a password. Do not put a real key into a published script, screenshot, shared log, or article comment. If it is exposed, replace or reset it through YouTube’s controls.
YouTube Help recommends RTMPS, a secure extension of RTMP. Its live encoder settings guidance describes supported protocols, codecs and recommended settings. Confirm the current guidance and the options exposed by your FFmpeg build before choosing a protocol and codec. A protocol label alone does not ensure that the output container or codecs are suitable.
For H.264, YouTube’s current guidance recommends a two-second keyframe interval and says not to exceed four seconds. It also gives bitrate recommendations that depend on the resolution and frame rate. For example, its guidance lists 10 Mbps for 1080p at 30 fps and 12 Mbps for 1080p at 60 fps. Those are examples for those modes, not a default for every stream. Check the live encoder settings page for the codec and video mode you select, and choose a bitrate your upload connection can sustain consistently.
A bitrate that is too high for a variable connection may lead to dropped frames or unstable ingest; a lower bitrate may be more appropriate for a smaller output resolution. Do not treat the highest available value as automatically best. Test the full path from the computer or hosting environment to YouTube at the intended settings. Audio needs attention too: make sure the output includes the expected track and that its codec and bitrate suit the selected ingest configuration.
The example command re-encodes as H.264 video and AAC audio and emits FLV output, but your FFmpeg build and YouTube’s current requirements govern whether that exact combination is usable. If you change to another supported codec, make sure the encoder is available and use the matching recommendations for bitrate and keyframes. The FFmpeg formats and codec documentation is useful when checking format options; YouTube’s current page remains the authority for its ingest recommendations.
Send the output to YouTube Live
In YouTube Studio, open Live Control Room and create or select the stream you intend to use. Find the encoder connection details, then use the server URL and key supplied there in the output destination. In the command example, replace YOUR_YOUTUBE_INGEST_DESTINATION with the exact destination format specified for your stream. Do not paste a real key into a public guide, shared shell history, or a screenshot.
If you store the command in a script for repeated use, restrict access to the script and avoid recording the key in places other people can read. A key grants access to the corresponding encoder feed, so handle it as a credential. YouTube’s instructions for creating a live stream with an encoder walk through the connection process. Stream selection, latency and start/stop behaviour are configured in YouTube, not inferred from the filenames in your playlist.
When FFmpeg starts, read its output rather than closing the window immediately. It should report that it has opened the playlist and begun writing encoded output. A successful local process does not by itself prove that YouTube is receiving a healthy picture and sound. If the command exits, preserve the relevant error message while removing any key or private destination details before sharing it for help.
If you want the playlist to run when your personal computer is off, you need a separate always-on arrangement and a plan for process supervision, network interruptions, and monitoring. A cloud-hosted stream can avoid keeping a home computer switched on, but it does not remove the need to verify the playlist and check the channel. For broader trade-offs, read how to choose a platform for an always-on educational stream. StreamNeo removes the need to leave your own computer running by taking an uploaded video and the channel’s stream key for a cloud-run YouTube broadcast, which is useful when managing a local FFmpeg process overnight is the specific burden.
Start and verify the broadcast
Test with a private or unlisted stream before scheduling a public event. Start FFmpeg, then check the Live Control Room preview. Confirm that the intended first file appears, the picture is not cropped or unexpectedly scaled, and the audio is present at a sensible level. Watch a transition between two files and, if practical, the point where the final file returns to the first. A short test can reveal problems, but it cannot prove that a long playlist will run without interruption.
Check YouTube’s stream health information while the encoder is connected. Look for ingest warnings, dropped frames, or other reported problems, and compare them with FFmpeg’s output and the computer’s network conditions. YouTube’s guidance on live streaming settings and stream health recommends testing and monitoring the stream. Allow time to resolve issues before the audience is expected; do not use a public event as the first test of a new manifest or command.
Confirm what action starts and ends the broadcast. YouTube’s Live Control Room settings can affect whether the event starts or stops automatically when the encoder connects or disconnects. For unattended operation, decide how you will notice a stopped FFmpeg process, a lost network connection, a full disk, or a stream that is connected but not showing the intended content. A loop option repeats media; it is not a process supervisor and does not guarantee uninterrupted service.
YouTube says encoder streams under 12 hours are automatically archived in its setup guidance. If you need an archive or intend a longer-running event, check the current official guidance for the planned duration and confirm how it applies to your event. Do not assume that a continuous loop will create one uninterrupted archive or that past behaviour will match current platform rules.
Troubleshoot playlist and ingest errors
If FFmpeg reports that it cannot open a file, check the path from the directory where the command is running. Confirm spelling, extension, permissions, and whether the path uses characters that need escaping. Open the text file in a plain-text editor and verify that the header is the first line, each file directive is on its own line, and every referenced file exists. If using relative paths, compare them with FFmpeg’s working directory rather than the manifest’s location by assumption.
If playback starts but fails at a boundary, compare the streams in the neighbouring files. The concat demuxer’s matching-stream and timestamp assumptions may be violated, or duration metadata may be inaccurate. Test the two files as a pair, then normalise or re-encode the outliers if needed. Changing -stream_loop will not fix incompatible media; it only determines how often the input repeats.
If the output runs too quickly, check that -re is before the input and that it applies to the playlist. If it is out of sync or shows timestamp warnings, investigate source durations, time bases and stream differences. Avoid adding arbitrary timestamp options without understanding the cause, since a change that masks one warning can create a different boundary problem.
If YouTube does not receive the feed, verify that the destination uses the exact server URL and key from the selected Live Control Room stream, that the key has not been revoked, and that the network can reach the chosen endpoint. Check FFmpeg’s protocol and encoder availability, the output format, and whether the selected codecs match current YouTube guidance. Keep private connection details out of any diagnostic report. If YouTube shows a healthy ingest but the preview is wrong, investigate the source playlist and encoding settings rather than repeatedly changing the key.
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 loop each MP4 or the whole playlist?
When placed before the concat input, it repeats that input, which is the playlist, rather than just the first MP4. The manifest determines the order on every pass. Check the placement of the option if FFmpeg is not repeating the sequence you expect.
Can I use MP4 files with different codecs or resolutions?
The concat demuxer expects matching streams, codecs and time bases, so files that differ may fail or produce problems at their joins. You can normalise or re-encode them to a consistent format, or use a decode-and-encode filter workflow, then test the result. An .mp4 extension alone does not establish compatibility.
Where do I get the YouTube server URL and stream key?
Get both from the relevant stream in YouTube Studio’s Live Control Room. Use the exact details supplied there rather than a URL copied from an example, and protect the key as a credential. If it is exposed, replace or reset it through YouTube.
Can this command guarantee a continuous 24/7 broadcast?
No. The loop repeats the playlist while FFmpeg is running, but the process, host, network, source files and YouTube ingest can still encounter problems. Test the setup and arrange monitoring and recovery appropriate to how long the channel needs to run.