How to Make a 24/7 Study Playlist Stream with FFmpeg
In this article
This guide shows you how to use FFmpeg to create a continuous, 24/7 looping stream of your study playlist, perfect for YouTube Live, Twitch, or a personal server. You'll set up a command that cycles through your audio and video files, and then push that stream to a platform of your choice. No coding experience is needed, just a computer that can stay on and a few free tools.
What You'll Need
- FFmpeg installed on your computer (free, open-source). Download from ffmpeg.org and add it to your system PATH.
- A folder of audio files (MP3, M4A, WAV, etc.) and/or video files (MP4, MKV) you want to loop.
- A streaming destination – e.g., a YouTube Live stream key, Twitch stream key, or an RTMP server URL.
- A computer that stays on – the stream will run as long as FFmpeg runs.
- Optional: A static background image (JPG/PNG) if you're streaming audio only.
Step-by-Step
- Install FFmpeg
Download the correct build for your OS (Windows, macOS, Linux) from ffmpeg.org. Extract the files and add thebinfolder to your system's PATH so you can runffmpegfrom any terminal. - Organize your media
Place all audio files (and optionally a background image) in a single folder. For video files, ensure they are in a format FFmpeg can read (most common formats work). Name files without spaces or special characters to avoid quoting issues, e.g.,song1.mp3,song2.mp3. - Test the loop locally
Open a terminal and run a simple command to verify FFmpeg can read your files and loop them. For audio-only with a background image:ffmpeg -loop 1 -i background.jpg -f concat -safe 0 -i filelist.txt -shortest -c:v libx264 -preset veryfast -b:v 3000k -c:a aac -b:a 128k -f flv test.flv
This creates a short test file. If you get errors, check file paths and codec support. - Create a file list for the concat demuxer
Create a text file (e.g.,playlist.txt) in the same folder. List each audio file with a full path or relative path, one per line, like:file 'song1.mp3'file 'song2.mp3'
This tells FFmpeg to play them in sequence. - Build the infinite loop command
Use the-stream_loop -1option to loop the entire playlist indefinitely. For audio-only with a background image, the command looks like:ffmpeg -stream_loop -1 -f concat -safe 0 -i playlist.txt -loop 1 -i background.jpg -shortest -c:v libx264 -preset veryfast -b:v 3000k -c:a aac -b:a 128k -f flv rtmp://a.rtmp.youtube.com/live2/STREAM_KEY
ReplaceSTREAM_KEYwith your actual stream key. For video files, you can omit the background image and use-stream_loop -1 -i video.mp4. - Start the stream
Run the command in your terminal. FFmpeg will begin encoding and pushing the stream to your destination. Keep the terminal open – closing it stops the stream. - Automate restart (optional)
If the stream drops, you can use a simple batch script (Windows) or shell script (macOS/Linux) that restarts FFmpeg automatically. For example, a.batfile with a loop that runs the command and waits 5 seconds if it fails.
Common Mistakes
- Not using the concat demuxer correctly – File paths must be correct, and the
-safe 0flag is needed if you use absolute paths or special characters. - Forgetting
-shortest– Without it, the audio stream may continue after the video (background) ends, causing the stream to stop.-shortestends the output when the shortest input ends. - Using a stream key publicly – Never share your stream key. Anyone with it can hijack your channel.
- Ignoring bitrate limits – If your upload speed is low, using a high bitrate (e.g., 3000k) will cause buffering. Check your upload speed and adjust.
- Not testing locally first – Always test with a short output to a local file before pushing to a live platform.
Tips
- Use a veryfast preset –
-preset veryfastreduces CPU load, which is important for long streams. - Add a clock or timer overlay – Use FFmpeg's
drawtextfilter to show the current time, which is helpful for study sessions. Example:-vf "drawtext=text='%{localtime}':fontsize=24:fontcolor=white:x=10:y=10". - Consider using a playlist file – Instead of listing files in the command, use the concat file to make it easier to edit the playlist without changing the command.
- Monitor your stream – Use a separate device to watch your stream and ensure it's stable.
- Use a static IP or dynamic DNS – If you're streaming from home, your IP may change; use a dynamic DNS service to keep the stream URL stable.
Troubleshooting
- FFmpeg not recognized – Ensure FFmpeg is in your PATH. On Windows, you may need to restart your terminal after adding it.
- Stream stops after a few minutes – Check your upload speed. Lower the bitrate (
-b:v 1500k) and try again. Also check if your internet connection is stable. - Audio/video out of sync – This usually happens with variable frame rate videos. Use
-vsync cfrto force constant frame rate. - Error: "Unknown encoder 'libx264'" – Your FFmpeg build may not include H.264. Download a full build from ffmpeg.org or use a different encoder like
mpeg4(but H.264 is recommended for streaming). - Stream shows black screen – If you're using a background image, ensure it's large enough and the
-loop 1flag is present. Also check the image format (JPG/PNG). - Cannot connect to RTMP server – Double-check the server URL and stream key. Ensure your firewall allows outbound RTMP (port 1935).
Frequently Asked Questions
Can I use this method for a podcast or music stream?
Yes, the same command works for any audio loop. Just replace the background image with a static cover art or a simple video loop.
Will this work on a Raspberry Pi?
Yes, but the Pi's CPU may struggle with high bitrates. Use a lower resolution (e.g., 720p) and a veryfast preset to keep it stable.
How do I add a live clock to my stream?
Use the drawtext filter with %{localtime} to display the current time. You'll need to install a font file and specify its path.
Can I use this to stream to multiple platforms at once?
FFmpeg can output to multiple RTMP destinations by adding multiple -f flv outputs with different URLs, but this increases CPU load. Alternatively, use a service like Restream.
Why does my stream stop after one loop?
Make sure you include -stream_loop -1 before the -i for the concat input. If you're using a single file, put -stream_loop -1 before that file's -i.
Is it legal to stream copyrighted music?
Only if you have the rights to the music. For study playlists, consider using royalty-free music or your own compositions to avoid copyright strikes.