Home

now

wiki

about


ffstream tools

ffstream is really a loose collection of scripts and miscellaneous files, and is my setup for streaming (to twitch.tv in my case) using ffmpeg! At the moment the main section is stuff which "just works" (lol not really) and an extra/ directory for experimental ffmpeg ramblings. The long-term goal is to turn it into a compiled, cross-platform application which is actually useful, but the short-term goal is to actually have something working :)

This project started because my laptop page coming soon :) really struggles to run OBS and any other software, so streaming games and such was never really feasible. However, after messing around with ffmpeg to encode video and such for months, I realized its (commonly) untapped potential for streaming!

ffmpeg is an incredibly impressive piece of software; it can convert from basically any format to any other with more options than almost anyone will ever use, and that's still not the coolest thing it can do! Unfortunately I won't be going over ffmpeg's awesome complex filter system in this article, as it's a little outside of the scope :/

The current main tool in this repo is the script ffst-main, which is a pretty basic script to stream your desktop to twitch. It's only 14 lines, and could be 1 if I didn't care about readability :)

#!/bin/bash

dunstify "starting stream"

size=$(xrandr | head -n1 | cut -d, -f2 | cut -d" " -f3-5 | sed 's/ //g')

ffmpeg -f x11grab \
  -video_size $size \
  -framerate 24 -i $DISPLAY \
  -f alsa -ac 2 -i pulse -acodec aac \
  -vf scale=1280x720 \
  -c:v h264 -g 24 -b:v 2M \
  -preset ultrafast -vb 3200k \
  -c:a aac -pix_fmt yuv420p \
  -f flv "rtmp://live-lax.twitch.tv/app/$STREAM_KEY"

The dunstify call is mostly to let me know the script is still working, and you could replace the size variable with a hardcoded value of your display's dimensions. Most of the ffmpeg flags just set formats and such, but a few flags deserve explanation

-f x11grab
uses the x11 server api to get desktop video
-video_size $size ... -i $DISPLAY
using x11grab, sets the video dimensions to your screen's values, and the input to your current display
-f alsa -ac 2 -i pulse -acodec aac
adds a second input for desktop audio from alsa and pulseaudio
-f flv "rtmp://live-lax.twitch.tv/app/$STREAM_KEY"
sets the output format to one commonly supported by streaming sites, and the output source to twitch
Incoming:

projects