一、客户端
- 推流端基于: yasea实现
- 拉流端基于: FFmpeg + GLSurfaceView
路径配置:rtmp://ip:port/application/串流密钥, 串流密钥可以理解为路径, 可以随便填, 只要推流拉流相统一即可.
二、服务端(Centos8/Mac)
采用nginx + nginx-rtmp-module.
环境
#安装Nginx的编译环境gcc
yum install gcc-c++
brew install gcc
#nginx的http模块使用pcre解析正则表达式所以安装perl兼容的正则表达式库
yum install -y pcre pcre-devel
brew install pcre
#nginx使用zlib对http包的内容进行gzip
yum install -y zlib zlib-devel
brew install zlib
#nginx不仅支持http协议,还支持https(即在ssl协议上传输http),如果使用了https,需要安装OpenSSL库
yum install -y openssl openssl-devel
brew install openssl
下载Nginx、nginx-rtmp-module
# 下载nginx
wget http://nginx.org/download/nginx-1.15.3.tar.gz 或者 官网下载
# 解压
tar -zxvf nginx-1.15.3.tar.gz
# 下载 nginx-rtmp-module
git clone https://github.com/arut/nginx-rtmp-module
cd nginx-1.15.3
./configure --add-module="/xxx/nginx-rtmp-module"
make
make install
vim /usr/local/nginx/conf/nginx.conf // 注意修改路径,修改解压路径下的conf不会起作用
# 编辑nginx.conf
rtmp {
server {
listen 1935; #监听的端口
chunk_size 4000;
application live {
listen 1935; #监听的端口
chunk_size 4000;
application live {
live on; #开启实时
}
}
}
}
# 启动服务
cd /usr/local/nginx/sbin
./nginx
安装规程中出现的问题
./configure时报错openssl找不到
虽然已经安装openssl, 但仍然报错.
这里需要根据提示配置openssl的路径:
./auto/configure
--add-module="./nginx-rtmp-module-1.2.1"
--with-openssl="/usr/local/Cellar/openssl@1.1/1.1.1g"
注意这个路径可能有变化, 这里我是根据openssl安装时的输出日志查找到安装位置, 使用which/whereis openssl获取到的是执行位置, 并不是安装位置.
make时报错./config: No such file or directory
原因在于make时使用的nginx-release-1.19.6/auto/lib/openssl/conf中配置的openssl安装path不一致导致, 需要修改其中的配置
// 修改为自己版本的路径, 例如对于1.1.1g需要删除./openssl中间路径
CORE_INCS="$CORE_INCS $OPENSSL/include"
// 修改为自己版本的路径, 例如对于1.1.1g需要删除./openssl中间路径
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
// 修改为自己版本的路径, 例如对于1.1.1g需要删除./openssl中间路径
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
// 修改为自己版本的路径, 例如对于1.1.1g需要删除./openssl中间路径
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
// 修改为自己版本的路径, 例如对于1.1.1g需要删除./openssl中间路径
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
// 修改为自己版本的路径, 例如对于1.1.1g需要删除./openssl中间路径
CORE_LIBS="$CORE_LIBS $NGX_LIBPTHREAD"
然后重新configure, 重新make即可
测试工具
obs推流器
推流配置
- 自定义服务
- 服务器: rtmp://ip:port/application, 注意这里的ip为localhost或者ip, port一般是1935, application为nginx.conf中配置的application名字
- 串流密钥: 可以理解为路径, 可以随便填, 只要拉流客户端相统一即可.
VLC
拉流地址配置为: rtmp://ip:port/application/串流密钥