Understand streaming media protocols RTMP and RTSP in seconds

2022.06.01
Understand streaming media protocols RTMP and RTSP in seconds

This article mainly introduces the streaming media protocol, TCP and UDP protocols, RTMP and RTSP protocols, RTMP and RTSP streaming media protocols have their own advantages.

RTMP and RTSP are two common streaming media protocols, so what is RTMP? What is RTSP? What is the difference between them? How to choose when using?

What is a streaming protocol?

Streaming media protocol, English scientific name Streaming Protocol, is explained in one sentence: Streaming media protocol is a protocol used to transmit multimedia through the Web.

Every time you watch a live or on-demand video, the technology behind it is the streaming protocol.

There are many streaming media protocols, which are mainly divided into three categories:

  • Traditional Video Streaming Protocol
  • HTTP-based adaptive protocol
  • new technology

Traditional Video Streaming Protocol

Traditional video streaming protocols mainly include:

  • RTMP
  • RTSP

HTTP-based adaptive protocol

The main adaptive protocols based on HTTP are:

  • Apple HLS
  • Low-Latency HLS
  • MPEG-DASH
  • Adobe HDS

new technology

The new technologies mainly include:

  • SRT
  • WebRTC

And what we mainly introduce and compare today is the traditional video streaming protocol: RTMP and RTSP.

TCP and UDP

Before discussing RTMP and RTSP, we need to understand TCP and UDP first, because RTMP is developed based on TCP, then RTSP uses UDP.

TCP

TCP English full name: Transmission Control Protocol, Chinese meaning: Transmission Control Protocol.

The TCP protocol is a transmission control protocol located between the application layer and the network layer, which is used to provide reliable streaming services, that is, to transmit data in the form of byte streams and receive data in the form of byte streams. TCP uses an acknowledgment mechanism to check that data arrived safely and reliably, multiplexing at the sender and demultiplexing at the receiver. TCP uses three phases to implement connection orientation functions such as connection establishment, data transfer, and connection termination.

UDP

UDP English full name: User Datagram Protocol, Chinese meaning: User Datagram Protocol.

UDP is a connectionless protocol, i.e. data is transferred from one end to the other; no connection needs to be established. UDP also sits between the application layer and the network layer. It also conveys data or information in the form of packets; these packets are called user datagrams. UDP uses multiplexing for outgoing user datagrams from multiple processes and demultiplexing for incoming user datagrams entering different processes on the same host.

Difference between TCP and UDP

  • TCP is connection oriented while UDP is connectionless
  • TCP is heavyweight while UDP is lightweight
  • TCP provides reliable service while UDP does not
  • TCP supports retransmission mechanism, while UDP does not
  • TCP packets arrive at the receiver in order, while UDP is out of order
  • TCP does not support broadcast while UDP supports broadcast
  • A TCP connection is a stream of bytes, while a UDP connection is a stream of messages

The above is the most basic part. Now I cut into today's topic: RTMP and RTSP protocols.

RTMP

  • English full name: Real Time Messaging Protocol
  • Chinese meaning: real-time messaging protocol
  • The underlying protocol: TCP
  • Application-level video streaming protocol
  • Video Codec: H.264
  • Audio Codec: AAC
  • Delay: 3 - 30 seconds

RTMP was born in 2005, developed by Macromedia and later acquired by Adobe, and has a long history in the streaming media market. Originally used to transfer data between RTMP servers and Flash players on user devices, Flash officially ended in 2020.

The biggest advantage of RTMP is that it can maintain a stable connection between the server and the client server, which allows seamless low-latency streaming regardless of the quality of the user's internet connection. This technique is mainly achieved by dividing the data stream into equal small parts (64 bytes by default for audio data and 128 bytes by default for video data) and transmitting them sequentially to the receiving device, and then reassembling them into a video stream.

How RTMP works 

Generally video streaming works like this:

  • webcam capture video
  • Stream video to video platform server via encoder
  • The video platform handles the video stream
  • Distributed via CDN to the server closest to the user
  • Finally, the video stream can successfully reach the user equipment

Then RTMP plays a very important role in this link. In the process of video from the camera to the server, RTMP divides a large amount of data into small pieces and transmits them across multiple virtual channels, providing stability between the video source and the RTMP server. and smooth video streaming.

The biggest disadvantage of RTMP is that it is not compatible with HTML5 players, in which case another protocol, such as HLS, must be used to transfer the video file to the user's device, in addition, RTMP is susceptible to bandwidth issues.

RTSP

  • English full name: Real Time Streaming Protocol
  • Chinese meaning: real-time streaming protocol
  • Underlying Protocols: TCP and UDP
  • network control protocol
  • Video Codec: H.265
  • Audio Codec: AAC
  • Delay: 2 seconds

RTSP was born in 1996 and was jointly developed by experts from RealNetworks, Netscape and Columbia University to control the entertainment and communication systems of VHS-style video streaming. RTSP uses the efficient RTP protocol to break the streaming data into smaller chunks, which can be more Deliver quickly.

RTSP supports reliable segmented streaming, which means users can continue watching the stream while still downloading it.

Android and iOS devices do not have RTSP compatible players out of the box, so the popularity is not high, but RTSP is widely used in many surveillance and closed-circuit television (CCTV) applications, such as remote cameras, online education, and Internet live broadcasts. more frequently.

As mentioned above, RTSP uses the RTP protocol to decompose video blocks. Here we will talk about the RTP protocol.

RTP protocol, English full name: Real-time Transport Protocol, Chinese is real-time transport protocol, its bottom layer is actually UDP, so that low latency can be achieved.

In addition to the RTP protocol, to ensure smooth and consistent streaming, RTSP uses two other network communication protocols:

  • TCP send and receive control commands (such as play or stop requests)
  • UDP transfers audio, video and data

How to understand this?

TCP reliable transmission, such as when the user presses play or stops playing, this is an accurate request, which needs to ensure reliability. At this time, the role of TCP is reflected.

UDP is a low-latency protocol, so it can be used to transmit audio, video and data very efficiently.

How RTSP works 

  • The user equipment sends an RTSP request to the video streaming platform
  • The video streaming platform returns a list of operable requests, such as play, pause, etc.
  • The user equipment sends specific requests to the video streaming platform, such as playback
  • The video streaming platform parses the request and invokes the specified mechanism to start video stream processing

Because RTSP relies on dedicated servers and relies on RTP, the protocol does not support encrypting video content or retransmitting lost packets.

Difference between RTMP and RTSP

1. Delay

RTMP: 3-30 seconds

RTSP: 2-5 seconds

2. Audio codec

  • RTMP: AAC, AAC-LC, HE-AAC+ v1 & v2, MP3, Speex, Opus, Vorbis
  • RTSP: AAC, AAC-LC, HE-AAC+ v1 & v2, MP3, Speex, Opus, Vorbis

3. Video codec

  • RTMP: H.264, VP8, VP6, Sorenson Spark®, Screen Video v1 & v2
  • RTSP: H.265 (preview), H.264, VP9, ​​VP8

4. Advantages

  • RTMP: low latency adaptability flexibility without buffering
  • RTSP: Low-latency segmented streaming

5. Disadvantages

  • RTMP: Bandwidth issues HTML5 not supported Compatibility issues with some browsers and devices Security is a bit low
  • RTSP:
  • HTTP incompatibility
  • Depends on other protocols

How to choose between RTMP and RTSP?

In fact, after reading the difference between RTMP and RTSP, you should have an insightful understanding of the usage scenarios.

  • IP cameras, IoT devices, then you can't go wrong with RTSP
  • If you are a third-party streaming media application, you can't go wrong with RTMP.

Summarize

This article mainly introduces the streaming media protocol, TCP and UDP protocols, RTMP and RTSP protocols, RTMP and RTSP streaming media protocols have their own advantages.

RTMP provides compatibility with different ingest devices and stability for low-latency streaming, however, you need a specific Flash Media Server to distribute your content using RTMP, so RTMP is suitable for major third-party streaming applications and older the hardware encoder;

RTSP works best with IP cameras and devices running IP cameras, such as drones.

Friends, do you understand?