使用php构建rtmp/fmp4/hls/flv直播服务

songshu

快速开始

1. 项目安装

composer create-project xiaosongshu/rtmp_server

2. 启动源站主服务

php server.php

启动成功输出示例:

[INFO] RTMP Server started on 0.0.0.0:1935
[INFO] HTTP-FLV/WS-FLV Server started on 0.0.0.0:8501
[INFO] HTTP Static Server started on 0.0.0.0:80

3. 快速推流测试

方式1:浏览器无软件推流

  • 屏幕实时推流:http://127.0.0.1/push.html
  • 本地 MP4/FLV 文件循环推流:http://127.0.0.1/flv_push.html

方式2:FFmpeg 标准推流

ffmpeg -re -stream_loop -1 -i video.mp4 -c:v libx264 -c:a aac -f flv rtmp://127.0.0.1:1935/live/stream

方式3:OBS Studio 推流

  • 服务器:rtmp://127.0.0.1:1935/live/
  • 串流密钥:stream

方式4:项目内置 PHP 推流客户端

php pusher.php test.mp4 http://127.0.0.1:8501/live/stream

4. 快速观看直播

浏览器访问:http://127.0.0.1/index.html

130 0 0
0个评论

songshu

750
积分
0
获赞数
0
粉丝数
2022-06-23 加入
🔝