Skip to content
streamneo.
Setup Guides11 min read

How to Make an FFmpeg YouTube Stream Play Videos in Filename Order

Build and check an FFmpeg concat playlist so YouTube videos play in the filename order you choose.

sn.
StreamNeoPublished 4 October 2026
Worth sharing?

FFmpeg plays videos in the order they appear in its concat playlist; it does not sort a folder by filename for you. To stream in alphabetical filename order, create or generate a playlist whose entries are already sorted the way you want them to play.

The reliable workflow is to decide what “alphabetical” means for your filenames, inspect the resulting playlist, and then test the files together before sending them to YouTube. This guide covers the playlist and command pattern, plus the compatibility checks that matter when the stream runs for hours.

Why FFmpeg does not sort filenames automatically

The concat demuxer reads a text file containing directives, including one file directive for each input. It processes those files in the listed order, one after another, as described in the FFmpeg concat documentation. It does not receive a request to inspect a directory and decide what “filename order” should mean.

That distinction matters because a folder listing is not a dependable playlist. Directory enumeration can vary by operating system, file manager, shell, or the way files were copied. Even when a tool appears to show an alphabetical listing, that is a display choice rather than a playback instruction FFmpeg can infer from the directory.

Treat the playlist as the source of truth. If the sequence should be aarti-01.mp4, then aarti-02.mp4, then aarti-10.mp4, those paths need to appear in that order in the playlist. The stream will follow that explicit sequence, subject to the files being readable and compatible for concatenation.

This also makes later changes easier to reason about. If the third video is wrong, inspect the third entry rather than wondering what order the folder happened to produce. A small, deliberate playlist is particularly useful for devotional sets, study blocks, or local news loops where a particular item should precede another.

Create a plain-text concat playlist

Make a text file in a location you can find again, for example playlist.txt. Add one line per input video, using the file directive and a path to the video. A basic playlist might be:

ffconcat version 1.0
file 'clip-001.mp4'
file 'clip-002.mp4'
file 'clip-010.mp4'

The paths above are relative to the directory from which the playlist is interpreted. For a first test, keep the playlist and its videos together, then run FFmpeg from that directory. You can instead use absolute paths, which are often clearer in an unattended job, but they must match the machine and directory where FFmpeg runs.

The first line shown is an optional format marker, not a requirement for every concat input. If you use it and want FFmpeg to recognise the format automatically from the marker, it must be exactly ffconcat version 1.0 at the start of the first line, without a leading space or byte-order mark. If you leave it out, FFmpeg can still be given the concat format explicitly with -f concat, as in the command below.

Save the playlist as plain text, not as a word-processing document. Rich-text editors can introduce formatting characters or change quotation marks. A simple text editor is enough; on a system with a terminal, tools that write plain text are suitable too. Avoid copying typographic “smart quotes” around file paths.

For a playlist that you will reuse, include explicit path names and keep the file near the scripts or notes that explain the stream. This is more maintainable than relying on a wildcard whose expansion order may not match the intended order. If you later add an episode or bhajan, edit the playlist deliberately and check its position before restarting.

Sort entries in the desired filename order

There is no universal answer to what alphabetical order means for every filename. Capital letters, accents, punctuation, spaces, and digits can sort differently depending on the application or locale. Decide on a rule and build the playlist using that rule, then inspect the final entries rather than assuming a directory display and a script will agree.

For names with numbers, zero padding makes ordinary alphabetical sorting easier to predict. clip-001, clip-002, and clip-010 appear in that sequence under a straightforward character-by-character comparison. Names such as clip-1, clip-2, and clip-10 may instead place clip-10 before clip-2, because a character comparison sees the digit 1 before 2; it is not interpreting each suffix as a complete number.

A practical naming scheme for a sequence is to use the same prefix and pad every number to the same width, such as morning-01.mp4, morning-02.mp4, and morning-10.mp4. Do this before building the playlist if you control the filenames. If the files already have mixed names, do not rename them blindly: create the playlist in the desired order and verify every entry against the folder.

On a desktop, you can sort the file list by name and add each full path to the text file, but check the result for numeric sequences and special characters. In a shell or script, use a sort method whose behaviour you understand and write the resulting paths to the playlist. The robust part is not the particular tool; it is that the completed playlist is explicit and reviewed.

If the set changes often, keep the sorting rule consistent and regenerate the playlist before each run. Do not combine an automatically generated, unsorted list with an assumption that FFmpeg will repair its order. For background on maintaining a fixed programme sequence, the guide to replacing a video in a running YouTube playlist discusses a related operational problem: changing items without losing track of the intended order.

Use the concat demuxer with the playlist

A representative command for a compatible set of files has this shape:

ffmpeg -re -f concat -safe 0 -i playlist.txt -c copy -f flv 'YOUTUBE_INGEST_URL/YOUR_STREAM_KEY'

This is a pattern, not a universal command to paste unchanged. Replace the destination with the stream URL and key provided for the intended broadcast in YouTube Live Control Room. Confirm the required output protocol and format for your setup, and choose output and encoding options that fit your inputs and YouTube’s current guidance. YouTube’s encoder set-up instructions explain where to obtain and enter the stream URL and key. Treat the key as a credential; do not publish it in a playlist, screenshot, or public script.

Here, -f concat selects the concat demuxer, and -i playlist.txt tells FFmpeg to read that playlist as input. -safe 0 permits paths that the demuxer would otherwise reject as unsafe; it is commonly used when playlists contain absolute paths. Do not add it without understanding the paths in your file, particularly if a playlist may include entries from an untrusted source.

The -re option reads the file input at its native rate rather than sending it as quickly as the machine can process it. -c copy asks FFmpeg to pass the existing streams through without re-encoding. That can reduce processing work, but it depends on compatible inputs and does not make incompatible files compatible.

A concat demuxer playlist expects the inputs to have matching stream layouts, codecs, and time bases. Files that look alike by extension can still differ in how their audio or video is encoded. Differences in durations or inaccurate duration metadata can also cause gaps or timestamp artefacts. The FFmpeg format documentation describes these constraints; test your actual collection rather than inferring compatibility from filenames.

If the videos do not match, you may need to transcode to a consistent output profile instead of using -c copy. Transcoding takes processing resources and requires you to select suitable video and audio settings; those choices depend on the source material and intended output. YouTube’s current live encoder settings give recommendations that vary by codec, resolution, and frame rate. Check that official page before choosing settings rather than treating one command as suitable for every stream.

The FFmpeg command is only one part of an always-on setup. It must keep running, retain access to every source file, and reconnect or be restarted if it stops. If the main concern is leaving your own computer on overnight, StreamNeo removes that particular task by letting you upload the video and run the YouTube broadcast with your computer switched off; it does not change the need to prepare a correct playlist or use compatible media.

Handle spaces and special characters in paths

A path with spaces needs to be represented so the playlist parser reads it as one path. For example, a relative filename can be quoted:

file 'morning prayer.mp4'

The playlist syntax is not exactly the same as shell quoting. Do not assume that adding shell quotation marks around a path in a command automatically fixes the text inside the playlist. Follow the concat demuxer’s escaping and quoting rules for the characters in your paths, and test a short playlist when names include quotes, backslashes, or other punctuation.

For the least confusing setup, use simple filenames without embedded quote marks or unusual punctuation, and put the files in a folder with a straightforward path. If you cannot rename them, use the documented escaping rules and confirm that FFmpeg opens the intended file. A filename such as episode 04.mp4 is a different path from episode_04.mp4; a small spelling mismatch can stop the run before streaming begins.

Relative paths make a playlist portable only when its working directory is controlled. If a scheduled process starts in a different directory, file 'clip-001.mp4' may resolve somewhere other than the folder you expected. Absolute paths avoid that ambiguity on a fixed machine, but they are tied to that machine’s directory layout. Choose one approach, record it, and test from the same context that will run the stream.

-safe 0 is relevant to the demuxer’s path safety checks, not a general-purpose path quoting switch. It does not correct misspellings or malformed playlist syntax. Also avoid placing a stream key in the playlist: the playlist needs source media paths, while the destination belongs in the command or encoder configuration and should be handled privately.

Check the first-line format marker

The line ffconcat version 1.0 can identify the playlist format automatically when it is placed exactly at the beginning of the file. It must be the first line, with no leading blank line, spaces, or byte-order mark. A text editor may add a byte-order mark without making it visible, which can prevent automatic format recognition.

This marker is optional when you explicitly select the demuxer with -f concat. The example command does that, so it does not rely on automatic format detection. Keeping the marker is still useful documentation for a playlist intended to use the ffconcat format, provided the file is saved with the required first-line form.

If FFmpeg reports that it cannot recognise the format, check both pieces: whether the command includes -f concat, and whether a marker you supplied is truly at the start of the file. Removing an accidental blank first line or saving as plain text can be a more direct fix than changing the media files.

Validate order before sending the stream

Read the playlist from top to bottom before using the real YouTube destination. Confirm the first few filenames, the transitions between groups, and the last entry. For numbered clips, pay particular attention to 1, 2, and 10 patterns, where a casual visual scan can miss an unexpected character order. This simple review tests the actual playback instruction rather than the folder’s display order.

Then test the files locally or with a short private/unlisted test stream if appropriate to your channel. Watch or listen through transitions, not only the opening seconds. Check for missing audio, unexpected gaps, frozen pictures, or a file that ends earlier than its stored duration suggests. A successful command start does not prove that every later entry is valid.

If the order is right but the stream has transition problems, inspect the source formats and durations. Direct stream copy is most suitable when the inputs meet the concat demuxer’s compatibility requirements. If they do not, make consistent copies or transcode them to a chosen profile, then test the new set. Avoid changing multiple factors at once; otherwise it is harder to tell whether a correction fixed ordering, compatibility, or the YouTube output configuration.

Keep a known-good playlist version before editing a recurring channel. When you add a new file, update the list, inspect the changed section, and run a local validation again. For workflows involving continuous material, the FFmpeg and GStreamer comparison for 24/7 streaming can help you think through whether a command-line playlist fits your operating approach. If your priority is a low-cost hosted FFmpeg setup, the 720p FFmpeg configuration guide for a VPS in India addresses a different part of the setup: where to run the encoder and what to check there.

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 play files alphabetically by default?

No. The concat demuxer reads files in the order of the file directives in the playlist. Sort or arrange those entries before running FFmpeg if you want alphabetical filename order.

Why did clip-10.mp4 appear before clip-2.mp4?

A character-by-character filename sort can put the digit 1 before 2, so clip-10 may precede clip-2. Use consistently zero-padded names such as clip-02 and clip-10, or manually verify the playlist’s intended sequence.

Is ffconcat version 1.0 required?

No, not in every use. It is an optional marker for automatic format recognition, and when used it must be exactly at the start of the first line; a command that specifies -f concat does not rely on automatic recognition from that marker.

Can I use -c copy with any MP4 files?

No. The concat demuxer expects compatible streams, including matching layouts, codecs, and time bases. If the inputs differ, test them and consider transcoding to a consistent profile rather than assuming stream copy will work.

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 ↗