How do I stream to Twitch.tv?

I am using the latest updated Ubuntu 12.04 and I would like to know how I can stream my second monitor to an RTMP address. (Twitch.tv)

Is there any kind of streaming on Linux I can set up, or an up to date guide that shows how to do it in 12.04?


Solution 1:

You can stream directly to an RMTP address using ffmpeg or avconv provided you have the necessary authentication (stream key).

An condensed example of using ffmpeg to stream to the Twitch.tv RMTP server would be as follows:

# stream key. You can set this manually.
STREAM_KEY=$(cat ~/.twitch_key)

# stream url. Note the formats for twitch.tv and justin.tv
# twitch:"rtmp://live.twitch.tv/app/$STREAM_KEY"
# justin:"rtmp://live.justin.tv/app/$STREAM_KEY"
STREAM_URL="rtmp://live.twitch.tv/app/$STREAM_KEY"

ffmpeg \
-f alsa -ac 2 -i "pulse" \
-f x11grab -s $(xwininfo -root | awk '/geometry/ {print $2}'i) -r "30" -i :0.0 \
-vcodec libx264 -pix_fmt yuv420p -s "640x360" -vpre "fast" \
-acodec libmp3lame -threads 6 -qscale 5 -b 64KB \
-f flv -ar 22050 "$STREAM_URL"

For more information on how to stream to popular platforms like twitch.tv and justin.tv see this askubuntu answer.

A gist of an extended version of the above script can be found here: https://gist.github.com/oseparovic/2db2aaa737cd37e7c068

Solution 2:

Red5 Install red5-server

This is a free RTMP server for recording and streaming to a Flash client. Its features according to the project's home page are:

  • Streaming Audio/Video (FLV and MP3)
  • Recording Client Streams (FLV only)
  • Shared Objects
  • Live Stream Publishing (live h264 supported now)
  • Remoting ( AMF0/ AMF3)

The application is mainly intended to setup your own RTMP server. We have no experience on how to set up sending a stream to a remote streaming server and if we are able to do this for Twitch.tv. Some documentation exists on the project's home page indicating that this can be done.

A (somehow quite nested) documentation can be found on the projects pages:

  • Red5 Getting Started