Skip to content

Repository files navigation

Multi-Stream RTSP Launcher

License Platform

Overview

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 .mp4 files.
  • 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.

Usage

1. Download the tool and video assets

sima-cli install gh:sima-ai/tool-mediasources

2. Dependencies

  • 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)

3. Supported platforms:

  • Linux (Debian/Ubuntu, CentOS/RHEL)
  • macOS (via Homebrew)
  • Windows (manual install of FFmpeg, MediaMTX required)

4. Run with a media folder

./mediasrc.sh ../videos-480p30

Important

On Windows, open Powershell and run:

mediasrc.bat ..\videos-480p30

The 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-480p30

If the default RTSP port is already in use, choose another port:

RTSP_PORT=9555 ./mediasrc.sh ../videos-480p30

5. Preview the streams

open preview.html

mediasrc.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-480p30

UDP Preview Relay

mediasrc-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.

Start UDP relays

./mediasrc-udp.sh --streams 4 --port-base 5600

This 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/.

Preview the UDP-backed streams

open preview-udp.html

Dry-run the setup

./mediasrc-udp.sh --streams 4 --port-base 5600 --dry-run

Dry-run mode writes the runtime config and SDP files without starting MediaMTX or FFmpeg relay processes.

MJPEG HTTP Streams

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.

Start MJPEG HTTP streams

./mjpegsrc.py ../videos-multicodec

This exposes the detected AVI files as:

  • http://127.0.0.1:8002/src0.mjpeg
  • http://127.0.0.1:8002/src1.mjpeg
  • http://127.0.0.1:8002/src2.mjpeg

The server also provides:

  • http://127.0.0.1:8002/ - simple stream index
  • http://127.0.0.1:8002/streams.json - machine-readable stream list

To use another port:

./mjpegsrc.py --port 8003 ../videos-multicodec

About

mediasource tool streams multiple RTSP streams from files, support local preview

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages