Skip to content

Instantly share code, notes, and snippets.

@sgdc3
Last active September 21, 2022 03:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgdc3/a782013c43037fb0ff03e8cd2d4017fc to your computer and use it in GitHub Desktop.
Save sgdc3/a782013c43037fb0ff03e8cd2d4017fc to your computer and use it in GitHub Desktop.
Restream: a simple bash script to split an rtmp video stream by using ffmpeg.
#!/bin/bash
LISTEN_URL='rtmp://0.0.0.0:5555'
# Youtube stream
YT_URL='rtmp://a.rtmp.youtube.com/live2'
YT_VIDEO_ARGS='-c:v copy'
YT_AUDIO_ARGS='-c:a copy'
# Keys
YT_KEY1=''
YT_KEY2=''
# Facebook stream
FB_URL='rtmp://rtmp-api-dev.facebook.com:80/rtmp/'
FB_VIDEO_ARGS='-c:v libx264 -preset -vf scale=-1:720:flags=lanczos -maxrate 4000k -bufsize 8000k -r 30 -g 60'
FB_AUDIO_ARGS='-c:a aac -b:a 128k -ac 1 -ar 48000'
# Keys
FB_KEY1=''
FB_KEY2=''
# Run ffmpeg inside a screen, useful for ssh sessions
screen -S restream ffmpeg -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_delay_max 2 -i $LISTEN_URL \
$YT_VIDEO_ARGS $YT_AUDIO_ARGS -f flv [onfail=ignore]$YT_URL/$YT_KEY1 \
$YT_VIDEO_ARGS $YT_AUDIO_ARGS -f flv [onfail=ignore]$YT_URL/$YT_KEY2 \
$FB_VIDEO_ARGS $FB_AUDIO_ARGS -f flv [onfail=ignore]$FB_URL/$FB_KEY1 \
$FB_VIDEO_ARGS $FB_AUDIO_ARGS -f flv [onfail=ignore]$FB_URL/$FB_KEY2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment