1 Star 0 Fork 2

joliny / xiu

forked from 好的项目备份 / xiu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

XIUcrates.io crates.io RTMPcrates.io crates.io RTSPcrates.io crates.io WEBRTCcrates.io crates.io HTTPFLVcrates.io crates.io HLScrates.io crates.io FLVcrates.io crates.io MPEGTScrates.io crates.io wechat

XIU是用纯Rust开发的一款简单和安全的流媒体服务器,目前支持的流媒体协议包括RTMP[cluster]/RTSP/WebRTC[Whip/Whep]/HLS/HTTPFLV。

功能

  • 支持多平台(Linux/Mac/Windows)
  • 支持RTMP
    • 支持发布和订阅H264/AAC 直播流;
    • 支持秒开(Gop cache);
    • 支持转换到HLS/HTTP-FLV协议;
    • 支持部署集群;
  • 支持RTSP
    • 支持通过TCP(Interleaved)和UDP发布或订阅H.265/H.264/AAC流;
    • 支持转换到RTMP/HLS/HTTP-FLV协议;
  • 支持WebRTC(Whip/Whep)
    • 支持使用Whip发布rtc流;
    • 支持使用Whep订阅rtc流;
  • 支持订阅HLS/HTTPFLV直播流
  • 支持命令行或者配置文件配置服务
  • 支持HTTP API/notify
    • 支持查询流信息;
    • 支持流事件通知;
  • 支持token鉴权
  • 支持把直播流录制成HLS协议(m3u8+ts)文件

准备工作

安装 Rust and Cargo

Document

安装和运行

有两种方式来安装xiu:

  • 直接用cargo来安装
  • 源码编译安装

用cargo命令安装

执行下面的命令来安装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

源码编译安装

克隆 Xiu

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

CLI

说明

可以使用配置文件或者在命令行对服务进行配置。比如:

通过配置文件进行配置
xiu -c configuration_file_path
通过命令行
xiu -r 1935 -t 5544 -f 8080 -s 8081 -l info

配置文件说明

RTMP
[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
[rtsp]
enabled = false
port = 5544
HTTPFLV
[httpflv]
# true or false to enable or disable the feature
enabled = true
# listening port
port = 8081
HLS
[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
[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推流

可以用任何推流软件或者命令工具来推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
RTSP推流
  • 基于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
使用Whip协议推送RTC流

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协议)

    1. 把xiu/protocol/webrtc/src/clients/目录下的文件拷贝到xiu可执行文件同级目录下;
    2. 在浏览器中打开地址:http://localhost:8900;
    3. 输入和推流地址相对应的app name和stream name;
    4. 点击Start WHEP进行播放.

image

转发 - 静态转推

应用场景为边缘节点的直播流被转推到源站,配置如下:

边缘节点的配置文件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

Star History

Star History Chart

鸣谢

其它

有任何问题请在issues提问,欢迎star和提pull request。你的关注可以让此项目走的更快更远。

MIT License Copyright (c) 2020 HarlanC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

rust 写的视频流服务器 展开 收起
Rust
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Rust
1
https://gitee.com/jbakwd/xiu.git
git@gitee.com:jbakwd/xiu.git
jbakwd
xiu
xiu
master

搜索帮助