Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

RTSP -> HLS using FFMPEG

Writer Emily Wong

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.

2

2 Answers

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

option:

-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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy