The problem
When submitting an extension for review, you have to provide a test stream that’s online and has the extension installed. You basically have to stream 24 hours a day until your extension is approved. Not everyone has stable internet or wants to hog the dev-rig for this.
The solution
We are going to use ffmpeg to stream a static test image 24/7 with very little cpu usage.
How (Linux)
- Install ffmpeg (usually
sudo apt install ffmpeg) - create an image with your desired resolution (I use 640 x 360, but you can use 720p or 1080p)
call itbg.pngorbg.jpg - get your stream key from Dashboard -> Settings (Channel)
- open a terminal and navigate to the folder with the image
- run
ffmpeg -nostdin -framerate 15 -re -loop 1 -i bg.png -f flv -vcodec libx264 -pix_fmt yuv420p -preset slow -r 15 -g 30 "rtmp://live-fra.twitch.tv/app/YOURSTREAMKEY" -nostats </dev/null >/dev/null 2>&1 &
Congratulations, you are now streaming a static test image to twitch
Command breakdown
-
-nosdtinto suppress some terminal outputs -
-framerate 15 -re -loop 1 -i bg.pngloops one image at 15fps in real time
if you don’t use-reit’s reading the image as fast as it can, using all ressources -
-f flv -vcodec libx264 -pix_fmt yuv420pare the twitch recommended codec settings -
-preset slowsets the encoding speed to compression ratio
other options areultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow
if ffmpeg can’t keep up, increase the speed -
-r 15 -g 30sets the output fps to 15 and the keyframe interval to 2
if keyframe interval is more than 4*fps twitch will show error messages -
"rtmp://live-fra.twitch.tv/app/YOURSTREAMKEY"is the stream url,live-frais Frankfurt, you should change this to your closest server from this list -
-nostats </dev/null >/dev/null 2>&1suppresses more terminal output by sending it to /dev/null -
&this runs the command and frees up the terminal, basically running the process in the background
How to Stop
After running the command, the terminal gives you a process id, like 28010 or something. You can stop ffmpeg by typing kill 28010 in the terminal. If you don’t know the id, type top to get a process list and look for ffmpeg (usually at the top). Ctrl + C to leave top
The best solution
If you really don’t want to use your own Pc, you can do this from a cheap linux server in the cloud. I use a 5$/month Digital Ocean droplet. If you use my referral link you get 10$ for free. My 640 x 360 png uses 11% CPU and 8% RAM. By doing this you need to use ssh, so you have to put nohup before the ffmpeg command, so it doesn’t stop, when you terminate the ssh session:
nohup ffmpeg -nostdin -framerate 15 -re -loop 1 -i bg.png -f flv -vcodec libx264 -pix_fmt yuv420p -preset slow -r 15 -g 30 "rtmp://live-fra.twitch.tv/app/YOURSTREAMKEY" -nostats </dev/null >/dev/null 2>&1 &
Troubleshooting
- make sure you use YOUR stream key and the right image name
- if you want to see output or errors run the command in the terminal foreground:
ffmpeg -framerate 15 -re -loop 1 -i bg.png -f flv -vcodec libx264 -pix_fmt yuv420p -preset slow -r 15 -g 30 "rtmp://live-fra.twitch.tv/app/YOURSTREAMKEY"
Ctrl + C to end it