FFmpeg’s concat demuxer can play a sequence of video files as one continuous stream, without first joining them into a new file. You’ll need FFmpeg installed, video files in a known order, and the address and stream key for your streaming service; the examples below send the result to an RTMP destination.
What You’ll Need
- FFmpeg installed and available as the
ffmpegcommand. Check withffmpeg -version. - The video files you want to play, accessible from your computer. For the simplest concat workflow, use files with matching codecs, dimensions, frame rates, audio layout, and time base.
- A text editor for a playlist, plus a terminal or command prompt.
- Your streaming service’s RTMP server URL and stream key. Treat the key like a password; do not post it publicly or include it in shared logs.
Step-by-Step
- Check the input files. Put the videos in one folder and decide their playback order. For a reliable stream-copy concat, make sure their technical properties are compatible. You can inspect a file with
ffprobe -v error -show_streams -show_format "clip1.mp4". Compare video and audio codecs, resolution, frame rate, sample rate, and channel layout. Similar-looking files are not necessarily technically compatible. - Create the concat list. In the same folder, create a plain-text file called
playlist.txt. Add one line per video, in the order you want them played:file 'clip1.mp4'
file 'clip2.mp4'
file 'clip3.mp4'
Use paths relative to the list file, or write full paths. Quote paths containing spaces. The concat demuxer uses a specific text format; if a filename contains a single quote or unusual characters, use a safely escaped path or rename the file to a simple name. Do not add commas or numbering between entries. - Test the playlist locally. Before connecting to a live service, confirm FFmpeg can read the sequence:
ffmpeg -f concat -safe 0 -i playlist.txt -c copy test-output.mkv
This writes a local file without re-encoding. The-safe 0option permits paths the demuxer would otherwise reject as unsafe, including some absolute paths. Only use it with a playlist you control. If the test fails, fix the playlist or input compatibility before streaming. - Prepare the streaming destination. In your streaming service’s live settings, copy its RTMP server address and stream key. Combine them in the form
rtmp://server-address/app/STREAM_KEY, following the exact format supplied by the service. Some platforms provide a complete URL already. Keep the destination private. - Start the stream. For compatible files that can be copied directly, run:
ffmpeg -re -f concat -safe 0 -i playlist.txt -c copy -f flv "rtmp://server-address/app/STREAM_KEY"
Replace the example destination with your own.-rereads the input at approximately real-time speed rather than sending the files as fast as possible.-f concatselects the concat demuxer,-isupplies the playlist, and-c copyavoids re-encoding. The FLV output format is commonly used for RTMP. - Check playback and the ending. Watch the service’s preview or a private test stream. Read FFmpeg’s terminal output for errors, and check that video and audio continue at each transition. By default, the playlist plays once and then stops. A continuous stream may loop the list using:
ffmpeg -re -stream_loop -1 -f concat -safe 0 -i playlist.txt -c copy -f flv "rtmp://server-address/app/STREAM_KEY"
Here-1requests infinite looping. Stop FFmpeg withqin its terminal or with the appropriate interrupt for your operating system. - Re-encode when copying is incompatible. If files differ in ways that prevent a stable output, use a consistent encoding instead of
-c copy:ffmpeg -re -f concat -safe 0 -i playlist.txt -c:v libx264 -preset veryfast -pix_fmt yuv420p -r 30 -c:a aac -ar 48000 -b:a 128k -f flv "rtmp://server-address/app/STREAM_KEY"
This example converts video to H.264 at 30 fps and audio to AAC at 48 kHz. Adjust settings to meet your destination’s requirements and your computer’s capacity. Re-encoding uses more CPU and may require testing to avoid dropped frames.
Common Mistakes
- Using the wrong playlist format: The concat demuxer expects
file 'path'entries, not a comma-separated list or a list made for the concat filter. - Assuming
-c copyfixes mismatches: Stream copy preserves each input’s encoded data. It does not normalize differing formats, frame rates, or audio streams. - Leaving out
-re: Without real-time pacing, local files can be sent much faster than their playback duration, depending on the output and setup. - Expecting automatic looping: A playlist ends when its last entry finishes unless you add a loop option or otherwise restart the command.
- Exposing the stream key: A key included in a screenshot, public script, or shared command can let someone else broadcast to your channel. Regenerate it through the service if it is exposed.
Tips
- Use simple filenames and keep the playlist beside the media, particularly when troubleshooting paths.
- Test with a short, unlisted or private broadcast before scheduling a long stream.
- For long-running broadcasts, monitor the FFmpeg process and network connection. A successful initial connection does not guarantee the stream will remain stable.
- Use
-c copywhen inputs are truly compatible to reduce CPU use. Choose re-encoding when you need a consistent output or transitions fail. - Save the command without a real stream key, then enter the key only when needed. Avoid putting credentials in scripts that others can read.
Troubleshooting
“Impossible to open” or “No such file”: Check that the playlist is in the current working folder and that each path is correct relative to the playlist. Try full paths, and confirm quote characters are paired. Use -safe 0 only for a playlist you trust.
Playback stops or glitches at a transition: Inspect each input with ffprobe and compare stream properties. Try re-encoding all files to one video and audio format. Also check for damaged media by testing each file individually.
The service rejects the stream: Verify the RTMP address and key, destination requirements, and that the service is set to accept a live broadcast. Check FFmpeg’s output for connection or authentication errors. Do not paste the key into a public support post.
Video plays too quickly or the broadcast ends early: Confirm -re appears before the input option and that the playlist contains every intended file. Add -stream_loop -1 before the input if the sequence should repeat.
Encoding is slow or frames drop: Re-encoding can exceed your computer’s available processing capacity. Try a faster preset, a lower output resolution or frame rate, or stream-copy compatible inputs. Check CPU use and upload stability while testing.
Frequently Asked Questions
Does FFmpeg create one combined video first?
No. The concat demuxer reads the files in sequence while FFmpeg streams them. The local test command creates a file only because it specifies an output file.
Can I mix MP4, MKV, and other containers?
Sometimes, but container names alone do not determine compatibility. The encoded streams and their properties matter. Re-encoding is often the practical option when inputs differ.
Will the stream continue forever?
Not by default. It stops after the final playlist entry. Use -stream_loop -1 before -i to repeat the sequence indefinitely, and keep the process and connection running.
Can I add a transition between videos?
The concat demuxer joins entries in sequence; it does not create fades or other transitions. Those require a filter workflow, typically with re-encoding.
Can I change the playlist while streaming?
Do not rely on edits to change an already-running input. Stop FFmpeg, update and check the playlist, then restart the stream.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Multi-Asset Trading Platforms: Why They’re Essential
- Creality K3 4-Nozzle 3D Printer: 4.8s Swap?
- Notepad Remove Duplicate Lines: 3 Simple Ways
- API Security Checklist: A Backend Dev’s Guide
- Storefront Hero Images: Desktop vs. Mobile Versions
- Device Encryption vs BitLocker: Key Differences