一、編譯SRS
https://github.com/winlinvip/simple-rtmp-server
目前有1.0-release、2.0、3.0等版本
2.0官方文檔地址:https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_Home
1.如果是新系統,先安裝git
CentOS:yum -y install git
- 1
2.源碼下載:
git clone https://code.csdn.net/winlinvip/srs-csdn.git
- 1
3.git操作
a.改變SRS分支
切換到1.0分支 git pull && git checkout 1.0release 切換到2.0分支 git pull && git checkout 2.0release
- 1
- 2
- 3
- 4
我把源碼下載到了/mnt目錄,然后我們cd /mnt
b.查看當前分支
cd /mnt/srs-csdn;git branch
- 1
c.改變到2.0分支
git pull && git checkout 2.0release
- 1
4.編譯安裝
cd /mnt/srs-csdn/trunk
- 1
./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
- 1
- 2
- 3
第三方應用啟動:
sudo ./objs/nginx/sbin/nginx --- 啟動nginx for hls ./objs/ffmpeg/bin/ffmpeg ---ffmpeg python ./research/api-server/server.py 8085 ---to start the api-server
- 1
- 2
- 3
SRS啟動
cd /mnt/srs-csdn/trunk ./objs/srs -c conf/srs.conf ps -ef | grep srs ./srs -v
- 1
- 2
- 3
- 4
到此為止,SRS已編譯安裝完成!
二、配置RTMP
1.RTMP URL解釋:
rtmp://HOST:PORT/app/stream_name rtmp: 協議頭 HOST:注意的IP地址或域名 app: 應用名稱 stream_name:流名稱
- 1
- 2
- 3
- 4
- 5
2.SRS中RTMP配置信息
文件目錄:/mnt/srs-csdn/trunk/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。 }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
3.ffmpeg推流 VLC播放
ffmpeg可執行程序目錄:/mnt/srs-csdn/trunk/objs/ffmpeg/bin/ffmpeg
推流:
cd /mnt/srs-csdn/trunk/objs/ffmpeg/bin ./ffmpeg -i "abc.avi" -vcodec libx264 -vprofile baseline -level 30 -g 60 -vb 800k -strict experimental -acodec aac -ab 96000 -ar 48000 -ac 2 -f flv rtmp://192.168.1.62:1935/live/zb
- 1
- 2
VLC取流:
rtmp://192.168.1.62:1935/live/zb
- 1
SRS服務器搭建,ffmpeg 本地推流,srs從本地拉流
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
參考:
https:
//github.com/ossrs/srs/wiki/v2_CN_SampleFFMPEG
git clone https:
//github.com/ossrs/srs
cd srs/trunk
./configure
make
make install
./objs/srs -c conf/myconf.conf
其中: ./configure --with-ffmpeg && make
如果編譯失敗就去掉--with-ffmpeg,自己安裝ffmpeg
本地推流: ffmpeg -re -i /root/Videos/aaa.mp4 -c copy -f flv rtmp:
//192.168.2.125:1935/live/aaa
|
配置文件myconf.conf:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# the config for srs use ffmpeg to transcode
# @see https://github.com/ossrs/srs/wiki/v1_CN_SampleFFMPEG
# @see full.conf for detail config.
listen 1935;
max_connections 1000;
daemon off;
srs_log_tank console;
vhost __defaultVhost__ {
transcode {
enabled
on
;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine ff {
enabled
on
;
vfilter {
}
vcodec libx264;
vthreads 4;
vprofile main;
vpreset medium;
vparams {
}
acodec libfdk_aac;
aparams {
}
output rtmp:
//127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
}
}
#保存直播為flv
dvr {
# https://github.com/ossrs/srs/wiki/v2_CN_DVR
enabled
on
;
dvr_path ./objs/nginx/html/[app]/[stream].[timestamp].flv;
dvr_plan session;
dvr_duration 30;
dvr_wait_keyframe
on
;
time_jitter full;
}
}
|
srs從本地拉流:
my.ingest.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
listen
1935
;
max_connections
1000
;
daemon off;
srs_log_tank console;
vhost __defaultVhost__ {
ingest livestream {
enabled on;
input {
type file;
url /root/Videos/zzzz.mp4;
}
ffmpeg /usr/local/bin/ffmpeg;
engine {
enabled off;
output rtmp:
//127.0.0.1:1935/live/livestream;
#rtmp:
//127.0.0.1:[port]/live?vhost=[vhost]/livestream;
}
}
}
|
關鍵是ffmpeg路徑要是絕對的