Skip to content

Instantly share code, notes, and snippets.

@hoangdh
Last active October 27, 2023 02:05
Show Gist options
  • Save hoangdh/58bcac949030d0e53bdfc1f6648f320d to your computer and use it in GitHub Desktop.
Save hoangdh/58bcac949030d0e53bdfc1f6648f320d to your computer and use it in GitHub Desktop.
Livestream to Facebook from YouTube's videos.
#!/bin/bash
FFMPEG=`which ffmpeg`
YOUTUBEDL=`which yt-dlp`
KEY=""
RTMP_SERVER="rtmps://live-api-s.facebook.com:443/rtmp"
V="$1"
A="$2"
if [ -z "$2" ]
then
A="$1"
fi
echo "Getting your audio..."
AUDIO=$($YOUTUBEDL -f 'bestaudio[ext=m4a]' $A --get-url)
echo "Getting your video..."
VIDEO=$($YOUTUBEDL -f 'bestvideo[height=1080]' $V --get-url)
if [ "$3" == "debug" ]
then
# $FFMPEG -re -i "$VIDEO" -i "$AUDIO" -c:v libx264 -b:v 1.5M -preset ultrafast -c:a copy -shortest -f flv "${RTMP_SERVER}/${KEY}"
$FFMPEG -re -i "$VIDEO" -i "$AUDIO" -c:a copy -ac 1 -ar 44100 -b:a 96k -vcodec libx264 -pix_fmt yuv420p -tune zerolatency -shortest -f flv -maxrate 2M -preset veryfast "${RTMP_SERVER}/${KEY}"
else
$FFMPEG -re -i "$VIDEO" -i "$AUDIO" -c:v libx264 -b:v 2M -preset ultrafast -c:a copy -shortest -f flv "${RTMP_SERVER}/${KEY}" > /dev/null 2>&1 &
fi
if [ $? -lt 0 ]
then
echo "ERROR: Please debug."
else
echo "Streaming from YouTube to Facebook."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment