Last active
September 21, 2022 03:09
-
-
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.
This file contains hidden or 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 | |
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