Skip to content

Instantly share code, notes, and snippets.

@JPLeBreton
Created October 21, 2012 21:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JPLeBreton/3928640 to your computer and use it in GitHub Desktop.
Save JPLeBreton/3928640 to your computer and use it in GitHub Desktop.
shell script for streaming to twitch.tv
#! /bin/bash
# from
# https://gist.github.com/3178130
# gist created by brodul
# modified for http://twitch.tv/jplebreton
# originaly from http://tinyurl.com/twitch-linux from taladan
# www.youtube.com/user/taladan
# input and output video resolutions
INRES="1280x720"
OUTRES="640x360"
FPS="25"
# avconv presets - slow, medium, fast, faster, veryfast, superfast, ultrafast
# significant impact on stream quality!
# see all these in a terminal with "locate avpreset"
QUAL="veryfast"
# offsets from top left of screen to capture from
XOFF="128"
YOFF="128"
# how many cores your machine has - mine's quite wimpy!
CORES="2"
# audio offset from video must account for encode time
# use positive numbers if audio lags behind video
AUDIOOFFSET="00:00:01.00"
# audio sample rate
AUDIORATE="44100"
# mp3 encoder quality - 5 default, 7 faster
MP3QUAL="7"
# total bitrate of stream
BITRATE=768k
BUFSIZE=800k
# Write your key in a file named .twitch_key in your home directory
# This is your streamkey generated by jtv/twitch found at: http://www.justin.tv/broadcast/adv_other
STREAM_KEY=$(cat ~/.twitch_key)
avconv \
-f x11grab -show_region 1 -s $INRES -r "$FPS" -i :0.0+"$XOFF","$YOFF" \
-itsoffset "$AUDIOOFFSET" \
-f pulse -sample_rate "$AUDIORATE" -ar "$AUDIORATE" -i default \
-vcodec libx264 -s $OUTRES -preset "$QUAL" \
-acodec libmp3lame -ar "$AUDIORATE" \
-threads "$CORES" -vsync -1 -qscale "$MP3QUAL" \
-b "$BITRATE" -bufsize "$BUFSIZE" \
-f flv "rtmp://live.justin.tv/app/$STREAM_KEY"
# junk i commented out but want to keep around
#-f alsa -ac 2 -ar 44100 -i hw:0 \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment