This gist contains files to set up a media streaming server using Docker, GStreamer, and a looping script. The configuration allows you to stream media files using the Real-Time Streaming Protocol (RTSP). The goal is to stream two synchronized videos packed into an MKV container.
This Docker Compose file sets up two services:
- server: A media server using the
bluenviron/mediamtx
image. It listens on port 8554 for RTSP streaming. - streamer: A GStreamer-based streamer using the
restreamio/gstreamer
Docker image. It streams video files to the RTSP server.
Key parts of the docker-compose.yml
:
- Ports: The server exposes port
8554
for RTSP streaming. - Volumes:
./videos
directory is mounted to/opt/videos
in thestreamer
container. Place your video files here../loop_stream.sh
is mounted to/root/loop_stream.sh
in thestreamer
container. This script controls the streaming loop.
- Command: The
streamer
service runs theloop_stream.sh
script to start the streaming process.
A bash script that handles the looping of video streams using GStreamer. This script should be placed in the same directory as the docker-compose.yml
file. Make sure it has execution permissions.
Your directory should look like this:
.
├── docker-compose.yml
├── loop_stream.sh
├── videos
│ └── output.mkv
│ └── trimmed_SampleVideo.mp4
│ └── flipped_SampleVideo.mp4
│ └── big_buck_bunny_720p_30mb.mp4
docker-compose.yml
: Docker Compose configuration file.loop_stream.sh
: Script to loop video streaming.videos/
: Directory containing theoutput.mkv
file created by combining videos.
The videos were created using a sample video file from Sample Videos.
-
Download the Sample Video:
-
Create the Video Files:
- Trimmed Video: Extract the first 120 seconds of the sample video.
ffmpeg -i SampleVideo_1280x720_30mb.mp4 -t 120 -c copy trimmed_SampleVideo.mp4
- Flipped Video: Create a vertically flipped version of the first 120 seconds of the sample video.
ffmpeg -i SampleVideo_1280x720_30mb.mp4 -t 120 -vf "vflip" flipped_SampleVideo.mp4
- Combine into MKV: Combine the trimmed and flipped videos into a single MKV file, with both videos synchronized.
ffmpeg -i trimmed_SampleVideo.mp4 -i flipped_SampleVideo.mp4 -map 0:v -map 1:v -c copy output.mkv
- Trimmed Video: Extract the first 120 seconds of the sample video.
-
Place the MKV File:
- Place the
output.mkv
file in thevideos
directory that will be mounted into the Docker container.
- Place the
-
Prepare Your Environment:
- Ensure Docker and Docker Compose are installed on your system.
-
Place Your Video Files:
- Put the
output.mkv
file you created in thevideos
directory. You may need to create this directory in the same location as yourdocker-compose.yml
file.
- Put the
-
Run Docker Compose:
- Open a terminal and navigate to the directory containing
docker-compose.yml
. - Run the following command to start the services:
docker-compose up
- Open a terminal and navigate to the directory containing
-
Access the RTSP Stream:
- Once the services are running, you can access the RTSP stream at
rtsp://localhost:8554/stream1
.
- Once the services are running, you can access the RTSP stream at
-
Stop the Services:
- To stop the services, press
Ctrl + C
in the terminal where Docker Compose is running, or run:docker-compose down
- To stop the services, press
- You can customize the GStreamer pipeline in the
docker-compose.yml
file by editing thecommand
section under thestreamer
service. - Adjust the video source and streaming settings in
loop_stream.sh
to fit your requirements.
This gist is provided under the MIT License. See LICENSE for details.