Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Twitch.tv script for streaming
#! /bin/bash
# originaly from http://tinyurl.com/twitch-linux from taladan
# www.youtube.com/user/taladan
# gist created by brodul
INRES="1280x800" # input resolution
#OUTRES="1024x640" # Output resolution
OUTRES="800x500" # Output resolution
FPS="30" # target FPS
QUAL="medium" # 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 6 -qscale 3 -b 712000 -bufsize 512k \
-f flv "rtmp://live.justin.tv/app/$STREAM_KEY"
@Evropi
Unrecognized option 'preset'
Failed to set value 'medium' for option 'preset'

Can't find usr/share/ffmpeg either on Linux Mint 14 KDE Edition. :(

@nchu

Unrecognized option 'preset'
Failed to set value 'medium' for option 'preset'

@temkretz

@Evropi:

install the package namend "ffmpeg"

@nchu

install 'libavcodec-extra-53'

@gorkipt
[x11grab @ 0x9caf20] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1920 height: 1080
[x11grab @ 0x9caf20] Could not open X display.
:0.0: Input/output error 

what now ? =S

@Kranium31

sound is way a head of the video, anyone know what command i can add to keep the audio in sync?

@noccy80

@Kranium31 try tweaking the buffer size (-bufsize) up and down and see if that makes any difference.

@mjrb

when i am broadcasting it dosnt show the video it just sits there and says loading

@CuBiC3D

Same problem as @mjrb. Video keeps loading on different devices. Tried streaming on fast @ 1024x640 with 10Mbit/s uplink on 13.10.

@ckdarby

This long longer works by the way.

Your live stream will just show a gray box but if you record the video it'll have the video contents.

Example:
http://www.twitch.tv/testubuntu/b/494211210

@KurinPawpad

To fix the 'Unrecognized option 'preset' Failed to set value 'medium' for option 'preset'' bug, change 'preset' to 'pre' on line 22, and change 'fast' or 'medium' to 'libx264-fast' or 'libx264-medium' respectively.

@xSidewinderx

I had this working before not sure what changed, but on the stream it says live but all I see is a gray screen and "loading video" any help?

@ual002

I'm a complete linux newbie. This worked great. What about the audio, including mic?

EDIT: Nevermind, the mic works, what about any gameplay audio?

@tomatogoatee

I'm streaming from my Windows box using OBS to my Ubuntu server running nginx to relay the stream to twitch and hitbox. I'm trying to add an overlay to the twitch stream telling people to follow me on hitbox, but it just gives me the grey 'loading' screen. Here's the exact line I'm using:

avconv -i rtmp://localhost/twitch/$name -vf "movie=/shared/message.png[logo];[in][logo]overlay=0:70[out]" -c:a copy -c:v copy -b:v 800k -maxrate 800k -minrate 800k -bufsize 800k -g 60 -f flv rtmp://live-ams.twitch.tv/app/

and this DOES WORK, but the message doesn't appear. If I change the "-c:v copy" to "-c:v libx264" then the stream fails to load.
I've tried redirecting the stream to my local streaming server (as well as to an output file) and it does play, including the message. It's only when I try to send it to twitch that it fails. Any ideas?

@tomatogoatee

Here's my setup: My Windows box using OBS to stream to my Ubuntu server running nginx to send the stream to both twitch and hitbox. What I'm trying to accomplish is adding a message to the twitch stream only, telling people to follow me on hitbox.
This is the line I'm using right now:

avconv -i rtmp://localhost/twitch/$name -vf "movie=/shared/message.png[logo];[in][logo]overlay=0:70[out]" -c:a copy -c:v copy -b:v 800k -maxrate 800k -minrate 800k -bufsize 800k -g 60 -f flv rtmp://live-ams.twitch.tv/app/

Now this works, except that the logo doesn't display. If I change the "-c:v copy" to "-c:v libx264" then twitch gives me the grey 'loading' box. However, if I send the stream to my local server (or output to a file), it opens fine and even shows the message!
Any suggestion as to how to fix this? I feel I'm close, but don't know what I'm doing wrong.

@xros

You may try this one for noobies. :) https://github.com/xros/livestreamer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.