How do I stream to Twitch.tv?

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:
gist.github.com/oseparovic/2db2aaa737cd37e7c068

Read more here: Source link