Skip to content

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

  1. Configure the RTMP port in config/mms.yaml:
yaml
rtmp:
  enabled: on               # Enable
  port: 1935                # Listening port
  out_chunk_size: 40960     # Output chunk size for the peer
  1. In addition, you need to add a configuration file for the streaming domain in the config/publish directory, named test.publish.com.yaml. The program determines the domain name based on the file name, so keep it consistent with the name field in the file. The simplest configuration is as follows:
yaml
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)
  1. You also need to configure a playback domain in the config/play directory, with a configuration file named test.play.com.yaml. The simplest configuration is as follows:
yaml
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
  1. 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

  1. After configuration, start the server:
shell
../bin/mms-live-server -c ../bin/config -d

-d means all logs are printed on the console.

  1. Then start OBS for stream pushing, filling in the stream URL: rtmp://test.publish.com/app/test.

  2. On Windows, launch PowerShell. Make sure ffmpeg or VLC is installed beforehand, then execute:

ffplay rtmp://test.play.com/app/test

to start playback.

  1. Note: If you use ffplay rtmp://test.publish.com/app/test for playback, it will fail.

Released under the MIT License.