RTMP流媒体服务器

348 阅读1分钟

获取SRS

git clone https://github.com/ossrs/srs.git

切换分支

本次测试使用6.0.48分支,系统为Ubuntu24.04

git checkout v6.0.48

编译SRS

# 进入trunk目录
[root@mini-desk trunk]# pwd
/root/srs/trunk

# 开始编译
# ./configure && make

The build summary:
     +------------------------------------------------------------------------------------
     For SRS benchmark, gperf, gprof and valgrind, please read:
          https://www.jianshu.com/p/6d4a89359352
     +------------------------------------------------------------------------------------
     |The main server usage: ./objs/srs -c conf/srs.conf, start the srs server
     |     About HLS, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/delivery-hls
     |     About DVR, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/dvr
     |     About SSL, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/rtmp-handshake
     |     About transcoding, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/ffmpeg
     |     About ingester, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/ingest
     |     About http-callback, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/http-callback
     |     Aoubt http-server, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/http-server
     |     About http-api, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/http-api
     |     About stream-caster, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/streamer
     |     (Disabled) About VALGRIND, please read https://github.com/ossrs/state-threads/issues/2
     +------------------------------------------------------------------------------------
binaries, please read https://ossrs.net/lts/zh-cn/docs/v4/doc/install
You can:
      ./objs/srs -c conf/srs.conf
                  to start the srs server, with config conf/srs.conf.

查看生成的文件

➜  trunk git:(v6.0.48) ls objs 
ffmpeg    openssl                                     research              _srs_build_summary.sh  utest
logs      opus                                        src                   srt
Makefile  Platform-Linux-6.8.0-SRS3                   srs                   srtp2
nginx     Platform-SRS6-Linux-6.8.0-GCC13.2.0-x86_64  srs_auto_headers.hpp  st

编辑SRS配置文件

在conf目录有个rtmp.conf配置文件,我们可以使用这个文件直接启动服务

文件内容如下

listen              1935;  // 监听端口
max_connections     1000;  // 最大连接数
daemon              off;   // 前台启动
srs_log_tank        console;  // 打印日志到控制台
vhost __defaultVhost__ {
}

启动SRS

./objs/srs -c ./conf/rtmp.conf

image.png

ss -tunlp | grep 1935
tcp   LISTEN 0      512                               0.0.0.0:1935       0.0.0.0:*    users:(("srs",pid=35707,fd=9)) 

测试SRS流媒体服务器

使用ffmpeg命令推流

ffmpeg -re -i video.flv -vcodec copy -acodec copy -f flv -y rtmp://127.0.0.1/live/livestream

image.png

使用ffplay拉流播放

ffplay rtmp://127.0.0.1/live/livestream

image.png

使用vlc播放测试

image.png

image.png