I'm using FFMPEG to convert my rtsp stream into an HLS stream so it can be played on all browsers on my website using player js. I'm having an issue with FFMPEG dying if the internet connection to the rtsp stream goes out for a min. Is there a way to make it reconnect? I've tried using the -reconnect flag before the -i flag, but I got back that the command wasn't found.

ffmpeg -i rtsp://rtspstreamaddress/1 -fflags flush_packets -max_delay 2 -flags -global_header -hls_time 2 -hls_list_size 3 -vcodec copy -y /var/www/video.m3u8

I then have a website that uses playwerjs to show the live stream. How can I make sure that the stream stays up without having to manually log into the VPS and rerun the script.

  • Have you looked at ffserver? It was designed for this sort of application.
    – Tyzoid
    May 10, 2017 at 0:05
  • I have. But I don't think ffserver will help with reconnects.
    – James
    May 10, 2017 at 3:18

2 Answers 2


I was able to create the following script that seems to be working for me. So far, it's been working for me.

!/bin/bash while : do ffmpeg -i rtsp://rtspstreamaddress/1 -fflags flush_packets -max_delay 2 -flags -global_header -hls_time 2 -hls_list_size 3 -vcodec copy -y /var/www/video.m3u8 done



-reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_on_network_error 1 -reconnect_on_http_error 1 -reconnect_delay_max 4096

need to be put after -i option like below:

ffmpeg -i rtsp://rtspstreamaddress/1 -reconnect 1 -reconnect_at_eof 1 -reconnect_streamed 1 -reconnect_on_network_error 1 -reconnect_on_http_error 1 -reconnect_delay_max 4096 -fflags flush_packets -max_delay 2 -flags -global_header -hls_time 2 -hls_list_size 3 -vcodec copy -y /var/www/video.m3u8

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .