SRS Learning - Deploying SRS (GB28181 Edition)

SRS Learning - Deploying SRS (GB28181 Edition)

introduce

SRS is a simple and efficient real-time video server that supports RTMP/WebRTC/HLS/HTTP-FLV/SRT/GB28181.

SRS official website

The single-point version architecture diagram is as follows

img

demand analysis

I have a need now. In the project, we will access real-time video surveillance cameras. The cameras basically support RTSP format push streaming, but RTSP in this format cannot be used on the Google kernel browser, so we It is necessary to use a centralized stream conversion service to convert the stream into a format that can be used by the web, and it is also necessary to ensure the real-time and stability of the stream. I have used nginx-rtmp streaming (.m3u8 format) before, but the timeliness is not good and the delay is a bit high. Finally, I chose to use SRS to implement the streaming server.

Idea analysis

Here my camera is from Hikvision, following the GB/T28181 specification. I plan to push the camera directly to the SRS server, and no longer use FFmpeg to push the stream in the middle, so that the timeliness will be much better and it will be quasi-real-time. Finally, get the video stream in .flv format from the SRS server, and the front desk can use flv.js to load the video. SRS even supports WebRTC, which we will talk about later.

Environment installation

Download the installation package

srs-gb28181 , here I choose the source code of SRS-gb version to install

image-20220516171416643

Unzip the installation package and put it on the linux server (I am centos7 here)

image-20220516171641232

Enter the trunk directory and execute the following command to complete the code compilation

./configure --gb28181=on

Done as shown below

image-20220516172115273

make

image-20220516172242636

The software has been compiled so far

Configure SRS (GB28181)

The configuration related to GB28181 in the SRS streaming media server is in the push.gb28181.conf file in the conf directory, and the content is as follows:

# push gb28181 stream to SRS.

listen                  1935; ## RTMP服务端口号,可用于拉取28181的推流数据
max_connections         1000;
daemon              off;
srs_log_tank        console; ## 表示服务在控制台运行,方便看日志

http_api {
    
      		## SRS提供了标准的HTTP API接口,可用于触发GB28181-SIP信令
    enabled         on;
    listen          1985;
}

http_server {
    
      ## HTTP Server用于支持HLS拉流
    enabled         on;
    listen          8080;
}

stats {
    
    
    network         0;
}

stream_caster {
    
    
    enabled             on;  
    caster              gb28181; ## 打开GB28181功能

    # 转发流到rtmp服务器地址与端口
    # TODO: https://github.com/ossrs/srs/pull/1679/files#r400875104
    # [stream] is VideoChannelCodecID(视频通道编码ID) for sip
    # 自动创建的道通[stream] 是‘chid[ssrc]’ [ssrc]是rtp的ssrc
    # [ssrc] rtp中的ssrc
    output              rtmp://127.0.0.1:1935/live/[stream];
    
    # 接收设备端rtp流的多路复用端口
    listen              9000;
    # 多路复用端口类型,on为tcp,off为udp
    # 默认:on
    tcp_enable            on;

    # rtp接收监听端口范围,最小值
    rtp_port_min        58200;
    # rtp接收监听端口范围,最大值
    rtp_port_max        58300;

    # 是否等待关键帧之后,再转发,
    # off:不需等待,直接转发
    # on:等第一个关键帧后,再转发
    wait_keyframe       on;
    
    # rtp包空闲等待时间,如果指定时间没有收到任何包
    # rtp监听连接自动停止,发送BYE命令
    rtp_idle_timeout    30;

    # 是否转发音频流
    # 目前只支持aac格式,所以需要设备支持aac格式
    # on:转发音频
    # off:不转发音频,只有视频
    # *注意*!!!:flv 只支持11025  22050  44100 三种
    # 如果设备端没有三种中任何一个,转发时为自动选择一种格式
    # 同时也会将adts的头封装在flv aac raw数据中
    # 这样的话播放器为自动通过adts头自动选择采样频率
    # 像ffplay, vlc都可以,但是flash是没有声音,
    # 因为flash,只支持11025 22050 44100
    audio_enable        off;


    # 服务器主机号,可以域名或ip地址
    # 也就是设备端将媒体发送的地址,如果是服务器是内外网
    # 需要写外网地址,
    # 调用api创建stream session时返回ip地址也是host
    # $CANDIDATE 是系统环境变量,从环境变量获取地址,如果没有配置,用*
    # *代表指定stats network 的网卡号地址,如果没有配置network,默认则是第0号网卡地址
    # TODO: https://github.com/ossrs/srs/pull/1679/files#r400917594
    host       $CANDIDATE;

    #根据收到ps rtp包自带创建rtmp媒体通道,不需要api接口创建
    #rtmp地址参数[stream] 就是通道id  格式chid[ssrc]
    auto_create_channel   off;

    sip {
    
    
        # 是否启用srs内部sip信令
        # 为on信令走srs, off 只转发ps流
        enabled on;
        
        # sip监听udp端口
        listen              5060;
        
        # SIP server ID(SIP服务器ID).
        # 设备端配置编号需要与该值一致,否则无法注册
        serial              34020000002000000001;

        # SIP server domain(SIP服务器域)
        realm               3402000000;

        # 服务端发送ack后,接收回应的超时时间,单位为秒
        # 如果指定时间没有回应,认为失败
        ack_timeout         30;

        # 设备心跳维持时间,如果指定时间内(秒)没有接收一个心跳
        # 认为设备离线
        keepalive_timeout   120;

        # 注册之后是否自动给设备端发送invite
        # on: 是  off 不是,需要通过api控制
        auto_play           on;
        # 设备将流发送的端口,是否固定
        # on 发送流到多路复用端口 如9000
        # off 自动从rtp_mix_port - rtp_max_port 之间的值中
        # 选一个可以用的端口
        invite_port_fixed     on;

        # 向设备或下级域查询设备列表的间隔,单位(秒)
        # 默认60秒
        query_catalog_interval  60;
    }
}

rtc_server {
    
    
    enabled         on;
    # Listen at udp://8000
    listen          8000;
    #
    # The $CANDIDATE means fetch from env, if not configed, use * as default.
    #
    # The * means retrieving server IP automatically, from all network interfaces,
    # @see https://github.com/ossrs/srs/issues/307#issuecomment-599028124
    candidate       $CANDIDATE;
}

vhost __defaultVhost__ {
    
    
    rtc {
    
       ## 打开WebRTC功能
        enabled     on;
        bframe      discard;
    }

    http_remux {
    
        ## 打开HTTP-Flv功能
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
}

start service

Foreground start service

cd trunk
./objs/srs -c ./conf/push.gb28181.conf

background start service

nohup ./objs/srs -c ./conf/push.gb28181.conf >/dev/null 2>&1 &

access service

The default port is 8080 http://ip:8080/

image-20220516192210591

Enter SRS

image-20220516192247056

Hikvision camera configuration GB28181

configure camera

Hikvision cameras generally have accessible web pages

The default id address is 64, here is mine: http://192.168.1.64/

The login interface is as follows:

image-20220516192947148

Default account password: admin/12345 (may be inconsistent)

The main page is as follows:

image-20220516193136219

Click Configure:

image-20220516193245953

Click Network->Advanced Settings->Platform Access

image-20220516193449958

Here the SIP server address is set to the newly deployed SRS server address, the configuration is as shown above

SIP user name can be set according to your own needs

If there is no problem, the registration status can be seen as online

The effect is as follows

You can see the newly registered camera under the SRS console

image-20220516193907596

image-20220516194125885

Guess you like

Origin blog.csdn.net/qq_36213352/article/details/124806963