How to run an RTSP Media Server [deprecated]
Before you read, know that the solution I’m proposing in this article is no longer maintained, as I am no longer able to work on it. If you are a C++ developer comfortable working with GStreamer and that you feel like becoming an open source maintainer, please fork the repository and keep the project alive 🙏
This story is targeted to a really niche audience, but I think it addresses a problem that doesn’t currently have any satisfying answer, as far as I could see when I was asking this question myself.
RTSP stands for Real Time Streaming Protocol, it’s a protocol that is widely used by video surveillance cameras, but also for streaming media on the internet, doing video calls, and other applications.
I recall originally using the excellent VLC for serving video over RTSP, and one day I needed it to have authentication, which VLC didn’t seem to handle. I entered the VLC IRC server, and asked them if I could help implementing it. They answered something along the lines of “Only mad people use this anyway, but sure go ahead, it’s in this file.” and pointed me to a 5 000 lines, 10 year old C file.
Another thing to note is that the command that I used to run my media server was very complicated, check it out:
I did some more research to try and find a way to have an RTSP server with authentication, and there were a few candidates:
live555
was the most obvious one, but it had a huge problem: it is very badly documented. Their FAQ literally says:
The best way to understand how to use the libraries is to study the example programs in the “testProgs” directory, study the library code itself, and ask questions on the “live-devel” mailing list.
Also, it wasn’t simple to use at all.ffserver
seemed perfect, was made by the same people as the universally acclaimedffmpeg
but it was deprecated and development stopped. I tried using the latest version but ran into a few problems, so I decided to keep looking.gst-rtsp-server
is a reliable solution, used by many professional software, but unfortunately it’s not easy to use because it’s a library and requires you to write C/C++ code to build your own server.
Which is why I made my own Media Server
I wanted to make something completely cross-platform, easy to use, that has a lot of features and that is performant. Here is the result: RTSPAllTheThings.
It’s far from perfect, but it does what it’s been designed for. It’s a simple Media Server that was written using the gst-rtsp-server
library and that can be used with a Docker image.
It handles authentication (basic and digest), can stream input files, preset video patterns (a ball that moves, white noise, etc.), the video feed from a device, or even relay another RTSP stream. You can also add a time overlay, change the frame rate of the video or change the stream’s resolution.
Now to get the same video stream as I did with the very long command using VLC above, I just need to run docker run --rm -p 8554:8554 ullaakut/rtspatt
.
A more complex command, that would handle authentication, serve a video file and set a custom address and port would be docker run --rm -e INPUT="/tmp/video.avi" -e RTSP_ADDRESS=172.100.100.12 -e RTSP_PORT=18554 -v "/path/to/your/video:/tmp/video.avi" -p 18554:18554 ullaakut/rtspatt
Conclusion
The problem is still there though, my software doesn’t have enough features at the moment to be a universal solution, and there doesn’t seem to be any other solution that are easy to use and work out of the box. Right now, if you have a specific need that isn’t covered by RTSPATT and that you don’t have the time/knowledge to use gst-rtsp-server or live555, let me know by creating an issue on RTSPATT, and maybe I’ll be able to help you out.
If you know of a better solution, please leave a comment on this article to tell me about it, and I’ll probably rewrite this article with it in mind. Also, if you’d like to help me build a solution to this problem, you are more than welcome to contribute.
Tap the 👏 button if you enjoyed this article :)