An RTSP server can deliver several media streams simultaneously and independently of each other. The RTSP server listens for connection requests on a TCP/IP port. An RTSP client (like the LEAD RTSP Source Filter) can connect and issue RTSP commands to the server. The most common commands are:
A server needs to respond to each of these commands.
The term "media stream" is used because the media being streamed can be a file or live stream. A live stream can be from a capture device, an MPEG-2 Transport Stream received over a UDP port, or an RTSP stream from another server. It can also be from a DVD image - anything that can be used to create an output file can also be used as a source media stream for an RTSP folder.
Typically, an RTSP server will stream all the files from a certain folder. However, not all compressions are supported by the RTSP streaming technology, so files with incompatible compressions need to be transcoded on the fly.
Currently, the LEAD RTSP Sink Filter supports both H264 and H265 video compressions, and AAC audio compression. Files with different video or audio compressions need to be transcoded to an RTSP-supported compression.
See the "RFC 2326 - Real Time Streaming Protocol (RTSP)" standard for more information on the RTSP specification.
RTSP servers provide a way to restrict access to content from unauthorized users. RTSP servers can optionally use authentication to identify users and then allow access only to authorized users. There are two authentication modes: Basic and Digest. In either mode, users have to enter a username and password before they can gain access to a media stream. Administrators can use different authentication methods and give different access rights to each media stream or the same access rights can be applied to all media streams.
The LEADTOOLS Multimedia SDK provides high-level objects that make it very easy to implement an RTSP server:
Suppose you want an RTSP server that streams all the files from "c:\MyFiles", and you want the server to listen on address 127.0.0.1 at port 554 (the default RTSP port). This RTSP server handles all RTSP URLs with the format,
rtsp://127.0.0.1/RelativeURL, as requests to stream the file
c:\MyFiles\RelativeURL. The C# code for a simple server would look like the following code:
// Error checking is suppressed here for brevity
// create the server instance
_server = new RTSPServer();
// specify c:\MyFiles as the source folder
// will listen on 127.0.0.1
_server.TargetAddress = "127.0.0.1";
// start listening on port 554
Here are some examples of using that server to stream files, along with the corresponding URLs:
Case 1: Stream a file from the root of the source folders
Connect with the LEAD RTSP Source and stream
c:\MyFiles\file1.mpg using the following URL:
When the LEAD RTSP server receives this URL, it will look for file1.mpg in all of the source folders. In this case, there is only one folder, so it will look for
Case 2: Stream a file
It is possible to use the same server to also stream from a live video capture device. All that is necessary is to run a capture from the video and audio capture that you have, and write it to a DVR file in
c:\Myfiles. The simplest way is to run the DVR demo, setting the output file to be something like
c:\MyFiles\LiveCapture2.lbl. To do this, use the RTSP Source Filter to stream the following URL:
Case 3: Re-stream an MPEG2 Transport UDP stream
Run the MPEG-2 Transport Stream and set its DVR settings to use
c:\MyFiles\UDPStream3.lbl. Then use the following URL in the RTSP Source filter:
Case 4: Stream a file from a subfolder of one of the source folders
If a subfolder is specified in the RTSP URL, the server will automatically search in subfolders. For example, you might want to keep the DVR files in different subfolders or you may want to reduce the number of files in the root folders.
To stream the file
c:\MyFiles\MySubfolder\file4.avi, use the following RTSP URL:
rtsp://127.0.0.1/MySubfolder/file4.avi. Note that the backslash that separates the source subfolder and filename is translated into a forward slash in the RTSP URL.
Case 5: Stream a file that is outside the source folders
Suppose you want to stream a file on another disk (for example,
f:\abc\def.mkv). In this case, create a link called
c:\MyFiles\MyLink5.lnk and make it point to
f:\abc\def.mkv. Next, use the following URL:
This applies to DVDs as well: you can create a link to
c:\MyFiles\MyDvd5.lnk. This makes it possible to stream it using the following URL:
rtsp://127.0.0.1/MySubfolder/MyDvd5.lnk. In this case, keep in mind that the DVD will be recompressed on the fly and DVDs take time to start playing. Consequently, a timeout may need to be specified on the RTSP URL to instruct the RTSP filter to wait for the DVD to begin converting. The following URL would tell the RTSP server to wait 10 seconds before giving up:
When high-level RTSP objects are streaming a growing DVR file, they will start streaming from the live position. This makes it possible to implement live streaming with the RTSP server. When streaming live DVR, all clients see the same video, regardless of how long ago they connected to the RTSP server.
If you are streaming a DVR file that is not growing anymore, the clients will start playing the video from the beginning of the DVR buffer.
When re-streaming an MPEG-2 Transport UDP stream, it is best to stream it as a DVR file because the LEAD MPEG-2 Transport UDP Source filter uses DVR files to store the data.