In this post I will show how I managed to set up a live stream of my Ubuntu 12.04 desktop to Justin.tv. Since Justin.tv is tightly connected to Twitch.tv, you can probably with very small modifications make this work with Twitch too.
Create a new file called stream.sh and paste the following text into the file:
INRES="1680x1050" # input resolution
FPS="15" # target FPS
QUAL="fast" # one of the many FFMPEG preset
avconv -f x11grab -s "$INRES" -r "$FPS" -i :0.0+$OFFSET -ab 192k \
-f alsa -ac 2 -i pulse -vcodec libx264 -crf 30 -preset "$QUAL" -s "1280x720" \
-vol 11200 -acodec libmp3lame -ar 44100 -threads 0 \
-f flv "$URL"
You can get your stream key from this page:
Note that you probably want to change the OFFSET variable to 0,0. I have it because I only wanted to stream my second monitor, which is to the right.
More options to x11grab can be found here, such as draw_mouse and follow_mouse:
The script is based on the one found in this thread:
Update the script’s permissions from the terminal:
chmod u+x stream.sh
The video codec (-vcodec libx264) requires that you have this package installed:
sudo apt-get install libavcodec-extra-53
This did I find out in this Stack Overflow answer:
Start streaming by running:
I’m not completely satisfied with the audio quality on the stream. I changed the bitrate argument in the script from 96k to 192k, and I added “-vol 11200″ to increase the audio volume since it was incredibly low. The quality is still not very good, so if you have a solution, please leave a comment.
The package pavucontrol in Ubuntu’s repository is an audio manager that has some more options than the pre-installed. However, I didn’t find anything that I had use of there, but maybe you have.