Skip to content
streamneo.
Setup Guides12 min read

How to Shuffle Videos in an FFmpeg YouTube Live Playlist

Shuffle video files before FFmpeg reads a concat list, then check paths, compatibility and YouTube Live output settings.

sn.
StreamNeoPublished 4 October 2026
Worth sharing?

To shuffle videos in an FFmpeg YouTube Live playlist, randomise the file list before FFmpeg reads it. The concat demuxer plays entries in the order written; it does not shuffle them itself.

That distinction makes the workflow easier to reason about: choose and inspect your files, generate a shuffled concat script, then test playback and ingest. The same script repeats the same order when looped, so a new order on each cycle needs a separate list-generation step.

How shuffle differs from playback order

A playlist has two separate jobs: decide which files are included and decide their sequence. In this workflow, you perform both decisions before starting FFmpeg. A shell utility or a small script changes the sequence, and the concat demuxer follows the resulting list from its first entry to its last.

This is different from a music player’s “shuffle” control, which may choose another track as each one ends. A concat script is a set of instructions on disk. If it says morning.mp4, then chant.mp4, then evening.mp4, FFmpeg reads those entries in that order. Starting the same input again does not make a new permutation.

For a devotional channel, you might want a varied order for a day’s run while keeping a known opening clip. You can keep that opening outside the randomised portion, or generate the order once and review it before going live. If the sequence itself needs to be repeatable for troubleshooting, save the generated list with a date or another clear label. That makes it possible to distinguish an order change from a media or connection problem.

Shuffle only the entries you intend to vary. If some material must always precede other material, divide the programme into fixed and random parts rather than shuffling every file indiscriminately. For example, a station ident can remain first, while a group of ambience videos is randomised after it. The concat demuxer still sees one ordered list; the structure is decided when you assemble that list.

Collect the intended source videos

Start with a dedicated folder containing only the videos you want in this run. Do not collect files by searching a broad downloads folder and assuming every match belongs in the broadcast. An old test export, a silent placeholder, or a partial download can become part of the stream if it is included in the list.

Write down the intended set or inspect the filenames before generating the playlist. Use meaningful filenames where practical: temple-dawn.mp4 is easier to recognise in a list than final2-fixed-new.mp4. If filenames contain spaces or punctuation, keep them; the concat format can represent quoted paths, but the quoting must be handled correctly. Avoid renaming files during a broadcast because the list points to paths, not abstract media items.

For a predictable result, keep the files in one location and use a clear path strategy. Relative paths are convenient if you run FFmpeg from a known working directory and the list is stored alongside the media. Absolute paths are less dependent on the current directory, but they are machine-specific and may require disabling the concat demuxer’s safe-path default. In either case, check that the account running FFmpeg can read the files.

The videos also need to be suitable for concatenation. FFmpeg’s concat documentation describes requirements for matching streams, codecs and time bases; files that differ may fail or produce timestamp issues. Review the media properties before relying on a long unattended run. If your source folder mixes phone recordings, downloaded clips and exports from different editing tools, assume that compatibility needs testing rather than treating the extensions as proof that the files match.

Randomise entries before writing the list

On systems that provide it, shuf can randomise lines or records. It is not available on every system, and a naïve line-based pipeline can break when filenames contain newline characters. A null-delimited collection helps preserve unusual filenames through a shell pipeline, but those raw paths still need conversion into valid concat-script directives. Do not treat the following schematic as a complete, universal filename-escaping solution:

find ./videos -type f -name '*.mp4' -print0 | shuf -z > /tmp/shuffled-paths

The result here is a shuffled collection of paths, not yet a concat-demuxer script. You need a step that converts each path into a file directive with quoting and escaping appropriate to FFmpeg’s script syntax. Test that conversion using representative names from your folder, including spaces or apostrophes if you have them. The exact safe method depends on your shell and scripting language; if a robust conversion is unfamiliar, use a controlled naming convention and a script you understand rather than copying a one-line pipeline that silently mishandles a filename.

Keep the source collection and the final order separate. For example, retain a source inventory for review, generate a new shuffled output file, and inspect the output before replacing the list used for streaming. This makes it easier to notice a missing video or an unexpected duplicate. If the random order is wrong for the channel, regenerate it before going live rather than editing the list by hand in a way that risks breaking its syntax.

If you need to reproduce a particular sequence, preserve the finished concat list rather than relying on a fresh random draw later. A shuffled list is not a record of the randomisation method; it is the actual playback plan. This is useful when checking an incident: you can tell whether an unexpected clip came from the chosen list or from a different process. For other continuous-playback approaches, the guide to playlist formats for a 24/7 YouTube music radio stream explains why format and playback behaviour matter as well as the order.

Format paths for the concat demuxer

A concat-demuxer script uses one file directive for each input. Its broad shape is:

file '/path/to/first.mp4'
file '/path/to/second.mp4'

These lines are examples of the required structure, not a promise that every path can be pasted between single quotes unchanged. FFmpeg has its own quoting and escaping rules for concat scripts. Characters such as a quote or backslash need deliberate handling, and the parser is not simply reading shell syntax. A path that works as a quoted shell argument may still need a different representation in the concat file.

For relative paths, make the relationship between the list and the media folder unambiguous. A list in the project directory might use paths such as videos/first.mp4; that works only when interpreted from the expected location. Before a long stream, run FFmpeg from the same working directory and with the same list location that the production setup will use. If a job scheduler or restart mechanism starts it from another directory, relative paths that worked in a terminal can stop resolving.

Absolute paths can be more explicit, for example /home/channel/videos/first.mp4, but the concat demuxer’s safe-path handling is restrictive by default. The commonly used -safe 0 option allows paths outside that safe subset, including absolute paths. Use it only with a list you trust: it relaxes path checks and should not be used to process an arbitrary concat file from an untrusted source. It does not fix malformed quoting or grant file permissions.

A duration directive can be used where appropriate to override a file’s stored duration, as documented by FFmpeg. That is a specialised correction, not a substitute for checking the media itself. Incorrect duration information can affect timestamps of later entries, so if audio and video drift or the next file appears at an unexpected time, inspect the source durations and the list directives together.

Feed the list to FFmpeg

The input shape for a concat list is -f concat -safe 0 -i list.txt. The demuxer reads the list in written order. A schematic command might be:

ffmpeg -re -f concat -safe 0 -i list.txt [encoding options] -f flv "$YOUTUBE_RTMPS_URL"

This leaves encoding options and the ingest destination as placeholders because they depend on your sources and YouTube’s current guidance. Obtain the stream URL and key from YouTube Live Control Room, and do not put a real key in a shared script, screenshot, article, or public repository. Treat the key as a credential. YouTube’s live encoder settings guidance gives current recommendations for resolution, frame rate, codecs, bitrate and keyframes; select settings for the output you are actually sending rather than copying an isolated bitrate from an example.

You can stream-copy only when the input files have compatible streams and parameters. The concat documentation’s compatibility requirements are important here: matching filenames or the same .mp4 extension does not mean that codecs, stream counts and time bases match. If the clips differ, normalise or re-encode them to a consistent format before concatenating. Re-encoding takes more processing capacity, while stream copy avoids that work but only fits compatible inputs. There is no universal choice independent of the media set and the machine doing the encoding.

For live ingest, YouTube recommends RTMPS in its encoder settings help, and Google’s RTMPS ingestion documentation explains the secure ingest connection. Confirm that your chosen output format and FFmpeg build support the intended settings. Do not assume that an ingest URL, codec option or sample command will be suitable for every account or setup without checking the current official documentation.

A local test should cover more than whether the command starts. Check a representative file transition, audio presence and level, picture dimensions and whether later entries continue to play. Then test the actual YouTube stream as an unlisted or otherwise appropriate test broadcast and watch stream health in Live Control Room. The guide to streaming pre-recorded videos to YouTube Live from a Mac using FFmpeg covers the broader encoder workflow; the shuffled-list step remains external to FFmpeg’s sequential concat playback.

Loop or refresh the playlist deliberately

Looping the concat input repeats the order in the script. If your list has twelve entries in a given sequence, looping it means that sequence starts again; it does not ask the demuxer to choose twelve new positions. This is often exactly what you want for a stable overnight channel, especially when you have reviewed the order and want the same programming pattern to recur.

If you want a different order each cycle, something outside the running concat input has to create and activate a new list. That can be a wrapper or a separate playlist-generation process. Plan how the process will hand over from one list to another, and test the behaviour before relying on it live. Replacing a file while FFmpeg has already opened it may not make the running input adopt the new entries; depending on how the process is arranged, the broadcaster may need to restart or reopen the input.

This is a trade-off between simplicity and variation. One saved order is straightforward to inspect, reproduce and troubleshoot. Re-generating for each cycle adds moving parts and raises questions about timing, handover and recovery if list generation fails. If a transition or short interruption is unacceptable for your programme, do not assume a new list can be swapped invisibly. Test the actual approach with representative media and monitor the resulting stream.

For a fixed loop of worship clips, OBS may be a more familiar production route than maintaining an FFmpeg list; the separate guide on looping worship videos in OBS helps you compare the operating model. If you are running a channel where the computer must stay off, the list-generation work can still be separated from the continuous broadcast: StreamNeo removes the need to keep your own computer running by taking an uploaded video and carrying the YouTube stream continuously, though it does not provide this FFmpeg shuffle workflow or serve platforms other than YouTube.

Check ordering and troubleshoot paths

Before starting the live encoder, open the generated script as plain text and read through its entries. Confirm that each intended file appears once unless repeats are deliberate, that the first and last entries make sense, and that the list contains no temporary or unrelated media. This simple inspection catches many problems that a randomisation command cannot identify, because shuffling only changes order; it does not decide whether the source set is correct.

Run a short local playback or test encode using the exact list and the production working directory. Errors such as “No such file or directory” usually call for checking path spelling, relative-path base, case sensitivity and permissions. If only particular filenames fail, inspect quoting and escaping. If FFmpeg reports an unsafe path, decide whether the list is trusted and whether absolute paths are necessary before considering -safe 0; do not use that option as a blanket fix for a list you did not create or inspect.

If playback stops or timestamps jump around at a boundary, check whether adjacent files actually have compatible streams and time bases. An apparent shuffle problem may instead be a decode error, a duration mismatch, or a media file that is damaged. Try the problem file on its own, compare its stream information with a working file, and consider normalising the set. A test with only one type of clip can miss incompatibility that appears later in the full playlist.

Once the local sequence behaves as intended, test the outbound stream and monitor YouTube’s stream health rather than assuming a successful FFmpeg launch means the live picture and sound are healthy. Keep the key private, and retain the exact list that was used if you need to reproduce the broadcast. For uninterrupted operation, process recovery is a separate concern from shuffle logic; automatic recovery for a 24/7 YouTube stream covers that operational layer without changing what the concat demuxer does.

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 FFmpeg shuffle concat-list entries automatically?

No. The concat demuxer reads entries in the order written in its script. Generate a shuffled order before FFmpeg opens the list if you want varied playback.

Does looping the list create a different order each time?

No. Looping repeats the same list and therefore the same order. A new permutation requires an external step that generates and activates a replacement list, which should be tested for handover behaviour.

Can I use -safe 0 with any concat file?

Use it only when the list is trusted. It allows paths outside the demuxer’s default safe subset, but it does not make untrusted paths safe or correct malformed quoting.

Why do some files fail even though they are all MP4?

The container extension does not establish that the streams, codecs or time bases match. Compare the media properties and, when needed, normalise or re-encode files to compatible output before concatenating.

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 ↗