How to Create a 24/7 Looping Livestream with FFmpeg on Ubuntu | Complete Guide
Running a 24/7 live stream doesn’t require expensive hardware, proprietary software, or complicated setups. With FFmpeg — an incredibly powerful open-source command-line tool — you can continuously loop a short video and broadcast it to platforms like YouTube all day, every day from a simple Ubuntu server.
This guide explains exactly how such a stream works, using the real FFmpeg configuration behind a fully automated looping livestream.
β Why FFmpeg for 24/7 Streaming?
FFmpeg is lightweight, reliable, scriptable, and designed for automation. When configured correctly, it can:
-
Loop video files endlessly
-
Encode in real-time
-
Push media to any RTMP streaming service
-
Run unattended for days or weeks
Perfect for music streams, ambience videos, tutorials, or demonstration channels.
βοΈ The FFmpeg Command Used
Below is the command used for a continuous looped stream (with stream key removed for security):
ffmpeg -re -stream_loop -1 -i yourvideo.mp4 \
-c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k \
-pix_fmt yuv420p -g 60 \
-c:a aac -b:a 128k -ar 44100 \
-f flv rtmp://a.rtmp.youtube.com/live2/YOUR-STREAM-KEY
This command handles everything from loop control to audio/video encoding and RTMP transmission.
π Understanding Each Part of the Command
Below is a breakdown of every parameter and why it’s used:
| Command Part | Meaning & Purpose |
|---|---|
| ffmpeg | Launches the FFmpeg program. |
| -re | Reads the input in **real time**. Essential for live streaming. |
| -stream_loop -1 | **Loops the input video infinitely** — perfect for 24/7 streams. |
| -i yourvideo.mp4 | Specifies your **video file** as the stream source. |
| -c:v libx264 | Encodes video using the **H.264 codec** (YouTube standard). |
| -preset veryfast | Balances encoding quality and CPU usage for **stable live broadcasting**. |
| -b:v 3000k | Sets **video bitrate** to 3 Mbps. |
| -maxrate 3000k | Prevents bitrate spikes that may cause buffering. |
| -bufsize 6000k | Helps maintain constant bitrate streaming. |
| -pix_fmt yuv420p | Ensures **maximum device compatibility**. |
| -g 60 | Sends a **keyframe every 2 seconds** (YouTube recommended). |
| -c:a aac | Sets **audio codec to AAC** (required by YouTube). |
| -b:a 128k | Sets **audio bitrate** to 128 kbps. |
| -ar 44100 | Audio **sample rate** set to 44.1 kHz. |
| -f flv | **FLV container format** — required for RTMP streaming. |
| rtmp://YOUR-STREAM-KEY | **RTMP URL** + the private stream key authorizing your broadcast. |
π What This Setup Achieves
This configuration allows you to:
-
Run a fully automated, 24/7 live stream
-
Use a short clip as a looping video source
-
Broadcast from any Ubuntu server or VPS
-
Deliver a stable, high-quality YouTube stream
-
Maintain low server load with efficient real-time encoding
It's one of the most affordable ways to run a persistent livestream.
π¬ Final Thoughts
Setting up a 24/7 broadcast with FFmpeg is surprisingly simple once you understand the command structure. The example shown here is robust, lightweight, and adaptable to almost any streaming purpose.
Conclusion
My FFmpeg logs are looking spot-on, which is a huge relief! I see the frame count just keeps climbing, a nice steady 28 frames per second, and that bitrate is holding rock-solid at around 3100 kbps.
All that tells me my 24/7 stream is running perfectly – the encoder is doing its job efficiently, my looped video is playing without a hitch, and the whole upload process is super smooth.
When I check these logs and see everything so consistent – steady frames, steady bitrate, steady timestamps – I know my continuous broadcast is running exactly as I intended.
1 Comments
Sagar
sudo apt update && sudo apt install ffmpeg -y && sudo apt install screen -y