1. Components of a URL
Taking rtsp://somedomain.com:554/live/0?token=abcdefg&field=value as an example, this URL is divided into the following parts:
Protocol(scheam): RTSP protocol, default port 554Virtual Host(vhost): somedomain.com. This field can be either a domain name or an IP. If it is an IP, the corresponding virtual host is__defaultVhost__Server Port(port): 554. If the port number is not specified, the protocol's default port number is usedApplication Name(app): liveStream ID(streamid): 0Parameters(args): token=abcdefg&field=value
2. Stream Media Source in ZLMediaKit
In ZLMediaKit, a stream media source is a data object that can be used for functions such as live broadcasting and stream forwarding, and is referred to as MediaSource in this project. Currently, it supports five types of stream media sources, namely RtspMediaSource, RtmpMediaSource, HlsMediaSource, TSMediaSource, FMP4MediaSource.
Identifying a stream media source is mainly based on four elements (referred to as 4-tuples hereafter), which are:
Protocol(scheam)Virtual Host(vhost)Application Name(app)Stream ID(streamid)
RtspMediaSource supports RTSP playback, RTSP streaming, WebRTC playback, and WebRTC streaming.
RtmpMediaSource supports RTMP streaming/playback, HTTP-FLV playback, and WS-FLV playback.
HlsMediaSource supports HLS playback.
TSMediaSource supports HTTP-TS playback and WS-TS playback.
FMP4MediaSource supports HTTP-FMP4 playback and WS-FMP4 playback.
3. Playback URLs Corresponding to the Stream Media Source
Suppose there is a RtspMediaSource, and its 4-tuple are rtsp (RtspMediaSource is always rtsp), somedomain.com, live, and 0
Then the URLs for playing this stream media source correspond to:
rtsp://somedomain.com/live/0rtsps://somedomain.com/live/0rtsp://127.0.0.1/live/0?vhost=somedomain.comrtsps://127.0.0.1/live/0?vhost=somedomain.com
If there is a RtmpMediaSource, and its 4-tuple are rtmp (RtmpMediaSource is always rtmp), somedomain.com, live, and 0
Then the URLs for playing this stream media source correspond to:
rtmp://somedomain.com/live/0rtmps://somedomain.com/live/0rtmp://127.0.0.1/live/0?vhost=somedomain.comrtmps://127.0.0.1/live/0?vhost=somedomain.com
RTMP types of stream media sources also support live streaming through http-flv, websocket, and other protocols. The corresponding URLs are as follows:
Note: Old code live broadcast suffix is .flv, and it has been changed to .live.flv in the new code
http://somedomain.com/live/0.live.flvhttps://somedomain.com/live/0.live.flvhttp://127.0.0.1/live/0.live.flv?vhost=somedomain.comhttps://127.0.0.1/live/0.live.flv?vhost=somedomain.comws://somedomain.com/live/0.live.flvwss://somedomain.com/live/0.live.flvws://127.0.0.1/live/0.live.flv?vhost=somedomain.comwss://127.0.0.1/live/0.live.flv?vhost=somedomain.com
Sure, ZLMediaKit typically converts RTSP and RTMP media streams to each other and also transforms them into HLS/HTTP-TS/WS-TS/HTTP-fMP4/WS-fMP4. The playback URLs are as follows:
-
HLS
http://somedomain.com/live/0/hls.m3u8https://somedomain.com/live/0/hls.m3u8http://127.0.0.1/live/0/hls.m3u8?vhost=somedomain.comhttps://127.0.0.1/live/0/hls.m3u8?vhost=somedomain.com
-
HTTP-TS/WS-TS (with the suffix .live.ts, to resolve the conflict with HLS)
http://somedomain.com/live/0.live.tshttps://somedomain.com/live/0.live.tshttp://127.0.0.1/live/0.live.ts?vhost=somedomain.comhttps://127.0.0.1/live/0.live.ts?vhost=somedomain.comws://somedomain.com/live/0.live.tswss://somedomain.com/live/0.live.tsws://127.0.0.1/live/0.live.ts?vhost=somedomain.comwss://127.0.0.1/live/0.live.ts?vhost=somedomain.com
-
HTTP-fMP4/WS-fMP4 (with the suffix .live.mp4, to resolve the conflict with MP4 on-demand)
http://somedomain.com/live/0.live.mp4https://somedomain.com/live/0.live.mp4http://127.0.0.1/live/0.live.mp4?vhost=somedomain.comhttps://127.0.0.1/live/0.live.mp4?vhost=somedomain.comws://somedomain.com/live/0.live.mp4wss://somedomain.com/live/0.live.mp4ws://127.0.0.1/live/0.live.mp4?vhost=somedomain.comwss://127.0.0.1/live/0.live.mp4?vhost=somedomain.com
Generally speaking, all the above URLs are valid in ZLMediaKit, as ZLMediaKit converts media sources by default.
4. Video-on-Demand URL
ZLMediaKit typically implements video-on-demand via MP4 files, and we recommend using HTTP MP4 on-demand as it is the simplest method and the server does not need to demultiplex the MP4 files. ZLMediaKit currently also supports RTSP, RTMP, HTTP-FLV, and WebSocket-FLV MP4 on-demand. The corresponding URLs are similar to live broadcast URLs and will not be elaborated here; only the differences are discussed.
- ZLMediaKit restricts the application name for on-demand to the default
record. - Suppose an MP4 file is placed in the HTTP root directory record folder (
www/record). Its relative path iswww/record/0.mp4, then the on-demand URL would be:rtsp://somedomain.com/record/0.mp4rtmp://somedomain.com/record/0.mp4http://somedomain.com/record/0.mp4(This is a generic HTTP file on-demand; the server does not need to demultiplex the file)http://somedomain.com/record/0.mp4.live.flv(This is HTTP-FLV live streaming, not HTTP on-demand; the server needs to demultiplex the file)ws://somedomain.com/record/0.mp4.live.flvhttp://somedomain.com/record/0.mp4.live.ts(This is HTTP-TS live streaming, not HTTP on-demand; the server needs to demultiplex the file)ws://somedomain.com/record/0.mp4.live.tshttp://somedomain.com/record/0.mp4.live.mp4(This is HTTP-fMP4 live streaming, not HTTP on-demand; the server needs to demultiplex the file)ws://somedomain.com/record/0.mp4.live.mp4
- If virtual hosting is enabled, then the on-demand files should be placed in
www/somedomain.com/record/0.mp4.
5. WebRTC Push/Pull
WebRTC playback is slightly different from the methods mentioned above. The WebRTC protocol itself does not define a signaling interaction protocol, and users need to implement the sdp+icecandidate exchange logic themselves. So, WebRTC does not have a standard player, and you need to use JS or a native SDK to implement playback.
ZLMediaKit implements the WebRTC SDP+icecandidate exchange method via HTTP POST. The interface name is /index/api/webrtc. This interface uses POST content to pass the offer sdp while passing the media source's four-tuple app stream_id in the URL query parameters. Since HTTP inherently supports vhost, there's no need to specify vhost separately. WebRTC in ZLMediaKit can be considered another representation of the RTSP protocol. Their push and playback use the same data source, which is RtspMediaSource.
When pushing WebRTC, the HTTP POST interface for exchanging WebRTC SDP+icecandidate is similar to: http://127.0.0.1/index/api/webrtc?app=live&stream=test&type=push
When playing WebRTC, the HTTP POST interface for exchanging WebRTC SDP+icecandidate is similar to: http://127.0.0.1/index/api/webrtc?app=live&stream=test&type=play.
ZLMediaKit comes with a WebRTC test player/pusher. After starting ZLMediaKit, you can access it by visiting http://127.0.0.1/webrtc/ in your browser.
Additionally, ZLMediaKit also supports playing MP4 files via WebRTC. The HTTP POST interface is similar to: http://127.0.0.1/index/api/webrtc?app=record&stream=test.mp4&type=play.
6. URL Parameters
ZLMediaKit recognizes the string after the question mark in the URL as parameters, which are consistent with HTTP formats. Among them, vhost is a built-in parameter supported by ZLMediaKit, which allows specifying a virtual host. URL parameters are mainly used for streaming and playback authentication. When triggering the hook API, these parameters will be submitted to the third-party business server.
测试文档
使用教程
- 代码依赖与版权声明
- 快速开始
- vcpkg安装zlmediakit
- 服务器的启动与关闭
- GB28181教程
- 推流播放测试
- RESTful 接口
- RESTful 接口 postman自动生成
- Web Hook 接口
- 配置文件详解
- 播放URL规则
- 按需拉流
- 按需推流
- 播放鉴权
- 推流鉴权
- 怎样创建直播流
- webrtc编译与使用
- webrtc信令交互格式
- 怎么开启https相关功能
相关文档和资源
- zlmediakit独家特性
- zlmediakit的hls高性能之旅
- 高并发实现原理
- RTSP推流流程
- 流媒体相关技术介绍
- 直播延时的本质
- rtmp对H265/opus的支持
- ssl自签名证书测试
- 视频会议相关资源