SRS 搭建rtmp流媒体服务器

xingyun86 2019-12-24 1309

1.源码下载:

git clone https://code.csdn.net/winlinvip/srs-csdn.git
cd srs-csdn
git pull  
git checkout 2.0release

2.编译安装

cd trunk
#查看编译时的帮助,里面有一些指定的参数是情况加减,官方文档
./configure -h 
#开始编译:
./configure --prefix=/usr/local/srs --with-ssl --with-hls --with-hds --with-dvr --with-nginx --with-http-callback --with-http-server --with-stream-caster --with-http-api --with-ffmpeg --with-transcode --with-ingest --with-stat --with-librtmp --with-research --with-utest --with-gperf --with-gprof
make
make install

3.第三方应用启动:

#启动nginx  for hls
sudo ./objs/nginx/sbin/nginx  
 
#ffmpeg
./objs/ffmpeg/bin/ffmpeg       
 
#to start the api-server
python ./research/api-server/server.py 8085
 
./objs/srs -c conf/srs_kp.conf
 
ps -ef | grep srs         #grep --color=auto srs
./objs/srs -v             #2.0.242
 
可能用到的调试命令:
sudo pkill -9 nginx 
objs/nginx/sbin/nginx -c ./objs/nginx-1.5.7/conf/nginx.conf
sudo nginx -s reload

到此为止,SRS已编译安装完成!

4.配置RTMP

文件目录:./conf/rtmp.conf 
配置内容:
listen              1935;
pid                 ./objs/srs.pid;
chunk_size          60000;
ff_log_dir          ./objs;
srs_log_tank        file;  
#配置日志答应到文件,需要和srs_log_level配合使用
srs_log_level       trace; 
#制定配置文件的级别,默认级别是trace
srs_log_file        ./objs/srs.log;  
#制定日志文件的位置。
max_connections     1000; 
#最大连接数
daemon              on; 
#以daemon的方式启动,如果要启动在console,那么需要配置daemon off;并且,需要配置srs_log_tank console;
utc_time            off; 
#是否使用utc时间。如果该值为off则使用本地时间,如果开始使用utc时间。
vhost __defaultVhost__ {   
#默认的vhost,在没有指明vhost的情况,默认使用这个vhost。
}

我配置的srs_kp.conf
注意gop_cache 一定要设置成on,否则切片推流有卡顿

# the config for srs to delivery hls
# @see https://github.com/ossrs/srs/wiki/v1_CN_SampleHLS
# @see full.conf for detail config.
 
listen              1935;
max_connections     1000;
daemon              off;
srs_log_tank        console;
http_server {
    enabled         on;
    listen          8080;
    dir             ./objs/nginx/html;
}
vhost __defaultVhost__ {
    dvr {
        enabled             on;
        #配置成时分秒
        dvr_path            ./objs/nginx/html/[app]/[stream]/[15][04][05].flv; 
        dvr_plan            segment;
        dvr_duration        5; #切片长度,这个可以改  e.g. 1 or 3
        dvr_wait_keyframe   on;
    }
    gop_cache   on;
}

5.推流和播放
推流:

./objs/ffmpeg/bin/ffmpeg -i "./doc/source.200kbps.768x320.flv" -vcodec libx264 -vprofile baseline -level 30 -g 60 -vb 800k -strict experimental -acodec aac -ab 96000 -ar 48000 -ac 2 -f flv rtmp://127.0.0.1:1935/live/gongjia

播放:

rtmp://172.17.6.96:1935/live/gongjia

6.查看日志

tail -f  ./objs/srs.log


×
打赏作者
最新回复 (0)
只看楼主
全部楼主
返回