同步操作将从 好的项目备份/xiu 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
XIU是用纯Rust开发的一款简单和安全的流媒体服务器,目前支持的流媒体协议包括RTMP[cluster]/RTSP/WebRTC[Whip/Whep]/HLS/HTTPFLV。
有两种方式来安装xiu:
执行下面的命令来安装xiu:
cargo install xiu
执行下面的命令来查看帮助信息:
xiu -h
A secure and easy to use live media server, hope you love it!!!
Usage: xiu [OPTIONS]
Options:
-c, --config <path> Specify the xiu server configuration file path.
-r, --rtmp <port> Specify the RTMP listening port(e.g.:1935).
-t, --rtsp <port> Specify the rtsp listening port.(e.g.:554).
-w, --webrtc <port> Specify the whip/whep listening port.(e.g.:8900).
-f, --httpflv <port> Specify the HTTP-FLV listening port(e.g.:8080).
-s, --hls <port> Specify the HLS listening port(e.g.:8081).
-l, --log <level> Specify the log level. [possible values: trace, debug, info, warn, error, debug]
-h, --help Print help
-V, --version Print version
git clone https://github.com/harlanc/xiu.git
Checkout最新发布的版本代码:
git checkout tags/<tag_name> -b <branch_name>
为了编译方便,把cargo相关的编译命令封装到了makefle中,使用下面的命令进行编译:
使用make local编译本地代码:
make local && make build
使用make online拉取线上crates仓库代码进行编译
make online && make build
cd ./xiu/target/release or ./xiu/target/debug
./xiu -h
可以使用配置文件或者在命令行对服务进行配置。比如:
xiu -c configuration_file_path
xiu -r 1935 -t 5544 -f 8080 -s 8081 -l info
[rtmp]
enabled = true
port = 1935
# pull streams from other server node.
[rtmp.pull]
enabled = false
address = "192.168.0.1"
port = 1935
# push streams to other server node.
[[rtmp.push]]
enabled = true
address = "localhost"
port = 1936
[[rtmp.push]]
enabled = true
address = "192.168.0.3"
port = 1935
[rtsp]
enabled = false
port = 5544
[httpflv]
# true or false to enable or disable the feature
enabled = true
# listening port
port = 8081
[hls]
# true or false to enable or disable the feature
enabled = true
# listening port
port = 8080
# need record the live stream or not
need_record = true
[log]
level = "info"
[log.file]
# 打开或者关闭输出日志到文件(注意:输出日志到控制台和文件只能2选1).
enabled = true
# set the rotate
rotate = "hour" #[day,hour,minute]
# set the path where the logs are saved
path = "./logs"
有一些现成的配置文件放在下面的目录:
xiu/application/xiu/src/config
包括4个配置文件:
config_rtmp.toml //只打开rtmp
config_rtmp_hls.toml //打开 rtmp 和 hls
config_rtmp_httpflv.toml //打开 rtmp 和 httpflv
config_rtmp_httpflv_hls.toml //打开所有的 3 个协议
可以用任何推流软件或者命令工具来推RTMP流,比如使用OBS或者用ffmpeg命令行:
ffmpeg -re -stream_loop -1 -i test.mp4 -c:a copy -c:v copy -f flv -flvflags no_duration_filesize rtmp://127.0.0.1:1935/live/test
基于TCP推流(Interleaved mode)
ffmpeg -re -stream_loop -1 -i test.mp4 -c:v copy -c:a copy -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:5544/live/test
基于UDP推流
ffmpeg -re -stream_loop -1 -i test.mp4 -c:v copy -c:a copy -f rtsp rtsp://127.0.0.1:5544/live/test
OBS(3.0或者更高版本)支持whip协议,按照如下配置推流:
使用ffplay来播放 rtmp/rtsp/httpflv/hls协议的直播流:
ffplay -i rtmp://localhost:1935/live/test
ffplay -i rtsp://127.0.0.1:5544/live/test
ffplay -rtsp_transport tcp -i rtsp://127.0.0.1:5544/live/test
ffplay -i http://localhost:8081/live/test.flv
ffplay -i http://localhost:8080/live/test/test.m3u8
如何播放RTC流(使用Whep协议)
应用场景为边缘节点的直播流被转推到源站,配置如下:
边缘节点的配置文件config_push.toml:
[rtmp]
enabled = true
port = 1935
[[rtmp.push]]
enabled = true
address = "localhost"
port = 1936
源站节点的配置文件config.toml:
[rtmp]
enabled = true
port = 1936
启动两个服务:
./xiu config.toml
./xiu config_push.toml
将一路RTMP直播流推送到边缘节点,此直播流会被自动转推到源站,可以同时播放源站或者边缘节点的直播流:
ffplay -i rtmp://localhost:1935/live/test
ffplay -i rtmp://localhost:1936/live/test
应用场景为播放过程中用户从边缘节点拉流,边缘节点无此流,则回源拉流,配置文件如下:
源站节点的配置文件为 config.toml:
[rtmp]
enabled = true
port = 1935
边缘节点的配置文件为 config_pull.toml:
[rtmp]
enabled = true
port = 1936
[rtmp.pull]
enabled = false
address = "localhost"
port = 1935
运行两个服务:
./xiu config.toml
./xiu config_pull.toml
直接将直播流推送到源站,到边缘节点请求此路直播流,边缘节点会回源拉流,可以同时播放边缘和源站节点上的直播流:
ffplay -i rtmp://localhost:1935/live/test
ffplay -i rtmp://localhost:1936/live/test
有任何问题请在issues提问,欢迎star和提pull request。你的关注可以让此项目走的更快更远。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。