ZLM 推流与播放简易教程
以下示例使用流标识 test001。先取得本节点的
publishKey,推流成功后再选择任意一种播放协议。
两个密钥用途不同:
publishKey 用于推流鉴权;API Secret
只用于调用 ZLM 管理 API,不能拿来代替推流密钥。播放鉴权当前未启用。
1. 在服务器取得推流密钥
sudo bash /www/docker-compose/zlm/install.sh --status --show-secrets
也可以直接查看安装器生成的完整接入教程:
sudo cat /www/docker-compose/zlm/connection-guide.txt
完整密钥不要发到公开聊天、工单、网页或代码仓库。
2. 推流
FFmpeg
ffmpeg -re -i input.mp4 -c copy -f flv \
'rtmp://114.80.33.45:1937/live/test001?publishKey=替换为完整密钥'
OBS
| OBS 字段 | 填写内容 |
|---|---|
| 服务 | 自定义 |
| 服务器 | rtmp://114.80.33.45:1937/live |
| 串流密钥 | test001?publishKey=替换为完整密钥 |
WebRTC 推流信令
http://114.80.33.45:8181/index/api/webrtc?app=live&stream=test001&type=push&publishKey=替换为完整密钥
缺少密钥或密钥错误时,ZLM 会拒绝发布该流。
3. 播放
推流在线后使用以下任一地址。当前播放不需要 publishKey。
| 协议 | 播流地址 |
|---|---|
| RTMP | rtmp://114.80.33.45:1937/live/test001 |
| HTTP-FLV | http://114.80.33.45:8181/live/test001.live.flv |
| HLS | http://114.80.33.45:8181/live/test001/hls.m3u8 |
| RTSP | rtsp://114.80.33.45:554/live/test001 |
| WebRTC | http://114.80.33.45:8181/index/api/webrtc?app=live&stream=test001&type=play |
浏览器可打开 内置 WebRTC 测试页,
填写 app=live、stream=test001 后播放。
4. 常见排查
- 推流被拒绝:先核对 URL 中的
publishKey,不要使用 API Secret。 - 播放 404:确认推流仍在线,并核对
app=live与 stream 完全一致。 - WebRTC 无画面:检查 9002/TCP+UDP、3478/TCP+UDP 和 50000-50050/TCP+UDP。
- 查看状态:
sudo bash /www/docker-compose/zlm/install.sh --status。 - 重新自检:
sudo bash /www/docker-compose/zlm/install.sh --self-test。