700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 海康威视 iSecure Center 平台预览监控

海康威视 iSecure Center 平台预览监控

时间:2018-12-18 06:53:11

相关推荐

海康威视 iSecure Center 平台预览监控

1、需求:基于海康威视的ISC平台做二次开发,以视频预览为例进行简单阐述。

2、版本号:ISC V1.3.0

3、参考并感谢海康威视平台文档:/docs/5dc5969b3ad3fd808b9f7238bf1fa124

4、请仔细阅读海康提供的公开文档,通过平台的公开API进行访问,屏蔽复杂的逻辑和推流操作。

具体的代码如下所示:

package ga;import com.alibaba.fastjson.JSONArray;import com.alibaba.fastjson.JSONObject;import com.hikvision.artemis.sdk.ArtemisHttpUtil;import com.hikvision.artemis.sdk.config.ArtemisConfig;import java.util.*;public class GetCameraPreviewURL {static {ArtemisConfig.host = "ip,端口不用写";// 代理API网关nginx服务器ip端口ArtemisConfig.appKey = "秘钥appkey";// 秘钥appkeyArtemisConfig.appSecret = "秘钥appSecret";// 秘钥appSecret}private static final String ARTEMIS_PATH = "/artemis";public static String GetCameraPreviewURL(String cameraIndexCode) {/*** STEP3:设置接口的URI地址*/final String previewURLsApi = ARTEMIS_PATH + "/api/video/v1/cameras/previewURLs";Map<String, String> path = new HashMap<String, String>(2) {{put("https://", previewURLsApi);//根据现场环境部署确认是http还是https}};/*** STEP4:设置参数提交方式*/String contentType = "application/json";/*** STEP5:组装请求参数*/JSONObject jsonBody = new JSONObject();jsonBody.put("cameraIndexCode", cameraIndexCode);jsonBody.put("streamType", 0);jsonBody.put("protocol", "rtmp");jsonBody.put("transmode", 1);jsonBody.put("expand", "streamform=ps");String body = jsonBody.toJSONString();/*** STEP6:调用接口*/String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数return result;}/*** 视频列表** @return*/private static String getCameraList() {final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/cameras";Map<String, String> path = new HashMap<String, String>(2) {{put("https://", previewURLsApi);//根据现场环境部署确认是http还是https}};/*** STEP4:设置参数提交方式*/String contentType = "application/json";/*** STEP5:组装请求参数*/JSONObject jsonBody = new JSONObject();jsonBody.put("pageNo", 10);jsonBody.put("pageSize", 10);String body = jsonBody.toJSONString();/*** STEP6:调用接口*/String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数return result;}/*** 视频在线列表** @return*/private static String getCameraListOnline(List<String> strArray) {/*** STEP3:设置接口的URI地址*/final String previewURLsApi = ARTEMIS_PATH + "/api/nms/v1/online/camera/get";Map<String, String> path = new HashMap<String, String>(2) {{put("https://", previewURLsApi);//根据现场环境部署确认是http还是https}};/*** STEP4:设置参数提交方式*/String contentType = "application/json";/*** STEP5:组装请求参数*/JSONObject jsonBody = new JSONObject();jsonBody.put("regionId", "root000000");jsonBody.put("includeSubNode", "1");jsonBody.put("indexCodes", strArray);jsonBody.put("status", 1);jsonBody.put("pageNo", 1);jsonBody.put("pageSize", 10);String body = jsonBody.toJSONString();/*** STEP6:调用接口*/String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数return result;}/*** 获取根区域信息** @return*/private static String getRegionsRoot() {final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/regions/root";Map<String, String> path = new HashMap<String, String>(2) {{put("https://", previewURLsApi);//根据现场环境部署确认是http还是https}};String contentType = "application/json";JSONObject jsonBody = new JSONObject();jsonBody.put("pageNo", 1);jsonBody.put("pageSize", 10);String body = jsonBody.toJSONString();/*** STEP6:调用接口*/String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数return result;}/*** 获取根区域信息** @return*/private static String getSubRegions() {final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v2/regions/subRegions";Map<String, String> path = new HashMap<String, String>(2) {{put("https://", previewURLsApi);//根据现场环境部署确认是http还是https}};String contentType = "application/json";JSONObject jsonBody = new JSONObject();jsonBody.put("parentIndexCode", "-1");jsonBody.put("resourceType", "camera");jsonBody.put("pageNo", 1);jsonBody.put("pageSize", 10);jsonBody.put("cascadeFlag", 0);String body = jsonBody.toJSONString();/*** STEP6:调用接口*/String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数return result;}public static void main(String[] args) {String result = getCameraList();JSONObject object = JSONObject.parseObject(result);JSONObject data = (JSONObject) object.get("data");JSONArray dataList = (JSONArray) data.get("list");List<String> cameraCodeList = new ArrayList<>();// 获取视频列表for (Object obj : dataList) {// System.out.println(obj);cameraCodeList.add(((JSONObject) obj).getString("cameraIndexCode"));}// 判断是否在线JSONObject onlineObj = JSONObject.parseObject(getCameraListOnline(cameraCodeList));JSONObject jsonObject = (JSONObject) onlineObj.get("data");cameraCodeList.clear();for (Object onlineCamera : (JSONArray) jsonObject.get("list")) {// 区域编号String regionIndexCode = ((JSONObject) onlineCamera).getString("regionIndexCode");// 区域String regionName = ((JSONObject) onlineCamera).getString("regionName");// 摄像头编码String indexCode = ((JSONObject) onlineCamera).getString("indexCode");// 在线String online = "1".equals(((JSONObject) onlineCamera).getString("online")) ? "在线" : "不在线";// cnString cn = ((JSONObject) onlineCamera).getString("cn");System.out.println("区域编码:" + regionIndexCode + "\t区域名:" + regionName + "\t摄像头编码:" + indexCode + "\t在线:" + online + "\tcn:" + cn);if ("在线".equals(online)) {cameraCodeList.add(indexCode);}}for (String cameraCode : cameraCodeList) {String url = GetCameraPreviewURL(cameraCode);}}}

5、其中秘钥appkey和秘钥appSecret,联系管理员做如下准备:

开发前需要先获取对接的身份认证信息,AK/SK;平台会通过AK/SK认证方式来验证请求发送者的身份。

1.进入运管中心(http://ip:8001/center),进入【状态监控】模块,选择【API网关】,选择【API管理】功能,进入API管理中心。

2.选择【合作方管理】,平台安装后,默认会创建一个对内合作方,可以使用此合作方进行接口调用测试,实际运行环境需要根据实际的情况创建新的合作方。

3.点击合作方的名称,进入合作方详情界面,获取合作方key(AK)和合作方Secret(SK)。

6、程序跑通之后,我们会获取到视频的rtmp协议(我设置的协议是rtmp),日志如下所示:

com.hikvision.artemis.sdk.ArtemisHttpUtil - the Artemis Request is Success,statusCode:200 SuccessMsg:{"code":"0","msg":"success","data":{"url":"rtmp://192.168.20.130:1935/live/openUrl/7SIswj6"}}

7、使用rtmp://192.168.20.130:1935/live/openUrl/7SIswj6协议在vlc中能够正常播放;

8、我们嵌入到vue中或者使用如下代码进行测试,总是无法播放,这个问题困扰了我半个月,一直在找解决办法。直到5月26日得到海康威视二次开发群(150425667)的群友的支持,才得以解决,在此再次感谢这位群友。

rtmp://192.168.20.130:1935/live/openUrl/7SIswj6 后面 加上斜杠/ 即可正常播放

<!DOCTYPE html><html lang="en"><head><title>Video.js | HTML5 Video Player</title><!-- <link href="video-js-6.2.0/video-js.css" rel="stylesheet"><script src="video-js-6.2.0/videojs-ie8.min.js"></script> --><link href="/5.20.1/video-js.css" rel="stylesheet"><script src="/5.20.1/videojs-ie8.min.js"></script></head><body><!--<video id="example_video_1" class="video-js vjs-default-skin" controls preload="auto" width="1280" height="720" poster="/v/oceans.png" data-setup="{}">--><!-- &lt;!&ndash; 湖南卫视 &ndash;&gt;--><!-- <source src="rtmp://58.200.131.2:1935/livetv/hunantv" type="rtmp/flv">--><!-- <p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="/html5-video-support/" target="_blank">supports HTML5 video</a></p>--><!--</video>--><video id="example_video_1" class="video-js vjs-default-skin" controls preload="auto" width="1280" height="720" poster="/v/oceans.png" data-setup="{}"><!-- 湖南卫视 --><source src="rtmp://192.168.20.130:1935/live/openUrl/6uhHAac/" type="rtmp/flv"><p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="/html5-video-support/" target="_blank">supports HTML5 video</a></p></video><script src="/5.20.1/video.js"></script></body></html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。