Last active
April 24, 2022 09:03
-
-
Save hucancode/f0f690c107252933f6332809ddf90773 to your computer and use it in GitHub Desktop.
Cast your screen to Facebook Live. Require `ffmpeg`, `xrandr`, `x11grab`, an audio driver (default to `pulse`)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# -eq 0 ]] ; then | |
echo "Usage: $0 <API_KEY> [AUDIO_SOURCE_NAME] [OUTPUT_WIDTH]"; | |
exit 0; | |
fi | |
AUDIO_SOURCE_NAME=${2:-pulse}; | |
ALL_AUDIO=$(ffmpeg -sources alsa | while read -r line; do echo -e $(echo "$line" | cut -d ' ' -f1)" "; done); | |
AUDIO_SOURCE_FOUND=$(echo $ALL_AUDIO | grep $AUDIO_SOURCE_NAME); | |
if [ -z "${AUDIO_SOUCE_FOUND}" ]; then | |
echo -e "Can't find audio source $AUDIO_SOURCE_NAME, please select 1 from:\n$ALL_AUDIO"; | |
exit 0; | |
fi | |
DIMENTIONS=$(xrandr --current | grep '*' | uniq | awk '{print $1}'); | |
W=$(echo $DIMENTIONS | cut -d 'x' -f1); | |
H=$(echo $DIMENTIONS | cut -d 'x' -f2); | |
OUTPUT_WIDTH=${3:-$W}; | |
ffmpeg \ | |
-f alsa -ac 2 -i $AUDIO_SOURCE_NAME \ | |
-f x11grab -framerate 24 -video_size $DIMENTIONS \ | |
-i :0.0+0,0 -c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 3000k \ | |
-vf "scale=$OUTPUT_WIDTH:-1,format=yuv420p" -g 60 -c:a aac -b:a 128k -ar 44100 \ | |
-f flv "rtmps://live-api-s.facebook.com:443/rtmp/$1"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment