RTMP Push and Pull Streaming
RTMP Introduction
RTMP is the de facto standard for live streaming and has been the most widely used live streaming protocol for many years.
However, Adobe has not continuously updated the RTMP protocol or submitted it to standard organizations such as RFC. As a result, many new features, such as HEVC or Opus, have not been supported. Until March 2023, the Enhanced RTMP project was finally established, starting to support HEVC and AV1. MMS and OBS now support HEVC encoding based on Enhanced RTMP.
In terms of stream production, SRT, WebRTC, and RIST have grown rapidly in recent years, and many devices now support SRT and RIST protocols. You can also use WebRTC for live streaming.
For stream distribution, HLS is the most widely used protocol, supported by all CDNs and devices, such as PC, iOS, Android, or tablets. Of course, HLS has relatively high latency (3-5s+). If you need lower latency, you can choose HTTP-FLV, HTTP-TS, or WebRTC.
To this day, RTMP is still the most widely used protocol in content production. For example, you can use OBS to push streams to platforms like Bilibili, WeChat Video Channels, or Kuaishou. If you want to connect to a broadcasting device or push streams to a platform, RTMP is the best choice, as it is almost universally supported.
Configuration
- Configure the RTMP port in
config/mms.yaml
:
rtmp:
enabled: on # Enable
port: 1935 # Listening port
out_chunk_size: 40960 # Output chunk size for the peer
- In addition, you need to add a configuration file for the streaming domain in the
config/publish
directory, namedtest.publish.com.yaml
. The program determines the domain name based on the file name, so keep it consistent with thename
field in the file. The simplest configuration is as follows:
type: publish # Domain type (publish for push, play for pull)
name: test.publish.com # Domain name
apps:
- name: app # Access point name (can have multiple)
- You also need to configure a playback domain in the
config/play
directory, with a configuration file namedtest.play.com.yaml
. The simplest configuration is as follows:
type: play # Domain type (publish for push, play for pull)
name: test.play.com # Domain name
publish_domain: test.publish.com # Bound push domain (source stream for playback)
apps:
- name: app # Access point name
- These two domains are custom-defined, so you need to configure DNS in the host file (in a production environment, DNS scheduling server handles nearby access):
192.168.108.130 test.publish.com
192.168.108.130 test.play.com
Push and Pull Streaming
- After configuration, start the server:
../bin/mms-live-server -c ../bin/config -d
-d
means all logs are printed on the console.
Then start OBS for stream pushing, filling in the stream URL:
rtmp://test.publish.com/app/test
.On Windows, launch PowerShell. Make sure ffmpeg or VLC is installed beforehand, then execute:
ffplay rtmp://test.play.com/app/test
to start playback.
- Note: If you use
ffplay rtmp://test.publish.com/app/test
for playback, it will fail.