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
10.74k
stars
1.4k
forks
source link
Regarding setting up a fallback for multiple RTSP streams proxied through MediaMTX #3267
Originally posted by **leysjeremy** April 16, 2024
### Question
I've hit a snag with my MediaMTX setup while attempting to initiate a fallback stream using FFmpeg with the runOnInit directive. It appears that the environment variables $RTSP_PORT and $MTX_PATH aren't initialized when runOnInit triggers the command.
My goal is to have MediaMTX manage RTSP streams and establish a fallback stream through FFmpeg that kicks in automatically upon MediaMTX startup. The aim is to seamlessly switch to the fallback stream if any of the primary streams encounter issues.
Expected Behavior:
1. MediaMTX serves primary RTSP streams (stream1 and stream2).
2. If primary streams fail, RTSP clients smoothly transition to a fallback stream (fallbackpath).
3. The fallback stream, configured with FFmpeg, should utilize environment variables ($RTSP_PORT and $MTX_PATH) to dynamically form the RTSP URL.
4. RTSP clients enjoy uninterrupted playback by automatically alternating between primary and fallback streams.
Here's a simplified version of my YAML configuration:
```
fallbackpath:
runOnInit: ffmpeg -re -stream_loop -1 -i "/path/to/fallback/video.mp4" -c:v copy -an -f rtsp "rtsp://127.0.0.1:$RTSP_PORT/$MTX_PATH"
runOnInitRestart: yes
paths:
# Primary streams
stream1:
source: rtsp://example.com/stream1
fallback: fallbackpath
stream2:
source: rtsp://example.com/stream2
fallback: fallbackpath
# More streams...
```
However, it seems that $RTSP_PORT and $MTX_PATH aren't available when runOnInit is triggered, resulting in errors.
I've attempted using the runOnDemand directive as an alternative, but I'm uncertain if it's suitable for my scenario. Unfortunately, both runOnInit and runOnDemand configurations fail, causing MediaMTX to abort.
I'd appreciate any guidance on ensuring that the environment variables are properly initialized when starting the fallback stream.
Thanks for your assistance!
This issue is being automatically closed because it does not follow the issue template.
Please reopen the issue and make sure to include all sections of the template.
Discussed in https://github.com/bluenviron/mediamtx/discussions/3251