Skip to content
streamneo.
Setup Guides13 min read

How to Use FFmpeg to Preserve Video Order in a Continuous YouTube Stream

Use FFmpeg’s concat demuxer to keep files in sequence, prepare compatible media, loop the playlist and test YouTube Live output.

sn.
StreamNeoPublished 5 October 2026
Worth sharing?

To preserve video order in a continuous YouTube stream, put each file in the intended sequence in an FFmpeg concat-demuxer list, check that the files are compatible, then loop that input and send a correctly encoded output to YouTube. The list controls sequence, but it does not by itself make unlike files join cleanly or guarantee uninterrupted transitions.

The reliable workflow is to check the source files, make the order explicit, confirm how FFmpeg is reading them, and test representative boundaries before relying on a long-running broadcast. The examples below are starting points to adapt to your media and installed FFmpeg version, not universal commands.

How FFmpeg reads an ordered file list

FFmpeg’s concat demuxer reads a text file containing references to media files and presents them as a sequence. The sequence is the order of the file entries. It does not sort by filename, title, creation date or the order in which you originally selected the clips; it follows the list you supply. The concat demuxer documentation explains this format and its requirements.

That distinction matters when a channel has a deliberate running order: an opening prayer followed by bhajans, a local news bulletin followed by notices, or study videos arranged by topic. A folder may contain names such as 1.mp4, 10.mp4 and 2.mp4; a shell wildcard or file picker may not expand those names in the order you expect. A written list makes the intended sequence visible and reviewable before you start the stream.

A concat list is not a playlist player that can freely switch among any media formats. For the demuxer to work, the inputs need matching streams, codecs and time bases. Files that differ can fail or behave unexpectedly around boundaries even if their entries are correctly ordered. Sequence and compatibility are separate checks: first verify what plays next, then verify that the next file can be joined in the chosen workflow.

If you are also deciding how the broadcast should run when your own computer is switched off, the operational differences are discussed in moving an aarti stream from a local PC to a VPS. That is a separate decision from FFmpeg’s list order: a different place to run the encoder does not correct a misordered list or mismatched source files.

Prepare compatible video files

Before writing the final list, inspect the files you plan to concatenate. Check the video and audio streams, codecs, frame rates, dimensions, audio layout and timing information. You can use FFmpeg’s probing tools to review media properties, but interpret the results together: two files both named MP4 may still contain different codecs or stream layouts.

The concat demuxer is intended for inputs with compatible stream properties. If your files were produced by the same export preset, they may already fit, but do not assume that from their extensions. A phone recording, a downloaded clip and a desktop editor export can all be .mp4 while differing in frame rate, resolution, audio sample rate or timestamps. Differences are a reason to test and, if needed, prepare a common profile before concatenation.

There are two practical paths when sources differ. You can transcode each source into a compatible intermediate profile and then use the demuxer, or use FFmpeg’s concat filter to decode and re-encode the sequence as one output. FFmpeg’s concat FAQ describes the filter route for cases that need re-encoding. Neither path is automatically preferable: pre-conversion means extra preparation and storage, while filter-based processing uses compute during conversion and requires choices about output quality.

Approach When it fits Main trade-off
Prepare matching files, then use the concat demuxer Your sources can be converted ahead of time to share the required streams and timing properties You spend time creating and checking intermediates before the live run
Use a concat filter and re-encode Sources differ and need decoded processing into a common output Encoding uses compute and may affect quality; the filter graph depends on the media

Set a target profile before converting: choose a resolution, frame rate, video codec and audio format that suit the material and YouTube’s current guidance. Avoid assuming that lowering every source to one arbitrary profile is harmless; it can reduce quality, and frame-rate conversion can change motion. Keep the original files so you can revise the preparation without introducing another loss from repeated conversions.

If the source material includes MOV files, first check whether format conversion is actually needed rather than converting by extension alone. The MOV-to-MP4 preparation guide covers that separate task. A container change does not necessarily make stream properties compatible, so verify the resulting media rather than treating the new filename as proof.

Write the concat demuxer list

Create a plain text file, for example playlist.txt, with one file entry per video. Put each entry on its own line and write entries in the sequence you want viewers to hear and see:

file 'intro.mp4'
file 'chapter-01.mp4'
file 'chapter-02.mp4'
file 'outro.mp4'

The order is explicit: intro.mp4 comes first, then the two chapters, then the outro. You can place comments or additional directives only in accordance with the concat demuxer’s documented syntax; keep a basic list simple while diagnosing an issue. Do not add entries by relying on a wildcard expansion unless you have checked the resulting order yourself.

Paths are interpreted relative to the working directory of the FFmpeg process unless written as absolute paths. A relative path that works in an interactive terminal may fail when a scheduled job or service starts in a different directory. For a first test, use a directory where both the list and the media locations are unambiguous, then move to absolute paths or set the working directory deliberately for the long-running process.

If a filename contains spaces, quoting it in the list is important. Filenames with quotes or unusual characters need the escaping rules in the current FFmpeg documentation; do not guess at the escaping syntax. Renaming a troublesome file to a simple name can be easier than debugging a malformed list, provided you update the entry and verify the file location.

Keep the list as an operational record. Give it a useful name, save it alongside the project notes, and review it after any replacement or addition. If a channel changes from a morning programme to an evening sequence, maintain separate lists rather than editing an active list without knowing which version the running FFmpeg process has opened.

Check paths and file order

Read the list from top to bottom before starting FFmpeg. Match each entry against the actual filename and confirm that no line is duplicated, omitted or misspelt. If the stream appears to play clips in a surprising order, inspect this text file first; the concat demuxer follows its entries rather than inferring the intended sequence from their names.

A useful check is to make a short copy of the list containing the opening file, the file that should follow it, and a later transition that you want to verify. Run a local test and note what appears and what is audible at each boundary. This helps separate a list problem from an ingest or encoding problem. If the short test plays the correct order, the remaining question is whether all transitions in the full sequence behave acceptably.

Check the process’s current working directory as well as the paths. For example, a list containing file 'chapter-01.mp4' refers to a location relative to where FFmpeg resolves the list’s entries, not necessarily to the folder visible in your file manager. Absolute paths avoid that ambiguity, though you still need to ensure the account running FFmpeg can access them.

For filenames numbered in sequence, consider spelling numbers with leading zeroes, such as chapter-01, chapter-02 and chapter-10. This makes filenames easier for people to scan, but the list remains the authority: write the intended order explicitly. Do not edit a generated list without checking the final text, since automatic file discovery can include a temporary render or an unwanted alternate version.

Loop the sequence continuously

For a repeating sequence, FFmpeg can loop the concat input using -stream_loop -1. The option must be placed with the input options before the corresponding input, and the list itself must be specified as a concat-demuxer input. FFmpeg’s command-line documentation describes how options are applied to inputs and outputs; placement is significant, so a command that looks close can still apply an option to the wrong part of the invocation.

The following is an illustrative command shape for a prepared playlist. It has not been tested against your files or FFmpeg build, and its example bitrate and keyframe values must not be copied without checking your output profile and current YouTube recommendations:

ffmpeg -re -stream_loop -1 -f concat -safe 0 -i playlist.txt \
  -c:v libx264 -preset veryfast -b:v 4500k -maxrate 4500k -bufsize 9000k \
  -g 60 -keyint_min 60 -sc_threshold 0 \
  -c:a aac -b:a 128k -f flv "rtmps://SERVER/APP/STREAM_KEY"

In this shape, the input-reading options appear before -i playlist.txt; the encoding and output-container options appear before the destination URL. -re asks FFmpeg to read at a rate suitable for real-time output rather than consuming the sequence as quickly as possible. -stream_loop -1 requests repeated input playback. The example uses a concat list and an FLV output for an RTMP-family destination, but the exact combination still needs validation with the installed version, the source files and YouTube’s current instructions.

The example’s -g 60 corresponds to a two-second GOP only when the output is 30 frames per second. If the frame rate changes, recalculate the interval rather than leaving that value unchanged. The example’s bitrate is not a universal recommendation. YouTube provides recommendations by codec, resolution and frame rate; choose from its current live encoder settings, and make sure your available upload capacity can sustain the output.

A repeated input does not mean the end-to-start boundary will be invisible. The demuxer uses media durations and timestamps to present inputs in sequence; imperfect duration metadata or differing properties can affect timing. Test the last item followed by the first item just as carefully as transitions in the middle. If that boundary has a pause, discontinuity or audio change, investigate the source timing and compatibility rather than assuming the loop flag will repair it.

Encode for YouTube Live

Treat the output profile as a separate stage from sequence control. YouTube’s current encoder guidance lists RTMP/RTMPS ingest, supported video and audio codecs, constant bitrate guidance, and keyframe interval recommendations. It recommends a two-second keyframe interval and says not to exceed four seconds. Its bitrate recommendations vary by resolution and frame rate, so use the relevant current row rather than taking the sample command’s value as a general setting.

RTMPS is the encrypted transport recommended for live ingestion. Obtain the ingest destination and stream key from YouTube Live Control Room, and replace the placeholders in any local command without publishing the actual key. A stream key grants access to the broadcast destination: do not put it in a public article, screenshot, shared command history or unredacted log. If it is exposed, use YouTube’s current account controls to manage the key.

Check output settings as a group. A matching video bitrate alone does not establish that the stream is suitable: codec, resolution, frame rate, keyframe interval, audio codec and upload capacity also matter. The 1080p bitrate guide can help frame the bitrate question for prerecorded video, but the live encoder page remains the current authority for YouTube ingest guidance.

If you are encoding in real time on your own computer, allow for the combined work of reading files, decoding where required, encoding and sending the output. Re-encoding a set of mixed sources can be substantially more demanding than passing through already compatible streams. Test the actual machine and connection that will run the stream; a successful short local test does not establish that a computer can sustain a long session under other workloads.

For people who want the uploaded file to run as a YouTube broadcast while their own computer is off, StreamNeo removes the need to keep a local FFmpeg process running for this specific file-to-live-stream task. It does not make source rights, content preparation or YouTube’s current ingest and channel requirements irrelevant; check those separately.

Test transitions and troubleshoot breaks

Test before a public broadcast with a representative section of the sequence, including motion and audio. YouTube recommends testing with audio and moving video and checking stream health in Live Control Room. A still image with silence may confirm that a connection opens, but it will not expose a bad audio transition, missing motion, an unsuitable frame rate or an interruption at a file boundary.

When something goes wrong, diagnose the symptom rather than changing several settings at once:

Symptom First checks
A clip plays in the wrong position Open the playlist text and check the exact entry order and any generated file list
FFmpeg cannot open a file Check spelling, working directory, absolute or relative path, permissions and list syntax
The stream pauses or changes at a boundary Compare streams, codecs, time bases, durations and timestamps for the adjacent files
Picture or sound changes unexpectedly Check resolution, frame rate, audio layout and whether the files were normalised consistently
YouTube reports stream issues Compare actual output settings and upload capacity with the current encoder recommendations, then read the Live Control Room messages

For a break at a boundary, test the two files immediately before and after it on their own. If they differ in stream properties, prepare compatible versions or use a workflow that decodes and re-encodes the sequence. If they appear compatible, inspect duration and timestamp information and check whether the issue occurs at the same point on repeat. That gives you evidence to work with instead of treating every pause as an ingest fault.

For an ingest warning, verify the actual output rather than relying on what the command was intended to do. Confirm that FFmpeg is sending the expected codec, resolution, frame rate, keyframe interval, audio format and bitrate. Compare those values with YouTube’s current recommendation and with the capacity of the connection used for the stream. The cause of an unstable ingest cannot be inferred from an ordering issue alone.

Keep test results modest and specific: record which list was tested, which files were used, what changed at the boundary and what YouTube reported. Avoid claiming a sequence is “seamless” based only on one successful transition. If the broadcast runs overnight, a representative test is useful preparation, not a promise that all later conditions will match.

A continuous channel also needs a practical operating plan for monitoring and recovery. If you use a local process, consider how you will notice a stopped encode, restore access to the stream key if necessary and restart safely. The choice between a local machine, a remote machine and an upload-once workflow is operational; the comparison of PC power costs and cloud fees can help you assess those costs without changing the technical checks above.

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 always preserve the order I wrote?

It follows the order of entries in the list it reads. If the result differs from what you expected, check that FFmpeg received the intended list, that the entries are in the right order and that the paths refer to the files you meant to include.

Can I concatenate any MP4 files with the demuxer?

No. The container extension does not tell you whether the streams, codecs and time bases match. Inspect the media and test transitions; mixed sources may need normalisation or a concat-filter workflow that re-encodes them.

Does -stream_loop -1 make every transition seamless?

No. It requests repeated input playback, but it cannot correct mismatched streams, inaccurate timing or an abrupt edit between the last and first clips. Test the repeat boundary and investigate any pause or change you hear or see.

Which bitrate should I use for YouTube Live?

Use YouTube’s current live encoder guidance for your chosen codec, resolution and frame rate, then check that your connection can sustain it. A bitrate copied from an example or an older article is not a universal setting.

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 ↗