bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.58k stars 1.58k forks source link

grabber.grabImage() ist zu langsam, um mehrere Frames hintereinander zu erhalten #1893

Open nhwxhn opened 2 years ago

nhwxhn commented 2 years ago

I want to get multiple frames in a row, but the grabber.grabImage() method is too slow, can it be optimized? Below is my code

int flag = 1;
        List<Map<Integer, Frame>> lists = new ArrayList<>();
        while (flag < 64) {
            Map<Integer,Frame> map = new HashMap<>();
            Frame frame = grabber.grabImage();
            map.put(flag,frame);
            lists.add(map);
            flag++;
        }
        log.info("lists");

        for (Map<Integer, Frame> map : lists) {
            map.forEach((k,v)->{
                DecimalFormat decimalFormat = new DecimalFormat("00000");
                String name = decimalFormat.format(k);
                File imgUrl = new File("C:\\Users\\Administrator\\Desktop\\video\\" + name + ".jpg");

                Java2DFrameConverter converter = new Java2DFrameConverter();
                BufferedImage bufferedImage = converter.getBufferedImage(v);
                try {
                    ImageIO.write(bufferedImage, "jpg", imgUrl);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
        }
saudet commented 2 years ago

You could try to use hardware acceleration: https://trac.ffmpeg.org/wiki/HWAccelIntro

nhwxhn commented 2 years ago

You could try to use hardware acceleration: https://trac.ffmpeg.org/wiki/HWAccelIntro

Thank you, I will refer to