To shuffle local videos in a continuing YouTube Live stream, first put the filenames in a randomized order, write that order as an FFmpeg concat script, then repeat the resulting input and send its encoded output to YouTube. These are separate steps: shuffling chooses the sequence, looping repeats it, and neither operation by itself guarantees an uninterrupted broadcast.
The FFmpeg and YouTube documentation describes the underlying pieces, but not one official, universal command for shuffle, repeat, and stream. Shell syntax, filename handling and loop-option placement can vary with your system and FFmpeg release. Treat any command example as something to test locally, not as a promise that it works unchanged everywhere.
How a shuffled playlist reaches YouTube Live
The pipeline has three parts. A shell or small script enumerates the files and randomizes their order. It writes the paths to a text file in FFmpeg’s concat-demuxer format. FFmpeg reads that file as one virtual input, encodes or copies the media as appropriate, then sends the output to the ingest address shown in YouTube Live Control Room.
Shuffling happens when you create the file list; the concat demuxer does not randomly select files. If you generate a list once and then repeat its input, the same shuffled sequence plays again. If you want a different sequence after a restart, generate a fresh list before starting again. Neither approach means each replay is guaranteed to have a different order.
The FFmpeg documentation covers the concat demuxer and its script format, as well as input and output option behaviour. YouTube separately documents its live encoder settings and stream-key setup. Read the current pages alongside your installed FFmpeg help: the docs may describe a newer release than the one on your computer.
If you are deciding whether a playlist-based broadcast suits your channel, the practical considerations in this guide to preparing a continuous-stream video playlist also apply. FFmpeg gives you control over the file order, but it does not remove the need to check content rights, channel settings or the stream’s status in YouTube.
Prepare and validate the video files
Start with a dedicated folder containing only the clips you mean to broadcast. Make a separate inventory of the exact filenames, inspect them for missing or damaged files, and check that each clip has the audio and picture you expect. This reduces the chance that a broad file search accidentally includes an old export, a temporary file or a clip that should not be on the channel.
The concat demuxer expects the files to have matching stream properties. FFmpeg’s documentation says that the files must have the same streams, including the same codecs and time bases. In practice, also check that picture dimensions, frame rate, pixel format and audio properties are suitable for a consistent output. A playlist assembled from unrelated exports can produce errors or visible and audible glitches at transitions.
There are two broad approaches. Stream copy, often configured with -c copy, avoids decoding and re-encoding the media, but it does not repair incompatibilities. It is only a sensible choice after you have confirmed that the clips can be joined and that their existing encoding is acceptable for your output. Re-encoding can make the clips more consistent, but it takes processing capacity and introduces another conversion step to configure and test.
| Approach | When it can fit | Trade-off |
|---|---|---|
| Stream copy | Clips already have compatible streams and acceptable encoding | Less processing, but mismatches remain mismatches |
| Re-encode or normalise first | Clips differ in properties or need a common output format | More processing and preparation, with control over the resulting format |
Do not assume that a command which succeeds on one transition proves the entire library is compatible. Check several transitions, including clips with different durations or audio characteristics. If you need a broader media-preparation workflow, the playlist preparation guide offers useful context; for a mixed collection in OBS, see the separate notes on colour range for mixed video files.
Keep a clean source library and work on copies when you normalise or re-encode. An external SSD can be a convenient place for a large local collection if your computer is short of storage; it is optional, and it does not resolve incompatible streams. Confirm that the drive stays mounted and that the account running FFmpeg can read its files.
Generate a randomized concat script
The first output of your shuffle step should be a stable, inspectable list: one intended file per entry, in the order you want this run to use. You can randomize an inventory with a shell utility or a small script, but the exact syntax depends on the operating system and shell. Do not assume that a command found for Linux will work in PowerShell or macOS unchanged.
For repeatability while you are testing, save the randomized list rather than regenerating it every time you launch FFmpeg. That gives you a known order to inspect and makes it easier to reproduce a transition problem. Once the list is checked, you can decide whether a restart should reuse that order or produce a new one. Keep a copy of the script alongside the inventory so that you know which files were included in a particular test.
The list is not just a plain list of filenames. FFmpeg’s concat demuxer reads a script with directives such as file followed by a path. A schematic entry looks like this:
file 'clip-one.mp4'
file 'clip-two.mp4'
This illustrates the format, not a ready-to-run playlist. Your real paths and quoting need to be valid for the machine that runs FFmpeg. Paths relative to the concat script’s working context can be easier to maintain than machine-specific absolute paths, but verify how the installed FFmpeg resolves them. If a path contains a quote, backslash, newline or other special character, a simple string substitution can produce a malformed script. Use a script writer that escapes values for concat syntax rather than assuming shell quoting and concat quoting are the same thing.
Keep the shuffle operation and the concat-file writer distinct in your reasoning. The shuffle changes order; the writer serialises that order in a format FFmpeg understands. After writing the script, read it back and confirm that it contains every intended file exactly once, with no unexpected entries. This simple check catches errors before the stream is live.
If you are building a devotional or music channel, editorial order may matter as much as random order. A fully shuffled sequence can place a quiet meditation track after a loud announcement or split a themed block. A prepared playlist and a documented rotation policy, such as the one discussed in this guide to a rotating Indian music stream, can help you decide whether to shuffle all files or only within planned groups.
Check concat demuxer formatting
FFmpeg’s concat script format is not the same as a shell command and is not a CSV file. Each file directive names an input path. The demuxer also recognises other directives, including duration-related entries, but do not add them casually: inaccurate duration information can contribute to timestamp problems or artifacts. Start with the basic file entries unless you have a clear reason to use additional directives and have checked them against the current documentation.
Use the official concat documentation to confirm syntax for your release. The documentation warns that all files need the same streams, including codecs and time bases. If you have different source formats, normalise them to compatible streams before concatenation rather than expecting the demuxer or -c copy to fix them on the fly.
Check these details before a long run:
- The script is saved as plain text in a format your FFmpeg build can read.
- Every path is spelled correctly and is accessible to the account running FFmpeg.
- Special characters in paths are represented according to concat-script rules.
- The listed files have compatible streams and play correctly at transitions.
- Any duration directives are accurate and intentionally included.
If FFmpeg reports that it cannot open a file, first distinguish a path problem from a formatting problem. A file may exist in your desktop session but not be visible to a scheduled task or service account. If the playlist opens but transitions are wrong, inspect the media compatibility and timestamps rather than changing shuffle logic.
Configure repeat behaviour for the input
Randomisation and repetition solve different problems. A shuffle step produces one order; repeat behaviour tells FFmpeg whether to read the concat input again. To replay one shuffled order, retain the generated script and configure the concat input to repeat. To get another shuffled order after a restart, regenerate the script before launching a new process. That choice is editorial, not a behaviour that FFmpeg decides for you.
FFmpeg options apply to the next input or output, so placement matters. An input-loop option placed in the wrong part of a command may not control the concat input you intended. The exact option and its accepted placement should be verified using documentation and ffmpeg -h for the installed build; do not copy a loop flag from an unrelated example and assume it will behave the same in every version.
A useful test is to create a tiny playlist of a few short clips, run it locally, and observe what happens after the last entry. Check whether it returns to the beginning, whether audio and video remain aligned, and what FFmpeg prints when the input repeats. This is more informative than starting with a full library and waiting until later to discover that the loop behaviour differs from your expectation.
A looping input is not a process supervisor. If FFmpeg exits because of a file error, host restart or other failure, the input loop does not relaunch the program. Likewise, a network interruption is not proof that the broadcast will resume on its own. The basic playlist command does not establish a reconnection or restart policy; test and arrange process supervision separately if the channel must keep running unattended.
For a small channel, that distinction can be important overnight. A computer that sleeps, loses power or changes network connection can stop the broadcast even when the playlist itself is valid. The discussion of Windows Connected Standby and OBS disconnects is relevant if your planned host is a Windows machine, though it does not replace testing your FFmpeg process and operating-system settings.
Set YouTube Live output and stream key
Create or select the stream in YouTube Live Control Room and copy the current ingest address and stream key from there. Configure FFmpeg’s output to use the address and key in the format required by the chosen protocol. Keep the key private: treat it as a password, avoid putting it in screenshots or public logs, and rotate it in YouTube if you believe it has been exposed. YouTube supports reusable stream keys, but use the key shown for the intended stream configuration.
YouTube documents RTMP and RTMPS workflows and recommends the encrypted RTMPS variant where available. Prefer RTMPS for the documented workflow when your FFmpeg build and network support it. Do not infer that a particular URL structure from an old command remains current; copy the current address from Live Control Room and follow YouTube’s instructions.
The encoder settings should match your actual output. YouTube’s current guidance lists supported video and audio codecs and recommends constant bitrate. It recommends a two-second keyframe frequency and says not to exceed four seconds. For H.264, its table gives examples of 14 Mbps for 1080p at 30 frames per second and 8 Mbps for 720p at 30 frames per second. These are examples, not universal settings: select the current row for your codec, resolution and frame rate, and verify the table before publishing because YouTube may update it.
Also compare the chosen bitrate with the upload capacity available where the stream runs. A high-resolution output consumes more bandwidth and may be a poor fit for an unreliable connection. If your audience mainly listens to devotional music or study ambience, a lower output resolution may be a practical choice, but choose its bitrate from YouTube’s current recommendations rather than guessing. For a channel that depends on a stable music rotation, the meditation-stream setup guide provides additional planning context.
In the FFmpeg command, keep input options before the input they affect and output options in the appropriate position for the output. Protect the stream key when storing or launching that command: a command history or process listing may expose credentials, depending on your system. Use a method appropriate to your environment, and avoid sharing unredacted logs. The output URL and the stream key are credentials and configuration, not content to publish in the concat file.
Test the command on the target system
Test on the actual computer, operating system, shell and FFmpeg release you intend to use. The official docs explain the building blocks, but no source gives a universal end-to-end shuffle-and-repeat command. Shell-specific randomisation, escaping rules and option placement are implementation details. Confirm the installed version with ffmpeg -version, then inspect its help and test a short playlist before using the real stream key.
A staged check keeps failures easier to diagnose. First verify that FFmpeg can read the concat script and play the files locally. Next test a short run with the intended output encoding but without broadcasting, where possible. Finally, create a private or unlisted test in Live Control Room and confirm that YouTube receives picture and sound, the keyframe behaviour is acceptable, and the stream remains stable through a playlist transition. Check the live preview and status in YouTube rather than treating a successful local command launch as proof of a healthy broadcast.
Record the exact command structure, FFmpeg version, script path and relevant encoder settings, but redact the stream key from notes and logs. If a test fails, change one variable at a time: path and script syntax first, then media compatibility, then loop placement, then output configuration. This avoids masking a malformed list with unrelated encoder changes.
Before you rely on the stream overnight, decide what should happen after a process exit or network loss. That requires a separate restart and monitoring plan; the concat loop alone does not handle it. StreamNeo can remove the need to leave your own computer running by taking an uploaded video and running it as a 24/7 YouTube live stream, but it is YouTube-only and does not replace checking your content, channel or broadcast in YouTube.
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
How do I randomise the playlist?
Randomise the file inventory before writing the concat script. FFmpeg’s concat demuxer reads the order you give it; it does not shuffle the entries itself. Save and inspect the script so you can verify which order will play.
How do I keep the shuffled playlist repeating?
Configure the concat input to repeat, and confirm the relevant option and placement against your installed FFmpeg version. The input loop repeats the same list; it does not automatically create a new random order each time. Test the behaviour on a short playlist before relying on it.
Why do clips fail or glitch at transitions?
The concat demuxer expects compatible streams, including codecs and time bases, and incorrect duration information can also cause artifacts. Stream copy does not repair mismatches. Inspect the files and normalise or re-encode them when needed.
What happens if FFmpeg stops or the network drops?
A looping input does not restart an FFmpeg process that has exited, and the basic command does not guarantee recovery from a network interruption. Arrange and test a separate restart and monitoring approach, and check YouTube Live Control Room for the stream’s current status.