Let's compare the RTMP and RTSP streaming protocols. We will tell you how they work, what are the pros and cons of each. We will show you how to choose in your case.
If you want to run a video streaming platform
with minimum latency, you will have a very limited number of streaming protocols for this task. At the same time, if you want to use the Internet as a video stream transmission channel, the choice will be even less, since you will need to overcome a number of difficulties, for example, jitter, lags or packet loss. In this article, we will compare two such communication protocols - RTMP and RTSP, describe their advantages with disadvantages, and also give some recommendations on choosing the most suitable option for you.
What is communication protocol
Latency when streaming data via popular communication protocols. Source
First of all, it is worth clarifying that both RTMP and RTSP are streaming protocols, which means that they are collections of certain logical layer interface conventions that define a method for transferring video, audio, and other types of data between different platforms, systems or devices. These rules are needed to set the standard for the transmission of information and error handling, which is necessary for the normal operation of any video broadcast.
If you compare the videos you want to send to viewers with a car, the streaming protocol is the traffic rules and the road that the car takes from one place to another. If the road is good, the car will reach its destination without any problems. If there are hollows and holes on the road, the movement will take longer and the car may be damaged.
With video data, everything is the same: if the protocol is good, the video signal will reach the viewer with minimal delay and will be of high quality. If the protocol is poorly implemented or does not correspond to the task, then the video on the viewer's screen may "crumble", often interrupt for loading, contain artifacts, not load at all, or audio and video signals will be out of sync.
Different streaming protocols target different aspects of the stream (tasks). They are usually divided into adaptive bitrate protocols, which are aimed at reducing delays and buffers for the video stream, and those aimed at minimizing latency, which allows the video signal to be transmitted to viewers in almost real time - live streaming.
RTMP and RTSP are perhaps the two most common protocols focused on low latency video streaming. And although they are designed to achieve similar goals, close comparison between them makes it easy to find significant differences that are important to know.
What is RTMP and how does it work
Real Time Messaging Protocol, or RTMP, is a standardized protocol for transferring multimedia data over the Internet. This technology was developed by Macromedia (currently owned by Adobe) and was originally used to transfer data between an RTMP server and a Flash player on the user's device. Flash is no longer used due to security concerns, but RTMP is still popular.
As a communication protocol, RTMP technology aims to provide stable and smooth transmission of the increasing amounts of data required to transmit and receive video in real time. This is achieved by fragmenting the data stream into small equal parts (the default is 64 bytes for audio data and 128 bytes for video data) and their sequential transmission to the receiving device, which then reassembles them into a video stream.
After Flash became outdated in 2020 (Google and other big players stopped supporting Adobe Flash Player altogether), RTMP was used as an open source protocol for the first mile contribution (transfer from the encoder to the network video host). This is how RTMP is currently used by Facebook, YouTube, Periscope and most other platforms.
RTMP currently exists in 5 variants:
How RTMP streaming works
Typically, live video streaming works like this: a camera captures video (or a video card captures the screen) and sends it to the host or video platform
server through an encoder (this step is commonly referred to as the "first mile"). Then the server or video platform processes this stream and transmits it further through the content delivery network (CDN) to distribute the video stream to users' devices (this is the "last mile"). When Flash was still running, both of these steps went through RTMP, but since Flash became outdated, RTMP no longer works on the "last mile". From this point on, the stream must intercept another communication protocol (HLS, MPEG-DASH, CMAF or WebRTC).
The diagram shows four distinct stages in the real-time video delivery chain. The first stage is usually called the "first mile" (video transmission from the camera to the server), and the fourth is called the "last mile" (the video is delivered to the user's screen, for example, a TV). Source
On the first mile, however, RTMP is still relevant as it does an excellent job of providing a stable and smooth video stream between the video source and the RTMP server by splitting large amounts of data into small blocks and transferring it across multiple virtual channels. Moreover, RTMP also opens up a persistent connection between the stream source and the server, allowing the protocol to act as a carrier for delivering data packets.
RTMP packets are delivered in a few seconds in three stages:
- TCP/IP handshake. The client and the server exchange information with each other to "negotiate" the transfer of the stream.
- Establishing a connection. Client and server agree on all parameters and connection specifications using a sequence of messages.
- Stream transmission. The client sends a "create Stream" call to the server followed by a ping message and replay.
RTMP advantages and disadvantages
So, these are the benefits of using RTMP:
- Low latency. In terms of live broadcasts, low latency basically means a reliable connection that won't drop even if the channel between the server and the viewer is a bit unstable. This metric is also extremely important for video quality. RTMP provides a stable connection due to the fact that it is created on TCP by default, while low latency is achieved by using the exclusive 1935 port, which eliminates the need to buffer the video stream.
- Adaptability. In a broadcast context, adaptability means being able to connect to and disconnect from a broadcast whenever they want, and users can also skip backward (and then forward) and join the live stream once it starts. These are very useful features for online conferencing, live streaming, video game streaming and simple video calling.
- Flexibility. RTMP technology allows integrating various types of multimedia content into one coherent package, seamlessly mixing video, audio and text (subtitles) on the viewer's screen. In addition, the protocol supports audio streams in AAC and MP3 formats, and formats such as MP4, FLV and F4V can be used for video transmission.
The disadvantages of using RTMP technology are as follows:
- No HTML5 support. RTMP is not supported by HTML5 players, which are currently the industry standard for user-side video playback (in Mozilla, Google, Microsoft, Apple, and Opera browsers). To "convert" an RTMP stream to HTML, you need a convector, such as HLS (Http Live Stream protocol developed by Apple).
- Bandwidth issues. RTMP has some low bandwidth vulnerabilities. They can cause intermittent interruptions in video streaming, which tend to spoil the video viewing experience.
- Incompatibility with HTTP. The last drawback of RTMP is the inability to transmit an RTMP stream over HTTP. To publish an RTMP stream on a site, you need to implement a dedicated server such as Flash Media Server and use a CDN or video streaming platform.
What is RTSP and how does it work
Real Time Streaming Protocol, or RTSP, is a less well-known set of rules for streaming video over the Internet than RTMP. Introduced by RealNetworks, Netscape and Columbia University in 1996 to control entertainment and communications systems for VHS-style video streaming. This implies that during streaming, the RTSP server can process commands on the VHS console: "Play", "Pause", "Stop", as well as "Scroll forward" and "Scroll backward".
To ensure smooth and consistent streaming, RTSP uses two other network communication protocols - TCP to issue and receive control commands (such as a play or stop request) and UDP (User Datagram Protocol) to deliver audio, video, and data. Thanks to this, the client can start playing the RTSP stream while downloading the stream.
Although RTSP can be used for both live broadcasts and video-on-demand, it is now commonly used in the last mile to transfer a video stream from the cloud to the player of the user's device, since this protocol allows the viewer to play, pause and rewind the video. In addition, RTSP is also popular in systems where you need to transmit video signal from cameras over IP, for example, from IP cameras or CCTV cameras.
How RTSP streaming works
RTSP video transmission scheme. Source
The RTSP communication protocol works as follows. When a user (program, app, or camera) wants to transmit a video signal from a remote source, the user device sends an RTSP request to a dedicated server (or video streaming platform) to determine the available options such as play, pause, rewind, and record. Then the server returns a signal to the device with a list of requests that it can receive via RTSP.
Once the device (player) knows the list of commands and how to make the request, it sends a request for the description of the video content to the streaming server, and the server responds with a description of this media. Then the device sends a download request, and the server responds with information about the transport mechanism, and then the video streaming process is initiated through the specified mechanism.
Since RTSP depends on a dedicated server and relies on RTP, this protocol does not support encrypting video content or retransmitting lost packets. In addition, RTSP is not HTTP compatible, hence it does not allow for direct playback of the video stream in a web browser. To do this, you need to convert the video stream through a special intermediate server.
Advantages and disadvantages of RTSP
The main advantages of using RTSP are as follows:
- Segmented streaming. This means that you can watch the video without having to download it in its entirety before watching, which is convenient if you need to organize the transmission of video on demand.
- Setting. RTSP allows you to create your own video streaming applications that take the TCP + UCD multi-protocol approach - from video messengers to online video conferencing software.
Here are some of the disadvantages of using RTSP streams:
- Less popularity. Most web browsers, video players, and streaming services do not support RTSP, making it difficult to stream the video signal directly to the browser. To do this, you need to use the dedicated RTSP Live Streaming Service.
- Incompatibility with HTTP. Since RTSP was originally created for use on private networks, you cannot directly stream RTSP over HTTP. To do this, you need special software that will receive a video stream from an RTSP server, embed it on a web page and allow viewers to play it on their screens.
RTMP vs RTSP specifications
Which protocol is best for you
In the vast majority of cases, the choice between RTMP and RTSP is determined by the project task and the devices used to stream video in real time. Here are some guidelines on when to use which video streaming protocol to use in your case.
IP cameras → RTSP
. Almost all IP cameras support RTSP, which is due to the fact that IP cameras existed long before the creation of the RTMP protocol. And since RTSP was (and still is) a fairly simple and effective tool for transmitting video signals, there is no need to change anything.
In conjunction with RTSP and IP cameras, the IP camera itself acts as an RTSP server. This means that to connect a video camera to the IP camera server and broadcast video, you need to launch an RTSP client, for example, via Restreamer Red5 Pro. This plugin allows you to connect to the stream as a client and redirect it to other endpoints that support Red5 Pro (a browser that works with WebRTC).