Skip to content

How to do an endless video stream

New Course Coming Soon:

Get Really Good at Git

I did an experiment for an idea I had for a side project.

My goal was to have YouTube live stream a video I already had recorded.

At the end of the video, the stream would start back from the start.

In case you’re wondering I just did the experiment and after seeing it work I said “works”, but I’m not actually using this. I also don’t guarantee it will work for you, just documenting what worked for me so next time I’ll reuse this code.

I guess this would work on Twitch as well but I haven’t tried so.. just a guess.

I started a live stream on YouTube and this gave me the stream key.

I had a video.mp4 video in a folder, and ran this shell script:


KEY="the YT stream key" #add yours

ffmpeg -stream_loop -1 -i "video.mp4" -vcodec libx264 -pix_fmt yuv420p -preset medium -r 30-g $((30 * 2)) -b:v 2500k -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k -f flv "rtmp://$KEY"

Those settings suppose the video is 720p, 30 frames per second.

Don’t ask me what all those settings do, I mixed some SO answers and tutorials to make it work.

Make sure you have the ffmpeg command line tool installed on your system.

This worked on my Mac, and also on a Ubuntu VPS I later used to test this so I could disconnect my Mac and let the VPS do the stream.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching May 21, 2024. Join the waiting list!

Here is how can I help you: