Skip to content

Instantly share code, notes, and snippets.

@mdcfe
Created December 11, 2016 20:48
Show Gist options
  • Save mdcfe/ec2018f036d01b91f5d38177e373aef8 to your computer and use it in GitHub Desktop.
Save mdcfe/ec2018f036d01b91f5d38177e373aef8 to your computer and use it in GitHub Desktop.
Facebook to YouTube Live relay
#! /bin/bash
sudo apt-get install vlc livestreamer jq # in case the packages aren't installed - replace with package manager of choice if not using apt
LSPORT='40106' # change this to any unused port on your machine
PATHTOFILE='http://localhost:'${LSPORT} # don't touch
STREAMID='fill-this-in12-3456' # find this on your YouTube livestreaming dashboard
FBVID='00000000000000000' # the ID of the FB video to stream, can be live or not live
STREAM=$(curl -s 'https://www.facebook.com/video/video_data/?video_id='${FBVID} | jq -r '.hd_src') # change '.hd_src' to '.sd_src' if you have a poor connection
echo ${STREAM}
# Capture the Facebook livestream
sleep 1s
livestreamer "${STREAM}" best --player-external-http --player-external-http-port ${LSPORT} & # you can try changing 'best' to 'worst' if you have a poor connection
# Output to YouTube
sleep 5s # give livestreamer a chance to start
cvlc "${PATHTOFILE}" --sout '#transcode{vcodec=h264,acodec=mp3,samplerate=44100}:std{access=rtmp,mux=ffmpeg{mux=flv},dst=rtmp://a.rtmp.youtube.com/live2/'${STREAMID}
# ctrl-c to kill the stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment