視訊監控安防平台-通過HTTP轉國标28181(GB28181-2016)實作動态擷取RTSP、RTMP、HLS輸出管理平台
最近抽時間把這個小型管理平台做了完善,目前支援的功能全部通過http+json的接口實作,由于有mysql資料庫和httpserver所有對環境依賴程度比較大(建議按照部署文檔來操作),demo裡面有系統的部署文檔和mysql資料庫的初始化部署,支援小型并發數在100路左右的視訊管理平台,如果開發力量大的可以在這個基礎上做二次開發,主要針對使用者、資源組和角色等管理,裝置管理在5000路左右,視訊并發在100路左右(同時100路碼流接收和發送)。運作環境是centos7.3 x64系統,mysql采用系統自帶的mariadb。
國标28181平台版本已更新(支援多線程處理和接收sip資料、支援BS用戶端),新位址:
https://blog.csdn.net/songxiao1988918/article/details/108087792
通過http轉國标28181(GB28181-2016)實作動态擷取RTSP、RTMP、HLS輸出管理平台下載下傳位址如下:
https://download.csdn.net/download/songxiao1988918/10870352
由于上傳無法選擇0積分下載下傳,沒有積分的可以聯系我, 聯系方式QQ:123011785 ,歡迎大家一起學習!
一、功能介紹:
1、支援國标GB28181平台、國标GB28181 IPC和國标GB28181 NVR裝置同時接入 (支援GB28181-2011版本和GB28181-2016版本)
2、支援國标GB28181裝置注冊和登出,對所有裝置進行管理,擷取資源 對資源清單進行管理
3、支援國标GB28181的目錄訂閱,對接收的訂閱通知進行處理
4、支援國标GB28181實時視訊請求(支援UDP、TCP主動(tcpactive)、TCP被動(tcppassive))
5、支援國标GB28181 PTZ控制
6、支援國标GB28181 錄像查詢
7、支援國标GB28181 曆史視訊點播 (支援UDP、TCP主動(tcpactive)、TCP被動(tcppassive))
8、支援國标GB28181 曆史視訊下載下傳 (支援UDP、TCP主動(tcpactive)、TCP被動(tcppassive))
9、支援對接收的國标實時視訊碼流和曆史視訊碼流進行管理
10、支援将國标的PS碼流轉換成ES碼流
11、支援丢包列印和斷流列印
13、支援RTSP服務和RTSP會話管理
14、支援RTSP用戶端 UDP傳輸和TCP傳輸
15、支援國标GB28181裝置5000路左右的接入管理,支援國标請求視訊在100路左右
16、支援國标28181裝置和通道寫入mysql資料庫
17、支援裝置的雲台PTZ控制,控制類型:上"up",下"down",左"left",右"right",左上"leftup",左下"leftdown",右上"rightup",右下"rightdown",鏡頭近"zoomin",鏡頭遠"zoomout", 焦距遠"focusfar",焦距近"focusnear", 設定預置位"setpos",調預置位"callpos"
18、支援曆史視訊的查詢和曆史視訊的點播控制
19、支援對國标裝置的控制,"record":錄像開啟和停止-通道id "guard":布放和撤防-報警通道id "reboot":裝置重新開機-裝置id "keyfame":強制關鍵幀-通道id
20、支援對實時視訊的圖檔截圖,通過http直接通路圖檔
21、支援rtmp和hls會話一直保留
22、支援報警消息(裝置上線、下線和裝置端報警)通過httpclient方式主動通知
23、支援公網和區域網路同時存在
24、支援httpserver,接口支援http+json
25、支援裝置上線、下線和裝置報警通過httpclient通知到指定的httpserver
架構圖:

二、使用文檔:
- 初始化mysql 資料庫(系統預設使用的是mariadb)
如果未安裝mariadb,可以使用yum安裝,安裝mariadb的yum指令:yum -y install mariadb mariadb-server
1.1、設定mysql忽略表名的大小寫
[[email protected] ~]# vi /etc/my.cnf.d/server.cnf
在[mysqlld]下加上
lower_case_table_names=1
1.2、設定啟動mariadb和開機自啟動mariadb資料庫
[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl enable mariadb
1.3、設定mariadb登入的使用者名和密碼
[[email protected] ~]# mysql -uroot
空格
MariaDB [(none)]> use mysql
MariaDB [mysql]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
MariaDB [mysql]> CREATE USER 'root'@'%' IDENTIFIED BY "123456";
MariaDB [mysql]> grant all privileges on *.* to 'root'@'%' identified by '123456';
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
MariaDB [mysql]> flush privileges;
Mysql資料庫初始化完成。
2、初始化資料庫表
由于建立表比較少,建議直接使用工具建立表。
将EGEyesForVSS-MariaDB.sql 的内容直接拷貝到工具下,執行相應的語句。
3、Windows準備程式包
4、上傳檔案
5、檢查檔案,包括程式和動态庫。
1、對所有的*.out和*.sh檔案賦予權限
[[email protected] videosvr]# cd /home/videosvr/
[[email protected] videosvr]# chmod 777 *.sh
[[email protected] videosvr]# chmod 777 *.out
[[email protected] videosvr]# chmod 777 objs
use EGEyesForVSS;
create table IF NOT EXISTS VSSDevTbl
(
ID int primary key auto_increment comment '自增ID;',
DevPubID varchar(32) not null unique comment '一級裝置賬号;',
DevNickname char(128) comment '昵稱;',
UserName char(64) comment '使用者名;',
Passwd char(64) comment '密碼;',
CorpID char(32) comment '裝置廠商;',
IP char(16) comment 'IP位址 ;',
Port smallint unsigned comment '端口;',
Alive boolean default 0 comment '注冊狀态;0-下線;1-上線',
DMarker int default 1 comment '0-未變化;1-增加;2-删除;3-修改;4-已同步,可删除;',
UpdateTime TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新時間;'
);
alter table VSSDevTbl comment '建立一級裝置表';
create table IF NOT EXISTS VSSChannelTbl
(
ID int primary key auto_increment comment '自增ID;',
DevPubID varchar(32) not null comment '一級裝置賬号;',
Nickname char(128) comment '昵稱;',
ChanPubID varchar(32) not null unique comment '二級裝置賬号;',
Alive boolean default 0 comment '注冊狀态;0-下線;1-上線',
CorpID char(32) comment '裝置廠商;',
Model char(32) comment '裝置型号;',
Owner char(32) comment '裝置歸屬;',
CivilCode char(32) comment '行政區域;',
Address char(128) comment '安裝位址;',
Parental int default 0 comment '0-沒有裝置;1-有子裝置',
ParentId char(64) comment '父裝置;',
IP char(16) comment 'IP位址 ;',
Port smallint unsigned comment '端口;',
Longitude double default 0 comment '經度',
Latitude double default 0 comment '緯度',
Altitude double default 0 comment '海拔',
PTZType int default 0 comment '1-球機;2-半球;3-固定槍機;4-遙控槍機;',
RoomType int default 0 comment '1-室外;2-室内',
DirectionType int default 0 comment '1-東;2-西;3-南;4-北;5-東南;6-東北;7-西南;8-西北;',
StreamType int default 0 comment '0-H264;1-MPEG2;2-MPEG4;3-SVAC;4-3GP;5-H265;',
RealRtspUrl varchar(256) comment '實時視訊rtsp位址;' ,
DMarker int default 1 comment '0-未變化;1-增加;2-删除;3-修改;4-已同步,可删除;',
UpdateTime TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新時間;'
);
alter table VSSChannelTbl comment '建立二級裝置表';
alter table VSSChannelTbl add constraint FK_VSSChannelTbl foreign key (DevPubID) references VSSDevTbl (DevPubID) on delete cascade;
create table IF NOT EXISTS SVRTbl
(
ID int primary key auto_increment comment '自增ID;',
GBServerID varchar(20) not null comment '國标伺服器ID;',
IP varchar(16) comment 'IP;',
GBServerPort smallint unsigned comment '國标伺服器端口;',
RtspServerPort smallint unsigned comment 'rtsp伺服器端口;',
HttpserverPort smallint unsigned comment 'http伺服器端口;',
HttpclientSvrIp varchar(16) comment 'http用戶端連接配接服務IP;',
HttpclientSvrPort smallint unsigned comment 'http用戶端連接配接服務端口;',
Active int default 0 comment '運作狀态 1開啟 0關閉;',
MaxCameraNum int default 0 comment '伺服器最大攝像頭數量;',
CurrentCameraNum int default 0 comment '伺服器目前攝像頭數量;',
ServerAlarmNum int default 0 comment '伺服器觸發警報警戒值;',
UpdateTime TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新時間:',
Remark varchar(255) comment'備用字段;'
);
alter table SVRTbl comment '建立伺服器配置表';
create table IF NOT EXISTS VSSDomainUnitTbl
(
ID int primary key auto_increment comment '自增ID;',
DevPubID varchar(32) not null comment '一級裝置賬号;',
DomainPubID char(32) not null unique comment '域名ID;',
Name char(128) comment '名稱;',
BusinessGroupID char(32) comment '業務分組ID;',
ParentId char(64) comment '父節點ID;',
UpdateTime TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新時間;'
);
alter table VSSDomainUnitTbl comment '建立一級裝置表';
alter table VSSDomainUnitTbl add constraint FK_VSSDomainUnitTbl foreign key (DevPubID) references VSSDevTbl (DevPubID) on delete cascade;
create table IF NOT EXISTS VSSRtmpCallTbl
(
ID int primary key auto_increment comment '自增ID;',
ChanPubID varchar(32) not null unique comment '二級裝置賬号;',
RtmpUrl varchar(256) comment 'rtmp位址;' ,
HlsUrl varchar(256) comment 'hls位址;' ,
Enable smallint DEFAULT 1 comment '是否啟用;',
Status int DEFAULT 0 comment'請求視訊的狀态;',
UpdateTime TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新時間;'
);
alter table VSSRtmpCallTbl comment 'RTMP會話表';
alter table VSSRtmpCallTbl add constraint FK_VSSRtmpCallTbl foreign key (ChanPubID) references VSSChannelTbl (ChanPubID) on delete cascade;
drop PROCEDURE IF EXISTS VSSDBProcPageView;
delimiter //
CREATE PROCEDURE VSSDBProcPageView
(
IN $TableName VARCHAR(200),
IN $FieldList VARCHAR(2000),
IN $PrimaryKey VARCHAR(100),
IN $Where VARCHAR(1000),
IN $Order VARCHAR(1000),
IN $SortType INT,
IN $RecorderCount INT,
IN $PageSize INT,
IN $PageIndex INT,
OUT $TotalCount INT,
OUT $TotalPageCount INT
)
BEGIN
IF !( ($TableName is null OR $TableName='') OR ($FieldList is null OR $FieldList='') OR ($PrimaryKey is null OR $PrimaryKey='') OR $SortType < 1 OR $SortType >3 OR $RecorderCount < 0 OR $PageSize < 0 OR $PageIndex < 0) THEN
IF ($where is null OR $where='') THEN
SET @new_where1 = ' ' ;
SET @new_where2 = ' WHERE ' ;
ELSE
SET @new_where1 =concat(' WHERE ',$where);
SET @new_where2 =concat(' WHERE ',$where,' AND ');
END IF;
IF $order='' OR $SortType = 1 OR $SortType = 2 THEN
IF $SortType = 1 THEN
SET @new_order =concat(' ORDER BY ',$PrimaryKey,' ASC' );
END IF;
IF $SortType = 2 THEN
SET @new_order =concat(' ORDER BY ',$PrimaryKey,' DESC');
END IF;
ELSE
SET @new_order =concat(' ORDER BY ',$Order);
END IF;
SET @SqlCount = concat('SELECT COUNT(*) into @TotalCount FROM ',$TableName,@new_where1);
SET @SqlCount1 = concat('SELECT CEILING((COUNT(*)+0.0)/',$PageSize,') into @TotalPageCount FROM ',$TableName,@new_where1);
IF $RecorderCount = 0 THEN
PREPARE stmt1 FROM @SqlCount;
EXECUTE stmt1;
set [email protected];
PREPARE stmt1 FROM @SqlCount1;
EXECUTE stmt1;
set [email protected];
ELSE
set $TotalCount = $RecorderCount;
END IF;
IF $PageIndex > CEILING(($TotalCount+0.0)/$PageSize) THEN
SET $PageIndex = CEILING(($TotalCount+0.0)/$PageSize);
END IF;
IF $PageIndex = 0 or $PageIndex = 1 THEN
SET @Sql=concat('SELECT ',$FieldList,' FROM ',$TableName,@new_where1,@new_order,' limit ',$PageSize);
ELSE
IF $SortType = 1 THEN
SET @Sql=concat('SELECT ',$FieldList,' FROM ',$TableName,@new_where2,$PrimaryKey,' > (SELECT max(',$PrimaryKey,') FROM (SELECT ',$PrimaryKey,' FROM ',$TableName,@new_where1,@new_order,' limit ',$PageSize*($PageIndex-1),' ) AS TMP) ',@new_order,' limit ',$PageSize);
END IF;
IF $SortType = 2 THEN
SET @Sql=concat('SELECT ',$FieldList,' FROM ',$TableName,@new_where2,$PrimaryKey,' < (SELECT MIN(',$PrimaryKey,') FROM (SELECT ',$PrimaryKey,' FROM ',$TableName,@new_where1,@new_order,' limit ',$PageSize*($PageIndex-1),' ) AS TMP) ',@new_order,' limit ',$PageSize);
END IF;
IF $SortType = 3 THEN
IF INSTR($Order,',') > 0 THEN
SET @Sql=concat('SELECT ',$FieldList,' FROM ',$TableName,@new_where2,$PrimaryKey,' NOT IN (SELECT ',$PrimaryKey,' FROM (SELECT ',$PrimaryKey,' FROM ',$TableName,@new_where1,@new_order,' limit ',$PageSize*($PageIndex-1),' ) a)',@new_order,' limit ',$PageSize);
ELSE
SET @new_order =concat(' ORDER BY ',$PrimaryKey,' ASC' );
SET @Sql=concat('SELECT ',$FieldList,' FROM ',$TableName,@new_where2,$PrimaryKey,' > (SELECT max(',$PrimaryKey,') FROM (SELECT ',$PrimaryKey,' FROM ',$TableName,@new_where1,@new_order,' limit ',$PageSize*($PageIndex-1),' ) AS TMP) ',@new_order,' limit ',$PageSize);
END IF;
END IF;
END IF;
Prepare stmt2 from @Sql;
execute stmt2;
END IF;
END;
//
delimiter ;