The Multi-Stream RTSP Launcher is a Bash tool designed to quickly stand up an MediaMTX RTSP server and stream multiple video files over RTSP using FFmpeg.
It automatically:
- Installs FFmpeg and MediaMTX if not already available.
- Starts a local RTSP server (
rtsp://<local-ip>:9554/). - Scans a media folder for
.mp4files. - Streams each file as a unique RTSP source (
/src0,/src1, …). - Keeps processes alive and logs FFmpeg output to
/tmp/ffmpeg_src<N>.log.
This is particularly useful for testing multi-channel video pipelines and validating AI/vision workloads that depend on live RTSP streams.
sima-cli install gh:sima-ai/tool-mediasources- FFmpeg → Installed automatically if missing (apt-get, yum, or brew).
- MediaMTX → Downloaded and installed automatically from GitHub releases.
- Bash 3.2+ (compatible with the default macOS
/bin/bash)
- Linux (Debian/Ubuntu, CentOS/RHEL)
- macOS (via Homebrew)
- Windows (manual install of FFmpeg, MediaMTX required)
./mediasrc.sh ../videos-480p30Important
On Windows, open Powershell and run:
mediasrc.bat ..\videos-480p30The folder should contain one or more supported media files (.mp4, .m4v,
.mov, .avi, or .mkv).
Each file will be exposed as its own RTSP stream.
The launcher runs in foreground mode and detects the video codec for each file. It streams the encoded video from the file directly over RTSP without transcoding:
- H.264 inputs are preserved as H.264 RTSP streams.
- HEVC inputs are preserved as HEVC RTSP streams. Browser preview depends on client HEVC support.
- MJPEG inputs are preserved as MJPEG RTSP streams. MJPEG is useful for RTSP camera simulation, but browser WebRTC preview may not display those sources.
Press Ctrl+C to stop all launched stream publishers:
./mediasrc.sh ../videos-480p30If the default RTSP port is already in use, choose another port:
RTSP_PORT=9555 ./mediasrc.sh ../videos-480p30open preview.htmlmediasrc.sh automatically writes preview-config.js so preview.html
uses the detected number of input videos, prints the preview page URL, and
opens it in your browser when possible.
To skip opening the browser automatically:
OPEN_PREVIEW=0 ./mediasrc.sh ../videos-480p30mediasrc-udp.sh is a companion launcher for live publishers that already emit
H.264 over RTP/UDP. It creates one MediaMTX relay per UDP input port and writes
preview-udp-config.js so the browser grid can open the matching WebRTC paths.
The UDP launcher expects ffmpeg and mediamtx to already be available in
PATH.
./mediasrc-udp.sh --streams 4 --port-base 5600This reserves the following inputs by default:
- UDP
5600-> RTSP/WebRTC path/udp0 - UDP
5602-> RTSP/WebRTC path/udp1 - UDP
5604-> RTSP/WebRTC path/udp2 - UDP
5606-> RTSP/WebRTC path/udp3
--port-base must be even. Each relay reserves an RTP/RTCP port pair, so the
odd port beside each listed RTP port is left available for RTCP.
Generated SDP files and relay logs are written under .mediasrc-udp/.
open preview-udp.html./mediasrc-udp.sh --streams 4 --port-base 5600 --dry-runDry-run mode writes the runtime config and SDP files without starting MediaMTX or FFmpeg relay processes.
mjpegsrc.py is a companion HTTP launcher for MJPEG AVI files. It is separate
from mediasrc.sh because it does not publish RTSP streams through MediaMTX.
Instead, it exposes .avi files as browser-readable multipart MJPEG HTTP
streams on port 8002.
The input folder may contain mixed media files. mjpegsrc.py only uses .avi
files whose first video stream is MJPEG; other files are ignored.
./mjpegsrc.py ../videos-multicodecThis exposes the detected AVI files as:
http://127.0.0.1:8002/src0.mjpeghttp://127.0.0.1:8002/src1.mjpeghttp://127.0.0.1:8002/src2.mjpeg
The server also provides:
http://127.0.0.1:8002/- simple stream indexhttp://127.0.0.1:8002/streams.json- machine-readable stream list
To use another port:
./mjpegsrc.py --port 8003 ../videos-multicodec