Twitch streaming from webradio stream

Twitch streaming from webradio stream

Twitch is a video streaming service, mostly used by gamers, that can be used also for another purpose. As you may already know, I’m a Digital Streaming Specialist in a web radio Can Twitch be used for a web radio or radio? How can a web radio use the Twitch video functionalities? 

There are multiple radio and web radio that use Twitch to stream their content, mostly they use some webcams in the studio and add the radio streaming audio to the video. This looks like a TV radio, like the one that you can find on TV. Technologies can achieve the same result on Twitch as the one on TV with fewer expenses. Twitch is free,  the streaming software can be free (OBS is a free software to do it), you need to buy a camera(s) and some video acquisition hardware but you can arrange these things with the budget you have. 

If you don’t have a budget at all, and you don’t want to add a real video taken from a camera to your web radio audio streaming, you can create a digital video with the following steps. The idea is to:

  1. Use a static image
  2. Add some dynamic content, for example, some video created directly from the audio source
  3. Add the streaming audio

You may think that you need software always open on a computer but there is a better solution: use ffmpeg to do this and let ffmpeg run in background on a computer. I’ve already written about ffmpeg (here, here, and here) and some of the function it has. With this solution, you can run it on a computer also used for something else, on a server, or also on a RaspberryPi connected to the internet. And this is very cool stuff!

  • twitch key, it looks like live_238476238546_234jhgfuowgsjdhbfwsDFSdgbjsbv
  • the audio stream
  • a static image /somepath/mystaticimage.jpg

then just run this command

ffmpeg -loop 1 -f image2 -thread_queue_size 256 -i /somepath/mystaticimage.jpg \
-thread_queue_size 256 -i -re \
-nostdin \
-f lavfi -i aevalsrc="sin(0*2*PI*t)" \
-vcodec libx264 -r 30 -g 30 \
-preset fast -vb 3000k -pix_fmt rgb24 \
-pix_fmt yuv420p -f flv \
-filter_complex \
"[1:a]showwaves=s=960x100:colors=Red:mode=cline:rate=25:scale=sqrt[outputwave]; \
[0:v][outputwave] overlay=0:510:shortest=1 [out]" \
-map '[out]' -map '1:a' -c:a copy -y \
rtmp:// \
-loglevel quiet 2> /dev/null &

some notes on this command: 

  • [0:v][outputwave] overlay=0:510:shortest=1 [out]" 
    set where the waveform is printed, 510 is “at what height” you can play with that value to move upper or lower the waveform.
  • "[1:a]showwaves=s=960x100:colors=Red:mode=cline:rate=25:scale=sqrt[outputwave];
    is the waveform creator. There is the color and how the waveform should be printed, check the ffmepg documentation for other configuration
  • -loglevel quiet 2> /dev/null &
    is to put the command on background

And this is the final result (some seconds)