Streaming to Twitch.tv in Ubuntu Linux!

So apparently i am writing this like a new post. I had a script for streaming to twitch.tv with ffmpeg, but apparently it doesn’t work for that anymore. So i found a script on github that i will share with you. This time it is using avconv.

Open a terminal, and create a file in your home directory or where ever you want, and name it “twitch-stream“, with this command “touch twitch-stream“. Then open it with a editor, and add this script to it.

#! /bin/bash
# originaly from http://tinyurl.com/twitch-linux from taladan
# gist created by brodul
INRES=”1600×900″ # input resolution
OUTRES=”1600×900″ # Output resolution
FPS=”30″ # target FPS
QUAL=”ultrafast”
STREAM_KEY=$(cat ~/.twitch_key)
avconv \
-f x11grab -s $INRES -r “$FPS” -i :0.0 \
-f alsa -ac 2 -i pulse \
-vcodec libx264 -s $OUTRES -preset $QUAL \
-acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b 712000 -bufsize 512k \
-f flv “rtmp://live.twitch.tv/app/$STREAM_KEY”
Ok so apparently this one is simular to the last one i had on here.
1.) set your INRES=
2.) set your OUTRES=
3.) set your FPS=
4.) you can set your QUAL=  <– i have it set to ultrafast. Really depends on your bandwith
5.) this script is telling us to put your live twitch key in a file in your home directory called “.twitch_key” .. so in our home directory we just type in “touch .twitch_key“, and then get our key from http://twitch.tv/broadcast. (you must be logged in to twitch.tv, and press the “Show Key” button on the right) Copy and past your key into “.twitch_key”, then save it.
6.) then run “chmod +x twitch-stream
I just tested this out on my laptop and i had to install something extra, because it was giving me an error “Unrecognized option ‘preset’ Failed to set value ‘ultrafast’ for option ‘preset’“. So i did “sudo apt-get install libavcodec-extra-53", and tried to run my script again. It started up, and i was able to view it on my twitch page. Also found out that sound wasn't working, so i noticed in the script that it is using libmp3lame. So make sure you install lame with "sudo apt-get install lame". It should now work well.
I hope this works out better than the last script with ffmpeg. I know it was working for me when i first created that last one, but it wasn’t working when i just tried it. Sorry for all that confusion.
-Orkultus-
PS: if you want to stream to justin.tv, you just change the line on the bottom from “rtmp://live.twitch.tv/app/$STREAM_KEY“, to “rtmp://live.justin.tv/app/$STREAM_KEY
Advertisements

25 comments on “Streaming to Twitch.tv in Ubuntu Linux!

  1. Matt says:

    Hey!

    I tried running your script, however the only thing the stream displays is the webcam in the 120x… resolution maxed up to the output res, the screen is not shown at all.

    Any suggestions?

  2. lol says:

    printing
    ./twitch-stream: строка 3: неожиданный EOF при поиске соответствующего `”‘
    ./twitch-stream: строка 13: ошибка синтаксиса: неожиданный конец файла

  3. cromies says:

    It’s telling me I have the wrong screen resolution, but the display setting tells me that it’s correct. Is this a bug?

    • orkultus says:

      Let me check on it, and see what i can make of it.

    • orkultus says:

      Ok so i ended up noticing that it was causing problems for a few people, and actually myself. So i found a script from github, to replace the one i posted. I just set it up on mine and it was streaming to my twitch.tv with no problem. Give it a try. Sorry for the confusion.

      • cromies says:

        Alright, the streaming works but I can’t hear anything. Is there anything we can do about the audio?

      • orkultus says:

        Let me check into that for you.

      • orkultus says:

        Ok so i figured it out. I noticed the code was doing output with libmp3lame, so i got it working by installing lame. with “sudo apt-get install lame”. I can hear it now with no problems at all. Good luck to yah!

        -Orkultus-

  4. tobywanbj says:

    just tried this but it’s saying that “-f: command not found” not sure what’s going on????

    • tobywanbj says:

      nevermind, re-copied it and now it gets past that but gives me [x11grab @ 0x1240be0] Couldn’t parse video size.
      :0.0: Invalid argument

      so confused about why it isn’t working?????

      • orkultus says:

        Let me look at it. I will reply soon. I have a job interview today, and i just worked overnight at my current job. So i need to get some sleep for a bit. Sorry for the wait, and the issues.

        -Orkultus-

      • tsih says:

        avconv version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
        built on Mar 30 2013 22:20:06 with gcc 4.7.2
        [x11grab @ 0x1d3ef20] Couldn’t parse video size.
        :0.0: Invalid argument

        So I’m getting it also. Using HD6870 with newest AMD drivers, 13.04 Ubuntu.

      • orkultus says:

        Yeah this is getting frustrating. It was working when i posted the script, and im starting to think that something got messed up after an update. I just tried to run this script in my Linux Mint 15 box, and my Arch Linux laptop. Both with no luck. Im sorry guys.

        Let me think of something else.

        -Orkultus-

      • Camoceltic says:

        Likely that the :0.0 at the end of the line in that file was supposed to indicate a file, but, since this is streaming, the 0.0 was supposed to act as a display or the beginning pixel for the input resolution. I don’t know how to fix it, but that may help in fixing it.

      • orkultus says:

        Yeah i believe it represents the screen number.

        -Orkultus-

  5. tychon says:

    If anyone still needs this, here’s my version for it.

    #! /bin/bash
    VI_RES=”1440×900″
    VI_FREQ=”30″

    VO_RES=”720×450″
    VO_TUNE=”ultrafast”
    VO_QSC=”5″

    AO_FREQ=”44100″
    AO_BITS=”256k”
    AO_BUFSZ=”512k”
    AO_QSC=”5″

    KEY_TWITCHTV=$(cat ~/.twitchtv-key)

    avconv \
    -f x11grab -s “$VI_RES” -r “$VI_FREQ” -i “$DISPLAY” \
    -f alsa -ac 2 -i pulse \
    -codec:v libx264 -s “$VO_RES” -pre:v “$VO_TUNE” -qscale “$VO_QSC” -pix_fmt “yuv420p” \
    -codec:a libmp3lame -ar “$AO_FREQ” -threads auto -qscale “$AO_QSC” -b “$AO_BITS” -bufsize “$AO_BUFSZ” \
    -f flv “rtmp://live.twitch.tv/app/$KEY_TWITCHTV”

  6. Lester says:

    All the errors people get are most probably because of html special chars like × and ”. Retype all the suspicious characters and try again.

  7. Anden says:

    So for all of you having problems with it not accepting :0.0, that’s not the problem. The problem comes from the lines with the audio, if you take them out it starts to work. I haven’t found the right config for that yet. Also, the quote signs here on this blog gets messed up so when you copy them you get the wrong kind of quotes into the script. Perhaps you should put up a link to pastebin instead or something.

    Although I got it to work, I only manage to stream the upper left corner of my screen. Twitch.tv says it’s a 1080p+ stream and that’s what I have confed the shell script for but it’s not what it’s outputting

  8. Im using the following with an A8-3870k and an HD5750 to stream some Serious Sam 3 BFE which I am playing in Fullscreen (1680×1050) and this is what I use. Oh, I have 5Mbps upload as well.
    #! /bin/bash

    # originaly from http://tinyurl.com/twitch-linux from taladan
    # http://www.youtube.com/user/taladan

    # gist created by brodul

    INRES=”1680×1050″ # input resolution
    #OUTRES=”1024×640″ # Output resolution
    OUTRES=”1280×720″ # Output resolution
    FPS=”30″ # target FPS
    QUAL=”fast” # one of the many FFMPEG preset on (k)ubuntu found in /usr/share/ffmpeg
    # If you have low bandwidth, put the qual preset on ‘fast’ (upload bandwidth)
    # If you have medium bandwitch put it on normal to medium

    # Write your key in a file named .twitch_key in your home directory
    STREAM_KEY=$(cat ~/.twitch_key) # This is your streamkey generated by jtv/twitch found at: http://www.justin.tv/broadcast/adv_other

    avconv \
    -f x11grab -s $INRES -r “$FPS” -i :0.0 \
    -f alsa -ac 2 -i pulse \
    -vcodec libx264 -s $OUTRES -preset $QUAL \
    -acodec libmp3lame -ar 44100 -threads 4 -qscale 3 -b 3000000 -bufsize 512k \
    -f flv “rtmp://live.justin.tv/app/$STREAM_KEY”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s