we are using FFmpeg for live streaming between two computers (point to point streaming) using TCP. The streaming works fine and we wanted to add support for two features:
- Save the stream locally in addition to streaming it to the remote pc
- Handle network interruptions
For the first item we started using the Tee Muxer and it solves the first problem. However, we didn't manage keep the connection alive during network interruptions , the stream doesn't recover if the network if disconnected more than ~10 seconds.
A little more technical information: The streaming ffmpeg command:
ffmpeg -f avfoundation -video_size 1280x720 -framerate 30.0 -pixel_format uyvy422 -i "0:0" -preset veryfast -c:v libx264 -c:a aac -b:a 128k -ac 2 -ar 44100 -pix_fmt yuv420p -b:v 500k -maxrate 500k -bufsize 1000k -sc_threshold 0 -g 60 -keyint_min 60 -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" -r 30.0 -f tee -map 0 "[onfail=ignore]test_new.ts|[f=fifo:fifo_format=mpegts:drop_pkts_on_overflow=1:attempt_recovery=1:recovery_wait_time=1:recover_any_error=1]tcp://[host]:[port]?timeout=900000000"
The receiving end:
ffmpeg -i tcp://host:port?listen&timeout=900000000&listen_timeout=300000 ...
After a few seconds , we get at the streaming end the following error:
Connection to tcp://[host]:[port]?timeout=900000000 failed: Network is unreachable
And the stream never recovers
We want to keep the tcp connection alive as long as possible (we choose 5 minutes for testing)
Does anyone know if this can be done and how?