4

I'm trying to configure restream server, ffmpeg listen on rtmp://ip:port and output to few stream services(youtube, twitch...etc) the problem is when I stop OBS streaming(using this on local pc) ffmpeg on server going down and i need manually run it next time I go stream. Can't find option in ffmpeg dock which will make ffmpeg continue listening even if input source go down. Maybe I'm missing something in docs or it's time to make scripts which will restart ffmpeg?

I'm using this command for ffmpeg:

ffmpeg -re -listen 1 -i rtmp://i.p:1234 -c:v libx264 -preset medium -maxrate 3500k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://live-ams.twitch.tv/app/key
Shadowraze
  • 65
  • 1
  • 6

1 Answers1

5

When you work with Linux, you could make a systemd services:

[Unit]
Description=ffmpeg listening and forward stream
After=syslog.target network.target

[Service]
PIDFile=/tmp/ffstreamer.pid
ExecStart= /usr/local/bin/ffmpeg -re -listen 1 -i rtmp://i.p:1234 -c:v libx264 -preset medium -maxrate 3500k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv rtmp://live-ams.twitch.tv/app/key

ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
User=www-data

[Install]
WantedBy=multi-user.target

When the input fails, it starts the process again.

jb_alvarado
  • 130
  • 2
  • 10