This document provides clear instructions for developers to set up a MediaMTX RTSP and HLS streaming server, stream videos, and connect to the streams.
- Docker and Docker Compose installed on your machine.
- Video files to stream.
Organize your project directory as follows:
project-root/
│
├── docker-compose.yml
├── mediamtx.yml
├── videos/ # Directory for your video files
│ ├── video1.mp4
│ ├── video2.mp4
│ └── video3.mp4
├── scripts/ # Directory for preconfigured scripts (no need for user interaction)
│ └── start.sh
Place your video files into the videos/
directory. For example:
videos/
├── video1.mp4
├── video2.mp4
Run the following command to start MediaMTX and the FFmpeg streamer:
docker-compose up
- This will:
- Start the MediaMTX server for RTSP and HLS streaming.
- Use FFmpeg to stream videos from the
videos/
directory to the MediaMTX server.
To stop the containers, use:
docker-compose down
Use an RTSP-compatible player like VLC to connect to the RTSP stream. The URL format is:
rtsp://<YOUR_HOST>:8554/live/<VIDEO_NAME>
- Replace
<YOUR_HOST>
withlocalhost
or the IP address of your server. - Replace
<VIDEO_NAME>
with the name of your video file (without the extension).
Example:
If your video file is video1.mp4
and the server is on localhost
:
rtsp://localhost:8554/live/video1
You can access the HLS stream using a browser or HLS-compatible player. The URL format is:
http://<YOUR_HOST>:8888/live/<VIDEO_NAME>/index.m3u8
Example:
If your video file is video1.mp4
and the server is on localhost
:
http://localhost:8888/live/video1/index.m3u8
Defines the services:
mediamtx
for RTSP and HLS server.ffmpeg-streamer
for video streaming.
Custom configuration for MediaMTX (RTSP/HLS server).
Bash script to stream all videos in the videos/
directory to unique RTSP paths.
- To view logs for the MediaMTX server:
docker logs mediamtx
- To view logs for the FFmpeg streamer:
docker logs ffmpeg-streamer
- Ensure the
videos/
directory is properly mounted in the containers. - Check video compatibility with FFmpeg (
libx264
for video,aac
for audio).
- Add more videos to the
videos/
folder and restart the system withdocker-compose up
. - Use VLC, a browser, or any HLS/RTSP client to test the streams.