海康威视摄像头通过GB28181接入SRS

安装依赖

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>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,185评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,445评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,684评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,564评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,681评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,874评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,025评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,761评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,217评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,545评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,694评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,351评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,988评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,778评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,007评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,427评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,580评论 2 349

推荐阅读更多精彩内容