一、源码下载
github地址 https://github.com/ossrs/srs.git
二、源码编译
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
三、文件配置
./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。
}
自己创建一个文件./conf/srs_kp.conf
# 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;
}
四、相关服务启动
#启动nginx for hls
sudo ./objs/nginx/sbin/nginx
#to start the api-server
python ./research/api-server/server.py 8085
./objs/srs -c conf/srs_kp.conf
五、推流播放
创建shell脚本,内容如下:
@echo off
for((;;)); do \
ffmpeg -re -rtsp_transport tcp -i rtsp://admin:Standstar@127.0.0.1:554/h264/ch33/main/av_stream -vcodec copy -acodec copy -f flv -y rtmp://127.0.0.1/live/livestream/ch33; \
sleep 1; \
done
pause
保存并运行脚本。打开VLC播放器,媒体->流->网络(贴入rtmp地址)-播放。