1.源碼下載:
git clone https://code.csdn.net/winlinvip/srs-csdn.git
cd srs-csdn
git pull
git checkout 2.0release
2.編譯安裝
cd trunk
#查看編譯時的幫助,里面有一些指定的參數(shù)是情況加減,官方文檔
./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
注:
CFLAGS='-w' ./configure
CFLAGS='-w' make
3.第三方應(yīng)用啟動:
#啟動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
可能用到的調(diào)試命令:
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
配置內(nèi)容:
listen 1935;
pid ./objs/srs.pid;
chunk_size 60000;
ff_log_dir ./objs;
srs_log_tank file;
#配置日志答應(yīng)到文件,需要和srs_log_level配合使用
srs_log_level trace;
#制定配置文件的級別,默認(rèn)級別是trace
srs_log_file ./objs/srs.log;
#制定日志文件的位置。
max_connections 1000;
#最大連接數(shù)
daemon on;
#以daemon的方式啟動,如果要啟動在console,那么需要配置daemon off;并且,需要配置srs_log_tank console;
utc_time off;
#是否使用utc時間。如果該值為off則使用本地時間,如果開始使用utc時間。
vhost __defaultVhost__ {
#默認(rèn)的vhost,在沒有指明vhost的情況,默認(rèn)使用這個vhost。
}
我配置的srs_kp.conf
注意gop_cache 一定要設(shè)置成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;
}
- 推流和播放
推流:
./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
- 查看日志
tail -f ./objs/srs.log
``