| | |
| | | |
| | | |
| | | @Override |
| | | public String getFrameImgByDevice(String deviceId, String channelId, String workOrderNo) { |
| | | public synchronized String getFrameImgByDevice(String deviceId, String channelId, String workOrderNo) { |
| | | String url = String.format(this.rtspServer + "/api/play/start/%s/%s", deviceId, channelId); |
| | | String result = HttpUtils.sendGet(url); |
| | | WVPResult wvpResult = JSON.parseObject(result, WVPResult.class); |
| | |
| | | System.out.println("目标地址:" + rtspUrl); |
| | | FFmpegFrameGrabber grabber = null; |
| | | try { |
| | | grabber = FFmpegFrameGrabber.createDefault(rtspUrl); |
| | | grabber = new FFmpegFrameGrabber(rtspUrl); |
| | | // grabber.setOption("rtsp_transport", "tcp"); // 使用tcp的方式,不然会丢包很严重 |
| | | // grabber.setVideoOption("probesize", "10000"); // 设置捕获分析的最大字节 |
| | | //设置10s超时 |
| | | grabber.setTimeout(10000); |
| | | grabber.start(); |
| | | Frame frame = grabber.grabImage(); // 直接捕获一帧 |
| | | if (frame != null) { |
| | |
| | | } else { |
| | | System.out.println("未捕获到帧"); |
| | | } |
| | | } catch (Exception e) { |
| | | } catch (FrameGrabber.Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | if (grabber != null) { |
| | | try { |
| | | grabber.stop(); // 停止捕获 |
| | | grabber.release(); |
| | | } catch (FrameGrabber.Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | } |
| | | } |
| | | } else { |
| | | System.out.println("请求失败,错误码:" + wvpResult.getCode()); |
| | | System.out.println("请求失败,错误码:" + wvpResult.getCode() + "--" + wvpResult.getMsg()); |
| | | } |
| | | System.out.println("图片URL:" + imgUrl); |
| | | return imgUrl; |