安装依赖
yum install gcc gcc-c++ patch tcl cmake autoconf automake -y
# ubuntu
apt install gcc unzip tclsh cmake autoconf automake -y
安装GIT
yum install git -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-25.el7_9 will be installed
--> Processing Dependency: perl-Git = 1.8.3.1-25.el7_9 for package: git-1.8.3.1-25.el7_9.x86_64
--> Processing Dependency: perl(Term::ReadKey) for package: git-1.8.3.1-25.el7_9.x86_64
--> Processing Dependency: perl(Git) for package: git-1.8.3.1-25.el7_9.x86_64
--> Processing Dependency: perl(Error) for package: git-1.8.3.1-25.el7_9.x86_64
--> Running transaction check
---> Package perl-Error.noarch 1:0.17020-2.el7 will be installed
---> Package perl-Git.noarch 0:1.8.3.1-25.el7_9 will be installed
---> Package perl-TermReadKey.x86_64 0:2.30-20.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================================
Installing:
git x86_64 1.8.3.1-25.el7_9 updates 4.4 M
Installing for dependencies:
perl-Error noarch 1:0.17020-2.el7 base 32 k
perl-Git noarch 1.8.3.1-25.el7_9 updates 56 k
perl-TermReadKey x86_64 2.30-20.el7 base 31 k
Transaction Summary
======================================================================================================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 4.5 M
Installed size: 22 M
Downloading packages:
(1/4): perl-Git-1.8.3.1-25.el7_9.noarch.rpm | 56 kB 00:00:00
(2/4): perl-TermReadKey-2.30-20.el7.x86_64.rpm | 31 kB 00:00:00
(3/4): perl-Error-0.17020-2.el7.noarch.rpm | 32 kB 00:00:00
(4/4): git-1.8.3.1-25.el7_9.x86_64.rpm | 4.4 MB 00:00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 4.8 MB/s | 4.5 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:perl-Error-0.17020-2.el7.noarch 1/4
Installing : perl-TermReadKey-2.30-20.el7.x86_64 2/4
Installing : git-1.8.3.1-25.el7_9.x86_64 3/4
Installing : perl-Git-1.8.3.1-25.el7_9.noarch 4/4
Verifying : 1:perl-Error-0.17020-2.el7.noarch 1/4
Verifying : git-1.8.3.1-25.el7_9.x86_64 2/4
Verifying : perl-Git-1.8.3.1-25.el7_9.noarch 3/4
Verifying : perl-TermReadKey-2.30-20.el7.x86_64 4/4
Installed:
git.x86_64 0:1.8.3.1-25.el7_9
Dependency Installed:
perl-Error.noarch 1:0.17020-2.el7 perl-Git.noarch 0:1.8.3.1-25.el7_9 perl-TermReadKey.x86_64 0:2.30-20.el7
Complete!
克隆源码
cd /home
git clone -b 5.0release https://gitee.com/ossrs/srs.git
Cloning into 'srs'...
remote: Enumerating objects: 82794, done.
remote: Counting objects: 100% (3719/3719), done.
remote: Compressing objects: 100% (3343/3343), done.
remote: Total 82794 (delta 1827), reused 1092 (delta 312), pack-reused 79075
Receiving objects: 100% (82794/82794), 238.15 MiB | 1.86 MiB/s, done.
Resolving deltas: 100% (63123/63123), done.
编译
cd srs/trunk
./configure --gb28181=on
make
cd conf
cp gb28181.conf hikvision.conf
修改配置
daemon off;
srs_log_tank console;
stream_caster {
enabled on;
caster gb28181;
output rtmp://127.0.0.1/live/[stream];
listen 9000;
tcp_enable on;
rtp_port_min 58200;
rtp_port_max 58300;
wait_keyframe off;
rtp_idle_timeout 30;
audio_enable on;
host 192.168.0.20;
sip {
enabled on;
listen 5060;
serial 34020000002000000001
realm 3402000000
ack_timeout 30;
keepalive_timeout 120;
auto_play on;
invite_port_fixed on;
query_catalog_interval 60;
# @see https://ossrs.net/lts/zh-cn/docs/v5/doc/gb28181#config-candidate
candidate 192.168.0.20;
}
}
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
http_api {
enabled on;
listen 1985;
raw_api{
enabled on;
allow_reload on;
allow_query on;
allow_update on;
}
}
stats {
network 0;
}
rtc_server {
enabled on;
listen 8000; # UDP port
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#config-candidate
candidate $CANDIDATE;
}
vhost __defaultVhost__ {
rtc {
enabled on;
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtmp-to-rtc
rtmp_to_rtc on;
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtc-to-rtmp
rtc_to_rtmp on;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
}
hls {
enabled on;
}
}
运行程序
cd ..
./objs/srs -c conf/hikvision.conf
flv.js网页展示,会有5秒左右延迟
<!DOCTYPE html>
<html>
<head>
<link href="videojs/video-js.css" rel="stylesheet">
<script src="videojs/video.js"></script>
<style>
.video-grid {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
max-width: 1200px;
margin: 0 auto;
}
.video-container {
flex: 0 0 calc(33.33% - 10px);
margin: 10px 0;
box-sizing: border-box;
border: 1px solid #ccc;
overflow: hidden;
}
.video-container video {
width: 100%;
}
</style>
</head>
<body>
<h3>L21095586</h3>
<div class="video-grid" id="grid1">
</div>
<script src="flv.js"></script>
<script>
if (flvjs.isSupported()) {
var urls = [
'http://192.168.0.20:8080/live/34020000001320000001.flv',
'http://192.168.0.20:8080/live/34020000001320000002.flv',
'http://192.168.0.20:8080/live/34020000001320000003.flv',
'http://192.168.0.20:8080/live/34020000001320000004.flv',
'http://192.168.0.20:8080/live/34020000001320000005.flv',
'http://192.168.0.20:8080/live/34020000001320000006.flv',
'http://192.168.0.20:8080/live/34020000001320000007.flv',
'http://192.168.0.20:8080/live/34020000001320000008.flv'
];
for(var i = 0;i<urls.length;i++){
createPlayer(urls[i],i);
}
}
function createPlayer(playUrl, index){
var container = document.createElement("div");
container.setAttribute("class","video-container");
var video = document.createElement('video');
video.setAttribute("controls",true);
video.setAttribute("id","videoEle" + index)
container.appendChild(video);
document.getElementById("grid1").appendChild(container);
var flvPlayer = flvjs.createPlayer({
type: 'flv',
url: playUrl
});
flvPlayer.attachMediaElement(video);
flvPlayer.load();
//flvPlayer.play()
}
</script>
</body>
</html>
webrtc.js网页展示,延迟在ms级
<!DOCTYPE html>
<html>
<head>
<link href="videojs/video-js.css" rel="stylesheet">
<script src="videojs/webrtc.min.js"></script>
<style>
.video-grid {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
max-width: 1200px;
margin: 0 auto;
}
.video-container {
flex: 0 0 calc(33.33% - 10px);
margin: 10px 0;
box-sizing: border-box;
border: 1px solid #ccc;
overflow: hidden;
}
.video-container video {
width: 100%;
}
</style>
</head>
<body>
<h3>L21095586</h3>
<div class="video-grid" id="grid1">
</div>
<script>
var urls = [
'webrtc://192.168.0.20/live/34020000001320000001.flv',
'webrtc://192.168.0.20/live/34020000001320000002.flv',
'webrtc://192.168.0.20/live/34020000001320000003.flv',
'webrtc://192.168.0.20/live/34020000001320000004.flv',
'webrtc://192.168.0.20/live/34020000001320000005.flv',
'webrtc://192.168.0.20/live/34020000001320000006.flv',
'webrtc://192.168.0.20/live/34020000001320000007.flv',
'webrtc://192.168.0.20/live/34020000001320000008.flv'
];
for(var i = 0;i<urls.length;i++){
createPlayer(urls[i],i);
}
function createPlayer(playUrl, index){
var container = document.createElement("div");
container.setAttribute("class","video-container");
var video = document.createElement('video');
video.setAttribute("controls",true);
video.setAttribute("id","videoEle" + index)
container.appendChild(video);
var player = new JSWebrtc.Player(playUrl,
{
video: video,
autoplay: true,
onPlay: (obj) => { console.log("start play")
}
});
document.getElementById("grid1").appendChild(container);
}
</script>
</body>
</html>