首次建设网站流程图,网站内页怎样做优化,美食网站建设前的市场分析,免费建购物网站开始之前请参考海康官方SDK文档 鉴于前段时间刚接触视频这一块#xff0c;整理了自己的一些经验#xff0c;具体的你们还是参考文档来吧 附上文档地址
https://open.hikvision.com/docs/docId?productId5c67f1e2f05948198c909700curNodeId16741aecc05944a6b0cd1341d68…开始之前请参考海康官方SDK文档 鉴于前段时间刚接触视频这一块整理了自己的一些经验具体的你们还是参考文档来吧 附上文档地址
https://open.hikvision.com/docs/docId?productId5c67f1e2f05948198c909700curNodeId16741aecc05944a6b0cd1341d68e4546#b5bd6fd9
不要问我哪里来的 问就是白嫖…
文档中有各种API接口请根据自己的业务需求使用
想要实验之前 你还需要搭建自己的视频服务器centos7就可以 首先你还要有一台海康的网络摄像头 这个嘛就是单纯测试的别忘了导入海康的坐标和lib包
安全认证库已上传公网仓库maven依赖坐标 !--海康依赖--dependencygroupIdcom.hikvision.ga/groupIdartifactIdartemis-http-client/artifactIdversion1.1.3/version/dependencyartemis-http-client-1.1.3.jar —从Hikvision AI Cloud开放平台网站https://open.hikvision.com/download/上下载“OpenAPI安全认证库Java”获取artemis-http-client.jar导入到Java工程中。 具体的也不细说文档够仔细了…
我把我自己写的业务需要的封装的工具类列出来你们参考一下
public class ArtemisUtil {private static final Logger logger LoggerFactory.getLogger(ArtemisUtil.class);static {// 代理API网关nginx服务器ip端口ArtemisConfig.host ;// 秘钥appkeyArtemisConfig.appKey ;// 秘钥appSecretArtemisConfig.appSecret ;}/*** 能力开放平台的网站路径*/private static final String ARTEMIS_PATH /artemis;/* *//*** 订阅报警事件*//*public static String alarmSubscription() {final String previewURLsApi ARTEMIS_PATH /api/eventService/v1/eventSubscriptionByEventTypes;MapString, String path new HashMapString, String(2) {{put(HTTP ://, previewURLsApi);//根据现场环境部署确认是http还是https}};String contentType application/json;JSONObject jsonBody new JSONObject();//订阅事件的类型,防区报警,int[] arr ConstParams.SUBSCRIBE_EVENT_TYPE_ARR;jsonBody.put(eventTypes, arr);String backUrl http:// ConstParams.CALLBACK_IP : ConstParams.CALLBACK_PORT ConstParams.CALLBACK_URL;logger.info(事件回调接口: backUrl);// 接受事件的回调接口jsonBody.put(eventDest, backUrl);String body jsonBody.toJSONString();String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数return result;}*//*** 取消订阅事件*//* public static String cancelAlarmSubscription() {final String previewURLsApi ARTEMIS_PATH /api/eventService/v1/eventUnSubscriptionByEventTypes;MapString, String path new HashMapString, String(2) {{put(ConstParams.ARTEMIS_HTTP ://, previewURLsApi);}};String contentType application/json;JSONObject jsonBody new JSONObject();//取消订阅事件类型int[] arr ConstParams.CANCEL_SUBSCRIBE_EVENT_TYPE_ARR;jsonBody.put(eventTypes, arr);String body jsonBody.toJSONString();String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数return result;}*//*** 分页获取区域列表*/public static String getAllRegionInfo(int pageNo, int pageSize) {String getRootApi ARTEMIS_PATH /api/resource/v1/regions;MapString, String path new HashMapString, String(2) {{put(https://, getRootApi);}};String contentType application/json;JSONObject jsonBody new JSONObject();jsonBody.put(pageNo, pageNo);jsonBody.put(pageSize, pageSize);String body jsonBody.toJSONString();String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);return result;}/*** 根据区域编号获取下级监控点列表*/public static String getCamerasByRegionCode(String regionIndexCode, int pageNo, int pageSize) {String getRootApi ARTEMIS_PATH /api/resource/v1/regions/regionIndexCode/cameras;MapString, String path new HashMapString, String(2) {{put(http://, getRootApi);}};String contentType application/json;JSONObject jsonBody new JSONObject();jsonBody.put(pageNo, pageNo);jsonBody.put(pageSize, pageSize);jsonBody.put(regionIndexCode, regionIndexCode);String body jsonBody.toJSONString();String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);return result;}/*** 根据设备编号获取监控点详细信息*/public static String getCameraInfo(String cameraIndexCode) {String getRootApi ARTEMIS_PATH /api/resource/v1/cameras/indexCode;MapString, String path new HashMapString, String(2) {{put(https://, getRootApi);}};String contentType application/json;JSONObject jsonBody new JSONObject();jsonBody.put(cameraIndexCode, cameraIndexCode);String body jsonBody.toJSONString();String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);return result;}/*** 查询监控点列表(此处为根据一定条件进行查询若不指定查询条件即全量获取所有的监控点信息)*/public static String getCamerasByParams() {String getRootApi ARTEMIS_PATH /api/resource/v1/camera/advance/cameraList;MapString, String path new HashMapString, String(2) {{put(https://, getRootApi);}};String contentType application/json;JSONObject jsonBody new JSONObject();jsonBody.put(pageNo, 1);jsonBody.put(pageSize, 100);
// jsonBody.put(regionIndexCode, 143c69e3-1478-4b31-8ec7-d0b78df09484);//区域唯一标识
// jsonBody.put(cameraIndexCodes, a8f74dcf14f846bb95c8dff6684f897e);//监控点唯一标识集,多个值使用英文逗号分隔
// jsonBody.put(encodeDevIndexCode, 73c2e4903a4547f8812a26d329802cd0);//所属编码设备唯一标识
// jsonBody.put(isCascade, 1);//是否级联,0非级联 1级联 2不限String body jsonBody.toJSONString();String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);return result;}/*** 获取预览取流的url*/public static String getCameraPreviewURL(String cameraIndexCode) {final String getCamsApi ARTEMIS_PATH /api/video/v1/cameras/previewURLs;MapString, String path new HashMapString, String(2) {{put(https://, getCamsApi);}};String contentType application/json;JSONObject jsonBody new JSONObject();jsonBody.put(cameraIndexCode, cameraIndexCode);//监控点唯一标识jsonBody.put(streamType, 0);//码流类型,0:主码流1:子码流2:第三码流参数不填默认为主码流jsonBody.put(protocol, rtsp);//取流协议,“rtsp”:RTSP协议,“rtmp”:RTMP协议,“hls”:HLS协议jsonBody.put(transmode, 1);//传输协议,0:UDP1:TCP默认是TCPjsonBody.put(expand, streamformps);//扩展内容,格式keyvalueString body jsonBody.toJSONString();String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);return result;}/*** 获取监控点回放取流url*/public static String getCameraPlayBackURL(String cameraIndexCode, String beginTime, String endTime) {String getRootApi ARTEMIS_PATH /api/video/v2/cameras/playbackURLs;MapString, String path new HashMapString, String(2) {{put(https://, getRootApi);}};String contentType application/json;JSONObject jsonBody new JSONObject();jsonBody.put(cameraIndexCode, cameraIndexCode);jsonBody.put(recordLocation, 1);//存储类型,0中心存储1设备存储默认为中心存储jsonBody.put(protocol, rtsp);jsonBody.put(transmode, 1);jsonBody.put(beginTime, beginTime);//开始查询时间jsonBody.put(endTime, endTime);//结束查询时间,IOS8601格式yyyy-MM-dd’T’HH:mm:ss.SSSXXXjsonBody.put(expand, streamformps);String body jsonBody.toJSONString();String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);return result;}//TODO 布撤防接口public static String setDefenceStatus(String subSystemIndexCode, String deviceIndexCode, int status) {final String api ARTEMIS_PATH /api/daf/v1/subsystem/status/set;MapString, String path new HashMapString, String(2) {{put(https://, api);}};String contentType application/json;JSONArray jsonArray new JSONArray();JSONObject jsonObject new JSONObject();jsonObject.put(subSystemIndexCode, subSystemIndexCode);jsonObject.put(status, status);//0-撤防1-布防jsonArray.add(jsonObject);JSONObject params new JSONObject();params.put(subSystems, jsonArray);JSONObject jsonBody new JSONObject();jsonBody.put(method, SetDefenceStatus);jsonBody.put(params, params);String body jsonBody.toJSONString();HashMapString, String header new HashMap();header.put(DeviceIndexCode, deviceIndexCode);//System.out.println(jsonBody.toJSONString());String result null;if (StringUtils.isNotEmpty(subSystemIndexCode) StringUtils.isNotEmpty(deviceIndexCode)) {result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, header);}return result;}/*** 5.4.3.3 获取资源列表*/public static String getResourceListByPage() {String getRootApi ARTEMIS_PATH /api/irds/v1/deviceResource/resources;MapString, String path new HashMapString, String(2) {{put(https://, getRootApi);//根据现场环境部署确认是http还是https}};String contentType application/json;JSONObject jsonBody new JSONObject();jsonBody.put(pageNo, 1);jsonBody.put(pageSize, 100);jsonBody.put(resourceType, subSys);//子系统通道String body jsonBody.toJSONString();//返回的indexCode是子系统编码()String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);return result;}/*** 监控点3D放大*/public static String CameraThreeDSelZoom(){String getRootApi ARTEMIS_PATH /api/video/v1/ptzs/selZoom;MapString, String path new HashMapString, String(2) {{put(https://, getRootApi);//根据现场环境部署确认是http还是https}};String contentType application/json;JSONObject jsonBody new JSONObject();jsonBody.put(cameraIndexCode, e66493f4ca9d4264a0bbb091887fec4b);jsonBody.put(startX, 10);jsonBody.put(startY, 40);jsonBody.put(endX, 10);jsonBody.put(endY, 40);String body jsonBody.toJSONString();/*** STEP6调用接口*/String result ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);System.out.println(result);return result;}/*根据监控点列表查询录像完整性结果*/public static String list(List listRequest){String listDataApi ARTEMIS_PATH /api/nms/v1/record/list;MapString,String path new HashMapString,String(2){{put(https://,listDataApi);}};JSONObject jsonBody new JSONObject();jsonBody.put(pageNo, 1);jsonBody.put(pageSize, 20);String body jsonBody.toJSONString(listRequest);String result ArtemisHttpUtil.doPostStringArtemis(path,body,null,null,application/json);return result;}/*** 时间格式转换* 将时间抓换成IOS8601格式* param data* param formatType* return*/public static String dateToString(Date data, String formatType){return new SimpleDateFormat(formatType).format(data);}
}static静态代码块的内容根据自己的进行修改//
在附上我做测试的controller
Slf4j
RestController
RequestMapping(/t-sys-video)
Api(tags 海康视频接口)
public class VideoController extends BaseController {ApiOperation(获取实时预览取流的url)PostMapping(/cameraIndexCode)public ResultEntity cameraIndexCode() {//查看监控点列表String camerasByParams ArtemisUtil.getCamerasByParams();JSONObject jsonObject JSONObject.parseObject(camerasByParams);String data jsonObject.getString(data);JSONObject jsonData JSONObject.parseObject(data);String list jsonData.getString(list);//JSONObject jsonList JSONObject.parseObject();JSONArray jsonArray JSONObject.parseArray(list);ArrayListString result new ArrayList();if (Objects.nonNull(jsonArray) jsonArray.size() 0) {for (Object object : jsonArray) {JSONObject parseObject JSONObject.parseObject(object.toString());String cameraIndexCode parseObject.getString(cameraIndexCode);result.add(cameraIndexCode);}}for (String cameraIndexCode : result) {String cameraPreviewURL null;try {//获取实时预览URLcameraPreviewURL ArtemisUtil.getCameraPreviewURL(cameraIndexCode);JSONObject json JSONObject.parseObject(cameraPreviewURL);String resultData json.getString(data);JSONObject da JSONObject.parseObject(resultData);String url da.getString(url);return ResultEntity.ok(url);} catch (Exception e) {log.error(e.getMessage());return ResultEntity.error(MessageConstant.GET_VIEDO_PREVIEW_ERROR_MSG);}}return ResultEntity.ok();}/*** 根据每个侯问室的摄像头编号记录审问期间视频** param cameraIndexCode* param beginTime* param endTime* return*/ApiOperation(获取监控点回放取流url)PostMapping(/indexTime)public ResultEntity indexTime(RequestParam(cameraIndexCode) ApiParam(name cameraIndexCode, value 摄像头id) String cameraIndexCode,RequestParam(beginTime) ApiParam(name beginTime, value 开始时间) String beginTime,RequestParam(endTime) ApiParam(name endTime, value 结束时间) String endTime) {String cameraPlayBackURL null;try {cameraPlayBackURL ArtemisUtil.getCameraPlayBackURL(cameraIndexCode, beginTime, endTime);} catch (Exception e) {log.error(e.getMessage());return ResultEntity.error(MessageConstant.GET_VIEDO_PREVIEW_ERROR_MSG);}JSONObject json JSONObject.parseObject(cameraPlayBackURL);String resultData json.getString(data);JSONObject da JSONObject.parseObject(resultData);String url da.getString(url);return ResultEntity.ok(url);}
}声明一下 这个获取到的视频流是rtsp格式并不能直接在浏览器播放不过可以通过网络串流播放例如使用VLC播放器进行播放
以上代码是可以获取到视频流的本人亲测有效不过很遗憾这样方法用在实际项目中实不可取的对接硬件摄像机可能有球形…各种不同类型的网络摄像机所以我们最后采取的方法是采用国标流服务器对接海康的国标流服务器只用配置一下每个摄像机就可以从海康的国标流服务器获取到数据如何对接这个你们需要跟海康的技术人员联系具体根据各自公司业务需求来