| | |
| | | |
| | | @Override |
| | | @SdkOperate |
| | | public void recordToMinio(CameraCmd cmd) throws IOException { |
| | | String cameraId = cmd.getCameraId(); |
| | | Integer channelNum = cmd.getChannelNum(); |
| | | boolean enable = cmd.isEnable(); |
| | | if (!globalVariable.loginMap.containsKey(cameraId)) { |
| | | return; |
| | | } |
| | | Integer userId = globalVariable.loginMap.get(cameraId); |
| | | String path = ""; |
| | | //预览参数 |
| | | NET_DVR_PREVIEWINFO previewinfo = new NET_DVR_PREVIEWINFO(); |
| | | previewinfo.read(); |
| | | previewinfo.lChannel = channelNum; |
| | | previewinfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-三码流,3-虚拟码流,以此类推 |
| | | previewinfo.dwLinkMode = 0;//连接方式:0-TCP方式,1-UDP方式,2-多播方式,3-RTP方式,4-RTP/RTSP,5-RTP/HTTP,6-HRUDP(可靠传输),7-RTSP/HTTPS,8-NPQ |
| | | previewinfo.hPlayWnd = null;//播放窗口的句柄,为NULL表示不解码显示。 |
| | | previewinfo.bBlocked = 0;//0- 非阻塞取流,1-阻塞取流 |
| | | previewinfo.byNPQMode = 0;//NPQ模式:0-直连模式,1-过流媒体模式 |
| | | previewinfo.write(); |
| | | int lRealHandle; |
| | | if (enable) { |
| | | if (!user_real_Map.containsKey(userId)) { |
| | | lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null); |
| | | if (lRealHandle == -1) { |
| | | int iErr = hCNetSDK.NET_DVR_GetLastError(); |
| | | log.error("取流失败" + iErr); |
| | | public void recordToMinio(CameraCmd cmd) { |
| | | try { |
| | | String cameraId = cmd.getCameraId(); |
| | | Integer channelNum = cmd.getChannelNum(); |
| | | boolean enable = cmd.isEnable(); |
| | | if (!globalVariable.loginMap.containsKey(cameraId)) { |
| | | return; |
| | | } |
| | | Integer userId = globalVariable.loginMap.get(cameraId); |
| | | String path = ""; |
| | | //预览参数 |
| | | NET_DVR_PREVIEWINFO previewinfo = new NET_DVR_PREVIEWINFO(); |
| | | previewinfo.read(); |
| | | previewinfo.lChannel = channelNum; |
| | | previewinfo.dwStreamType = 0;//码流类型:0-主码流,1-子码流,2-三码流,3-虚拟码流,以此类推 |
| | | previewinfo.dwLinkMode = 0;//连接方式:0-TCP方式,1-UDP方式,2-多播方式,3-RTP方式,4-RTP/RTSP,5-RTP/HTTP,6-HRUDP(可靠传输),7-RTSP/HTTPS,8-NPQ |
| | | previewinfo.hPlayWnd = null;//播放窗口的句柄,为NULL表示不解码显示。 |
| | | previewinfo.bBlocked = 0;//0- 非阻塞取流,1-阻塞取流 |
| | | previewinfo.byNPQMode = 0;//NPQ模式:0-直连模式,1-过流媒体模式 |
| | | previewinfo.write(); |
| | | int lRealHandle; |
| | | if (enable) { |
| | | if (!user_real_Map.containsKey(userId)) { |
| | | lRealHandle = hCNetSDK.NET_DVR_RealPlay_V40(userId, previewinfo, null, null); |
| | | if (lRealHandle == -1) { |
| | | int iErr = hCNetSDK.NET_DVR_GetLastError(); |
| | | log.error("取流失败" + iErr); |
| | | return; |
| | | } |
| | | log.info("取流成功"); |
| | | File file = new File("D:/recordTemp/" + cameraId + ".mp4"); |
| | | if (!file.exists()) { |
| | | File fileParent = file.getParentFile(); |
| | | if (!fileParent.exists()) { |
| | | fileParent.mkdirs(); |
| | | } |
| | | file.createNewFile(); |
| | | } |
| | | path = file.getCanonicalPath(); |
| | | recordInfo info = new recordInfo(); |
| | | info.setLRealHandle(lRealHandle); |
| | | info.setRecordPath(path); |
| | | user_real_Map.put(userId, info); |
| | | } |
| | | recordInfo info = user_real_Map.get(userId); |
| | | if (!hCNetSDK.NET_DVR_SaveRealData_V30(info.getLRealHandle(), 1, info.getRecordPath())) { |
| | | log.error("保存视频文件到临时文件夹失败 错误码为: " + hCNetSDK.NET_DVR_GetLastError()); |
| | | return; |
| | | } |
| | | log.info("取流成功"); |
| | | File file = new File("D:/recordTemp/" + cameraId + ".mp4"); |
| | | if (!file.exists()) { |
| | | File fileParent = file.getParentFile(); |
| | | if (!fileParent.exists()) { |
| | | fileParent.mkdirs(); |
| | | } |
| | | file.createNewFile(); |
| | | log.info("录像开始"); |
| | | } else { |
| | | recordInfo info = user_real_Map.get(userId); |
| | | if (StringUtils.isNull(info)) { |
| | | return; |
| | | } |
| | | path = file.getCanonicalPath(); |
| | | recordInfo info = new recordInfo(); |
| | | info.setLRealHandle(lRealHandle); |
| | | info.setRecordPath(path); |
| | | user_real_Map.put(userId, info); |
| | | } |
| | | recordInfo info = user_real_Map.get(userId); |
| | | if (!hCNetSDK.NET_DVR_SaveRealData_V30(info.getLRealHandle(), 1, info.getRecordPath())) { |
| | | log.error("保存视频文件到临时文件夹失败 错误码为: " + hCNetSDK.NET_DVR_GetLastError()); |
| | | return; |
| | | } |
| | | log.info("录像开始"); |
| | | } else { |
| | | recordInfo info = user_real_Map.get(userId); |
| | | if (StringUtils.isNull(info)) { |
| | | return; |
| | | } |
| | | hCNetSDK.NET_DVR_StopRealPlay(info.getLRealHandle()); |
| | | log.info("录像停止"); |
| | | //存入minio |
| | | String BucketName = cmd.getRecordBucketName(); |
| | | String ObjectName = cmd.getRecordObjectName(); |
| | | String ContentType = "video/MP4"; |
| | | FileInputStream stream = new FileInputStream(info.getRecordPath()); |
| | | String url = ""; |
| | | try { |
| | | hCNetSDK.NET_DVR_StopRealPlay(info.getLRealHandle()); |
| | | log.info("录像停止"); |
| | | //存入minio |
| | | String BucketName = cmd.getRecordBucketName(); |
| | | String ObjectName = cmd.getRecordObjectName(); |
| | | String ContentType = "video/MP4"; |
| | | FileInputStream stream = new FileInputStream(info.getRecordPath()); |
| | | String url = ""; |
| | | boolean b = MinioUtils.uploadObject(BucketName, ObjectName, stream, stream.available(), ContentType); |
| | | if (b) { |
| | | url = BucketName + ObjectName; |
| | | log.info("上传文件成功!" + url); |
| | | user_real_Map.remove(userId); |
| | | } |
| | | } catch (IOException ex) { |
| | | log.error("上传文件异常:" + ex.getMessage()); |
| | | } |
| | | user_real_Map.remove(userId); |
| | | } catch (Exception ex) { |
| | | log.error("录像异常" + ex.getMessage()); |
| | | } |
| | | } |
| | | } |