直接上代码吧:
前端页面专递点的x和y的坐标及其设备的ip
@RequestMapping(value = "/getRealTemperatureByPoint") public float getRealTemperatureByPoint(HttpServletRequest request) {Map<String, Object> params = ParamUtil.getParams(request);String x = MapUtils.getString(params, "x");String y = MapUtils.getString(params, "y");String ip = MapUtils.getString(params, "ip");//根据ip获取用户名、密码和端口Map<String, Object> deviceInfo = deviceDao.getDeviceInfoByIp(ip);if (deviceInfo.size()>0){String username = (String) deviceInfo.get("username");String password = (String) deviceInfo.get("password");Short port = Short.parseShort(deviceInfo.get("port").toString());// 登陆设备int userId = ClientDemo.login_V40_x(ip, port, username, password);//取流Float temperature = VideoDemo.getTemperature(new HKPoint(Float.parseFloat(x),Float.parseFloat(y)),256, 192,userId);System.out.println("温度是·············"+((float)Math.round(temperature * 10)) / 10);return ((float)Math.round(temperature * 10)) / 10;}else {return 0.0f;}}
效果如图
部分调用的代码:videoDemo里的代码部分
package com.ydx.yemms.video.hk.NetSDKDemo;import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import com.ydx.yemms.video.hk.Thermometry.HKPoint; import org.springframework.stereotype.Component;import java.io.*; import java.nio.ByteBuffer; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Timer;import static com.ydx.yemms.video.hk.NetSDKDemo.ClientDemo.hCNetSDK; import static com.ydx.yemms.video.hk.NetSDKDemo.ClientDemo.playControl;/*** 视频取流预览,下载,抓图mok* @create 2022-03-30-9:48*/ @Component public class VideoDemo {Timer downloadtimer;//下载用定时器Timer Playbacktimer;//回放用定时器static FRealDataCallBack fRealDataCallBack;//预览回调函数实现static fPlayEScallback fPlayescallback; //裸码流回调函数static playDataCallBack playBackCallBack; //回放码流回调static int lPlay = -1; //预览句柄static int Count=0;int m_lLoadHandle;int iPlayBack; //回放句柄static File file;static boolean palybackFlay=false;static FileOutputStream outputStream;static IntByReference m_lPort= new IntByReference(-1);static String resultFileName = "..\\Download" + new String("returnFile" + ".h264");static FileOutputStream fileOutputStream = null;static int fileLenth = 0;public static void realPlay(int userID, int iChannelNo) {if (userID == -1) {System.out.println("请先注册");return;} // HCNetSDK.NET_DVR_PREVIEWINFO strClientInfo = new HCNetSDK.NET_DVR_PREVIEWINFO();HCNetSDK.NET_DVR_CLIENTINFO strClientInfo = new HCNetSDK.NET_DVR_CLIENTINFO();strClientInfo.lChannel=2; // strClientInfo.read(); // strClientInfo.hPlayWnd = 0; //窗口句柄,从回调取流不显示一般设置为空 // strClientInfo.lChannel = iChannelNo; //通道号 // strClientInfo.dwStreamType=0; //0-主码流,1-子码流,2-三码流,3-虚拟码流,以此类推 // strClientInfo.dwLinkMode=0; //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4- RTP/RTSP,5- RTP/HTTP,6- HRUDP(可靠传输) ,7- RTSP/HTTPS,8- NPQ // strClientInfo.bBlocked=1; // strClientInfo.byProtoType = 0; // strClientInfo.write();//回调函数定义必须是全局的if (fRealDataCallBack == null) {fRealDataCallBack = new FRealDataCallBack();}//开启预览lPlay = hCNetSDK.NET_DVR_RealPlay_V30(userID, strClientInfo, fRealDataCallBack , null,false); // lPlay = hCNetSDK.NET_DVR_RealPlay_V40(userID, strClientInfo, fRealDataCallBack , null);if (lPlay == -1) {int iErr = hCNetSDK.NET_DVR_GetLastError();System.out.println("取流失败" + iErr);return;}System.out.println("取流成功");//设置裸码流回调函数 // if (fPlayescallback==null) // { // fPlayescallback=new fPlayEScallback(); // } // boolean setcallback=hCNetSDK.NET_DVR_SetESRealPlayCallBack(lPlay,fPlayescallback,null); // if (setcallback==false) // { // System.out.println("设置裸码流回调失败,错误码:"+hCNetSDK.NET_DVR_GetLastError()); // }//取流解码过程中播放库从解码码流中抓图 // getPicbyPlayCtrl();/*** 预览一段时间;如果要一直取流预览,需要保证程序一直运行*/try {Thread.sleep(500);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}String path = ".\\savevideo.mp4";Boolean bSaveVideo = hCNetSDK.NET_DVR_SaveRealData_V30(lPlay,0x2,path);if (bSaveVideo == false) {int iErr = hCNetSDK.NET_DVR_GetLastError();System.out.println("NET_DVR_SaveRealData_V30 failed" + iErr);return;}System.out.println("NET_DVR_SaveRealData_V30 suss");try {Thread.sleep(0);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}Boolean bStopSaveVideo = hCNetSDK.NET_DVR_StopSaveRealData(lPlay);if (bStopSaveVideo == false) {int iErr = hCNetSDK.NET_DVR_GetLastError();System.out.println("NET_DVR_StopSaveRealData failed" + iErr);return;}System.out.println("NET_DVR_StopSaveRealData suss");if (lPlay>=0) {if (hCNetSDK.NET_DVR_StopRealPlay(lPlay)){System.out.println("停止预览成功");return;}}}//播放库抓图public static void getPicbyPlayCtrl(String path){//取流成功后,延时一段时间保证播放库解码开始try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}IntByReference pWidth = new IntByReference(0);IntByReference pHieght = new IntByReference(0);boolean bFlag = playControl.PlayM4_GetPictureSize(m_lPort.getValue(), pWidth, pHieght);if (!bFlag) {System.out.println("获取失败:" + playControl.PlayM4_GetLastError(m_lPort.getValue()));}System.out.println(pWidth.getValue());System.out.println(pHieght.getValue());IntByReference RealPicSize = new IntByReference(0);int picsize = pWidth.getValue() * pHieght.getValue() * 5;HCNetSDK.BYTE_ARRAY picByte = new HCNetSDK.BYTE_ARRAY(picsize);picByte.write();Pointer pByte = picByte.getPointer();boolean b_GetPic = playControl.PlayM4_GetJPEG(m_lPort.getValue(), pByte, picsize, RealPicSize);if (!b_GetPic) {System.out.println("抓图失败:" + playControl.PlayM4_GetLastError(m_lPort.getValue()));}picByte.read();SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");String newName = sf.format(new Date());FileOutputStream fout = null;try {fout = new FileOutputStream(path+ "/" + newName + ".jpeg");//将字节写入文件long offset = 0;ByteBuffer