Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#! /bin/bash
# streaming on Ubuntu via ffmpeg.
# see for full documentation
# see
# for instructions on how to use this gist
if [ ! -f ~/.twitch_key ]; then
echo "Error: Could not find file: ~/.twitch_key"
echo "Please create this file and copy past your stream key into it. Open this script for more details."
exit 1;
# input resolution, currently fullscreen.
# you can set it manually in the format "WIDTHxHEIGHT" instead.
INRES=$(xwininfo -root | awk '/geometry/ {print $2}'i)
# output resolution.
# keep the aspect ratio the same or your stream will not fill the display.
# input audio. You can use "/dev/dsp" for your primary audio input.
# target fps
# video preset quality level.
# more FFMPEG presets avaiable in /usr/share/ffmpeg
# According to the presets are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo
# stream key. You can set this manually, or reference it from a hidden file like what is done here.
STREAM_KEY=$(cat ~/.twitch_key)
# stream url. Note the formats for and
# twitch:"rtmp://$STREAM_KEY"
# justin:"rtmp://$STREAM_KEY"
ffmpeg \
-f alsa -ac 2 -i "$INAUD" \
-f x11grab -s "$INRES" -r "$FPS" -i :0.0 \
-vcodec libx264 -s "$OUTRES" -vpre "$QUAL" \
-acodec libmp3lame -threads 6 -qscale 5 -b 64KB \
-f flv -ar 44100 "$STREAM_URL"
Copy link

MadcowD commented Apr 5, 2018

To capture a window by name (in this example pygame window) with ffmpeg 3.1

ffmpeg \
-f alsa -ac 2 -i "$INAUD" \
-f gdigrab -i title="pygame window" -r "$FPS \
-vcodec libx264 -s "$OUTRES" -vpre "$QUAL" \
-acodec libmp3lame -threads 6 -qscale 5 -b 64KB \
-f flv -ar 44100 "$STREAM_URL"

Copy link

Muehlental commented Apr 6, 2021

I would like to stream live video of an ip camera to twitch so people will be able to watch there. As I am not very familiar with the comand line I tried winff. Unfortunately I am obviously lacking knowledge, so this does not help me. Can anyone advise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment