Streaming to Twitch.tv - SteamLUG/steamlug.org GitHub Wiki

#!/bin/bash
STREAM_KEY=$(cat ~/.twitch_key)
DATE=$(which date)
THREADS=0
RESO=1920x1080
RESOUT=1280x720
AUDIO=alsa
CHANNELS=2
SOUNDCARD=pulse
FPS=25
CRF=25
PRESET=ultrafast
FILTER="[1:0]setpts=PTS-STARTPTS[background];[2:0]setpts=PTS-STARTPTS,scale=240:-1[foreground];[background][foreground]overlay=main_w-overlay_w-2:main_h-overlay_h-2,format=pix_fmts=yuv420p,scale=1280:720"

DIRECTORY=/media/share/25-Capture/
FILENAME=videocast-`$DATE +%d%m%Y_%H.%M.%S`.mp4

ffmpeg -f $AUDIO -i $SOUNDCARD -f x11grab \
-r $FPS -s $RESO -i :0.0 -c:v libx264 -preset $PRESET -s $RESOUT \
-pix_fmt yuv420p -crf $CRF \
-c:a libmp3lame -b:a 96k -ar 22050 -threads $THREADS -f flv \
"rtmp://live.justin.tv/app/$STREAM_KEY"
# $DIRECTORY$FILENAME

# Without Webcam
#ffmpeg -f $AUDIO -ac $CHANNELS -i $SOUNDCARD -f x11grab \
#-r $FPS -s $RESO -i :0.0+1920 -vcodec libx264 -preset $PRESET -s $RESOUT \
#-crf $CRF -acodec libmp3lame -ab 96k -ar 22050 -f flv -threads $THREADS \
#$DIRECTORY$FILENAME
#"rtmp://live.justin.tv/app/$STREAM_KEY"

#-f video4linux2 -i /dev/video0 -filter_complex $FILTER
# With Webcam
#ffmpeg -f $AUDIO -ac $CHANNELS -i $SOUNDCARD -f x11grab \
#-r $FPS -s $RESO -i :0.0+1920 -f video4linux2 -i /dev/video0 -filter_complex "$FILTER" -vcodec libx264 -preset $PRESET -s $RESOUT -pix_fmt yuv420p \
#-crf $CRF -acodec libmp3lame -ab 96k -ar 22050 -threads $THREADS -f flv "rtmp://live.justin.tv/app/$STREAM_KEY"