Introduction
Fixed Origin Pull Mode: This refers to configuring the origin URL, protocol, and other information directly in the configuration file for origin pull. There are other methods as well, such as querying a central node to obtain the origin address and then performing the origin pull, or reading an FLV file from local storage and outputting it, which is also considered a type of origin pull.
- Purpose of Origin Pull: CDN edge nodes pull stream data from the origin server using RTMP/HTTP-FLV, ensuring content is quickly synchronized to global nodes and reducing latency for end users.
- Supported Protocols: Currently, the MMS server supports two origin pull protocols: RTMP and HTTP-FLV.
- Origin Fetch Status Propagation: When fetching from the origin, if the origin server returns HTTP errors such as 404, 403, or 500, or RTMP errors like NetConnection.Connect.Rejected or NotFound, these errors will be passed to the client instead of causing a stall or waiting for a timeout.
Configuration
- First, you need to configure an origin pull in the streaming domain configuration file
test.publish.com.yaml
:
type: publish
name: test.publish.com
apps:
- name: app
origin_pull:
enabled: true
protocol: http-flv
url: http://zlm.com:8080/${app}/${stream_name}..flv
Test Method
- You can push streams to other open-source servers such as SRS or ZLMediaKit, and then fill in the playback address of the other servers for testing.
Configuration Explanation:
${app}
and${stream_name}
are placeholders, similar to%s
and%d
inprintf
, which will be replaced with the requested playback app and stream name. For details, please refer to Authentication.protocol
: Specifies the origin pull protocol, which can behttp-flv
orrtmp
. You can extend it to other protocols like QUIC.url
: The origin URL, where placeholders will be replaced to generate an actual URL.
- If you need to use RTMP for playback, you can configure a bridge to enable RTMP to FLV conversion:
type: publish
name: test.publish.com
apps:
- name: app # Access point name
hls: # Segmenting configuration
ts_min_seg_dur: 2000 # 2000ms, default 2000ms, unit: ms
ts_max_seg_dur: 6000 # 6000ms must be segmented, default 6000ms, unit: ms
ts_max_bytes: 2m # Maximum 2MB, default 2MB, units supported: k/m
min_ts_count_for_m3u8: 3 # Output M3U8 with 3 segments, default 3
origin_pull:
enabled: true
protocol: http-flv
url: http://test.play.com:8080/${app}/${stream_name}.flv
bridge: # Protocol conversion configuration
no_players_timeout_ms: 10s # Time without players before ending protocol conversion
flv:
to_rtmp: on # Enable FLV to RTMP conversion
to_hls: on # Enable FLV to HLS conversion
Stream Pushing
Use OBS to push streams to ZLMediaKit or other open-source servers.
Playback
Use ffplay to play the stream:
ffplay http://test.play.com:8080/app/test.flv
After the server receives the request, it will request the origin FLV data from http://zlm.com/app/test.flv
.
Authentication Generation
For live streaming, anti-leeching is often required, especially for important live content. In such cases, authentication is usually applied to the playback URL. Authentication is generated using a specific rule to create a sign signature, ensuring the link cannot be forged.
The MMS server provides a highly flexible authentication generation method. For concepts related to authentication parameter generation, please refer to the Authentication section.
Authentication generation for origin pull is similar — it essentially generates the origin URL. Below is an example:
type: publish
name: test.publish.com
apps:
- name: app # Access point name
origin_pull:
enabled: true
protocol: http-flv
params:
time: get_time()
sign: md5_upper(sys@test.publish.com/${domain}/${app}/${stream_name}/${params[time]})
url: http://test.publish.com:8080/${app}/${stream_name}.flv?time=${params[time]}&sign=${params[sign]}
This is fairly straightforward: params
are used to calculate and generate some custom parameters, and the placeholders in the URL are replaced with the corresponding values.
Secure Protocol Support
If the URL starts with https
or rtmps
, HTTPS/RTMPS will be used for origin pulling.