在RK3588上使用SRS流媒体服务器
在RK3588上使用SRS流媒体服务器
SRS(Simple Realtime Server)是一款开源的流媒体服务器,支持RTMP、WebRTC、HLS、HTTP-FLV等多种协议。在RK3588平台上部署SRS可以实现高效的视频流媒体服务。
SRS在RK3588上的安装
1. 安装依赖
sudo apt update
sudo apt install -y git gcc g++ make cmake perl
2. 克隆SRS源码
git clone https://github.com/ossrs/srs.git
cd srs/trunk
3. 编译安装
./configure --with-arm-ubuntu20 --with-ssl --with-hls --with-http-server --with-http-api
make -j$(nproc)
sudo make install
配置SRS
基本配置
编辑配置文件 /usr/local/srs/conf/srs.conf
:
listen 1935;
max_connections 1000;
daemon on;
pid ./objs/srs.pid;
srs_log_tank file;
srs_log_file ./objs/srs.log;http_api {enabled on;listen 1985;
}http_server {enabled on;listen 8080;dir ./objs/nginx/html;
}rtc_server {enabled on;listen 8000;candidate $CANDIDATE_IP;
}vhost __defaultVhost__ {hls {enabled on;hls_path ./objs/nginx/html;hls_fragment 10;hls_window 60;}
}
针对RK3588硬件编码的优化配置
如果使用RK3588的硬件编码器,可以添加以下配置:
vhost __defaultVhost__ {transcode {enabled on;ffmpeg ./objs/ffmpeg/bin/ffmpeg;engine rk {enabled on;vcodec h264_rkmpp;vbitrate 1500;vfps 30;vwidth 1280;vheight 720;vthreads 4;vprofile main;vpreset fast;vparams {g 60;keyint_min 60;}acodec aac;abitrate 128;asample_rate 44100;achannels 2;aparams {}output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];}}
}
启动SRS服务
sudo /usr/local/srs/objs/srs -c /usr/local/srs/conf/srs.conf
使用示例
推流到SRS
使用FFmpeg推流:
ffmpeg -re -i input.mp4 -c:v h264_rkmpp -c:a aac -f flv rtmp://localhost/live/stream1
播放流媒体
- RTMP播放:
rtmp://localhost/live/stream1
- HTTP-FLV播放:
http://localhost:8080/live/stream1.flv
- HLS播放:
http://localhost:8080/live/stream1.m3u8
RK3588特定优化
-
硬件编码支持:
- 使用
h264_rkmpp
编码器可以利用RK3588的硬件编码能力 - 安装MPP库以启用硬件加速
- 使用
-
性能调优:
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
-
内存管理:
- 调整SRS的worker进程数以匹配RK3588的8核CPU
- 在配置中增加
worker_processes 4;
常见问题解决
-
端口冲突:
- 检查1935(RTMP)、8080(HTTP)、1985(API)端口是否被占用
-
权限问题:
- 确保SRS有权限访问编码设备
/dev/mpp_service
- 确保SRS有权限访问编码设备
-
硬件编码失败:
- 检查是否安装了正确的MPP驱动
- 尝试使用软件编码
libx264
进行测试
通过以上步骤,您可以在RK3588平台上成功部署和优化SRS流媒体服务器,充分利用RK3588的硬件编码能力实现高效的视频流媒体服务。