Skip to content

Instantly share code, notes, and snippets.

@robvanderleek
Last active April 13, 2022 03:14
Show Gist options
  • Save robvanderleek/364b527e2ce2f557cf13baf321c472a2 to your computer and use it in GitHub Desktop.
Save robvanderleek/364b527e2ce2f557cf13baf321c472a2 to your computer and use it in GitHub Desktop.
Simple RTSP test server

Simple RTSP test server

Sometims you just need to have a local RTSP stream to test your software against. The attached script start-rtsp-stream.sh does just that. It requires Docker and ffmpeg and can be launched with zero arguments to give you an RTSP stream of a looped video:

$ ./start-rtsp-stream.sh
Stopping server (if running)...
Starting simple RTSP server...
Starting video stream at: rtsp://localhost:8554/live.stream

You can also launch the script with a local video file (or video URL) as the single argument:

$ ./start-rtsp-stream.sh test.mp4
Stopping server (if running)...
Starting simple RTSP server...
Starting video stream at: rtsp://localhost:8554/live.stream
#!/bin/sh
#
# This script will start a simple test RTSP server with a single, looped video
# stream. By default you can find the stream at:
#
# rtsp://localhost:8554/live.stream
#
# You can also call this scipt with a different video file/url:
#
# $ ./start-rtsp-stream.sh test.mp4
#
# Below are some configuration options.
#
RTSP_PORT=8554
RTSP_STREAM_NAME=live.stream
INPUT=https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_640_3MG.mp4
function stop_server() {
echo "Stopping server (if running)..."
docker kill rtsp-simple-server >/dev/null 2>&1
docker rm rtsp-simple-server >/dev/null 2>&1
}
trap stop_server EXIT
stop_server
# Configure to stream over TCP, not UDP
TMPFILE="/tmp/rtsp-simple-server.yml.$$"
echo "protocols: [tcp]\n" > $TMPFILE
trap "rm -f $TMPFILE" EXIT
echo "Starting simple RTSP server..."
docker run \
-d --name rtsp-simple-server \
-v $TMPFILE:/rtsp-simple-server.yml \
-p 8554:$RTSP_PORT aler9/rtsp-simple-server >/dev/null
if [ "$#" -gt "0" ]; then
INPUT=$1
fi
rtsp_url=rtsp://localhost:$RTSP_PORT/$RTSP_STREAM_NAME
echo "Starting video stream at: $rtsp_url"
ffmpeg \
-v quiet \
-re -stream_loop -1 -i $INPUT -f rtsp \
-rtsp_transport tcp $rtsp_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment