/// <summary> /// 停止录像 /// </summary> public static bool StopRec(string IPChannel) { if (!RealHandleList.ContainsKey(IPChannel)) { return(false); } int m_lRealHandle = RealHandleList[IPChannel]; DateTime dt = DateTime.Now; if (CHCNetSDK.NET_DVR_StopSaveRealData(m_lRealHandle)) { //停止预览 Stop live view CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); //从预览列表中移除 RealHandleList.Remove(IPChannel); //将录像结束信息写入数据库 string errorInfo = ""; bool result = RecFileClass.AddEndTime(RecDataClass.recInfo[IPChannel].Name, dt.ToString("yyyy-MM-dd"), dt.ToString("HH:mm:ss"), ref errorInfo); if (!result) { MessageBox.Show(errorInfo + "停止录像失败!"); } //移除RecInfo存储信息 RecDataClass.recInfo.Remove(IPChannel); return(true); } return(false); }
/// <summary> /// 开启录像 /// </summary> /// <param name="IP"></param> /// <param name="Channel"></param> /// <returns></returns> public static int Rec(string IP, int Channel, string strDeviceID) { CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO(); //lpPreviewInfo.hPlayWnd = handle;//预览窗口 lpPreviewInfo.lChannel = Channel; //预te览的设备通道 lpPreviewInfo.dwStreamType = 0; //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推 lpPreviewInfo.dwLinkMode = 0; //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流 lpPreviewInfo.dwDisplayBufNum = 15; //播放库播放缓冲区最大缓冲帧数 CHCNetSDK.REALDATACALLBACK RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数 IntPtr pUser = new IntPtr(); //用户数据 if (!userIDList.ContainsKey(IP)) { return(-1); } int m_lUserID = userIDList[IP]; //打开预览 Start live view int m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser); if (m_lRealHandle < 0) { } else { //录像保存路径和文件名 the path and file name to save string sVideoFileName; DateTime dt = DateTime.Now; sVideoFileName = IP + "_" + Channel + dt.ToString("yyyyMMddHHmmss") + "手动.mp4"; //预览成功 //强制I帧 Make a I frame int lChannel = Channel; //通道号 Channel number CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel); //开始录像 Start recording if (CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle, path + sVideoFileName)) { RealHandleList.Add(IP + "," + Channel + "_1", m_lRealHandle); RecInfo info = new RecInfo(sVideoFileName, dt, "手动录像"); RecDataClass.recInfo.Add(IP + "," + Channel + "_1", info); //写入数据库 RecFileList recFileList = new RecFileList(); recFileList.CameraID = strDeviceID; recFileList.RecName = sVideoFileName; recFileList.RecRecFile = path + sVideoFileName; recFileList.RecStartDate = dt.ToString("yyyy-MM-dd"); recFileList.RecStartTime = dt.ToString("HH:mm:ss"); recFileList.RecType = "1"; RecFileClass.AddStartTime(recFileList); } else { return(-1); } } return(m_lRealHandle); }
/// <summary> /// 停止录像 /// </summary> public static bool StopRec(string strDeviceID) { Guid DeviceID; if (!Guid.TryParse(strDeviceID, out DeviceID)) { return(false); } Client.Entities.CameraList device = Class1.cameraList.Find( delegate(Client.Entities.CameraList camera) { return(camera.DeviceID.Equals(DeviceID)); } ); if (device == null) { return(false); } Client.Entities.StreamMediaList streamMedia = Class1.streamMediaList.Find( delegate(Client.Entities.StreamMediaList sm) { return(sm.DeviceID.Equals(device.StreamMedia_DeviceID)); }); if (streamMedia == null) { return(false); } string IPChannel = streamMedia.VideoIP + "," + device.VideoChannel + "_3"; if (!RealHandleList.ContainsKey(IPChannel)) { return(false); } int m_lRealHandle = RealHandleList[IPChannel]; DateTime dt = DateTime.Now; if (CHCNetSDK.NET_DVR_StopSaveRealData(m_lRealHandle)) { //停止预览 Stop live view CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle); //从预览列表中移除 RealHandleList.Remove(IPChannel); //将录像结束信息写入数据库 string errorInfo = ""; bool result = RecFileClass.AddEndTime(RecDataClass.recInfo[IPChannel].Name, dt.ToString("yyyy-MM-dd"), dt.ToString("HH:mm:ss"), ref errorInfo); if (!result) { MessageBox.Show(errorInfo + ",停止录像失败!"); } //移除RecInfo存储信息 RecDataClass.recInfo.Remove(IPChannel); return(true); } return(false); }
/// <summary> /// 开启录像 /// </summary> /// <param name="strDeviceID"></param> /// <returns></returns> public static int Rec(string strDeviceID, ref string errorInfo) { Guid DeviceID; if (!Guid.TryParse(strDeviceID, out DeviceID)) { errorInfo = "设备ID为" + strDeviceID; return(-1); } Client.Entities.CameraList device = Class1.cameraList.Find( delegate(Client.Entities.CameraList camera) { return(camera.DeviceID.Equals(DeviceID)); } ); if (device == null) { return(-1); } Client.Entities.StreamMediaList streamMedia = Class1.streamMediaList.Find( delegate(Client.Entities.StreamMediaList sm) { return(sm.DeviceID.Equals(device.StreamMedia_DeviceID)); }); if (streamMedia == null) { return(-1); } string IP = streamMedia.VideoIP; int Channel = device.VideoChannel; CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO(); //lpPreviewInfo.hPlayWnd = handle;//预览窗口 lpPreviewInfo.lChannel = Channel; //预te览的设备通道 lpPreviewInfo.dwStreamType = 0; //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推 lpPreviewInfo.dwLinkMode = 0; //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流 lpPreviewInfo.dwDisplayBufNum = 15; //播放库播放缓冲区最大缓冲帧数 CHCNetSDK.REALDATACALLBACK RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数 IntPtr pUser = new IntPtr(); //用户数据 if (!ManualRec.userIDList.ContainsKey(IP)) { return(-1); } int m_lUserID = ManualRec.userIDList[IP]; //打开预览 Start live view int m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser); if (m_lRealHandle < 0) { } else { //录像保存路径和文件名 the path and file name to save string sVideoFileName; DateTime dt = DateTime.Now; sVideoFileName = IP + "_" + Channel + dt.ToString("yyyyMMddHHmmss") + "报警.mp4"; //预览成功 //强制I帧 Make a I frame int lChannel = Channel; //通道号 Channel number CHCNetSDK.NET_DVR_MakeKeyFrame(m_lUserID, lChannel); //开始录像 Start recording if (CHCNetSDK.NET_DVR_SaveRealData(m_lRealHandle, path + sVideoFileName)) { RealHandleList.Add(IP + "," + Channel + "_3", m_lRealHandle); RecInfo info = new RecInfo(sVideoFileName, dt, "报警录像"); RecDataClass.recInfo.Add(IP + "," + Channel + "_3", info); //写入数据库 RecFileList recFileList = new RecFileList(); recFileList.CameraID = strDeviceID; recFileList.RecName = sVideoFileName; recFileList.RecRecFile = path + sVideoFileName; recFileList.RecStartDate = dt.ToString("yyyy-MM-dd"); recFileList.RecStartTime = dt.ToString("HH:mm:ss"); recFileList.RecType = "3"; if (!RecFileClass.AddStartTime(recFileList, ref errorInfo)) { return(-1); } } else { return(-1); } } return(m_lRealHandle); }