fuliqi
2024-09-30 b571b243fe34b63ced919cbf7c56da0e48dbdac4
ycl-server/src/main/java/com/ycl/platform/service/impl/WorkOrderServiceImpl.java
@@ -758,7 +758,7 @@
    @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);
@@ -770,7 +770,11 @@
                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) {
@@ -789,13 +793,12 @@
                    } 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();
                        }
@@ -803,7 +806,7 @@
                }
            }
        } else {
            System.out.println("请求失败,错误码:" + wvpResult.getCode());
            System.out.println("请求失败,错误码:" + wvpResult.getCode() + "--" + wvpResult.getMsg());
        }
        System.out.println("图片URL:" + imgUrl);
        return imgUrl;