bluenviron / mediamtx

Ready-to-use SRT / WebRTC / RTSP / RTMP / LL-HLS media server and media proxy that allows to read, publish, proxy, record and playback video and audio streams.
MIT License
11.64k stars 1.47k forks source link

Feature request: run a command before connecting #3684

Open andreymal opened 3 weeks ago

andreymal commented 3 weeks ago

Describe the feature

I have an IP camera that is sometimes intentionally offline, but MediaMTX doesn't know this and floods the log with useless error messages:

2024/08/23 14:26:09 ERR [path mycamera] [RTSP source] dial tcp 192.168.6.66:554: connect: no route to host
2024/08/23 14:26:17 ERR [path mycamera] [RTSP source] dial tcp 192.168.6.66:554: connect: no route to host
2024/08/23 14:26:25 ERR [path mycamera] [RTSP source] dial tcp 192.168.6.66:554: connect: no route to host
...

To prevent this, I can make a script that waits until the camera is online:

#!/usr/bin/env bash
CAM_IP="$1"
until ping -c 1 -W 5 -- "$CAM_IP" >/dev/null; do
  sleep 30
done
sleep 1
echo "Camera $CAM_IP is online"

And it would be nice if MediaMTX could run such a script and wait for it to complete before connecting, something like:

paths:
  mycamera:
    source: rtsp://192.168.6.66/Streaming/Channels/101
    runBeforeInit: /usr/local/bin/camera-ping.sh 192.168.6.66
andreymal commented 3 weeks ago

(That stupid bot forced me to duplicate this post just because I didn't add the "Describe the feature" header...)