bytedeco/javacv

grabbing frames only in each second

Open

#2,211 创建于 2024年3月28日

在 GitHub 查看
 (9 评论) (0 反应) (0 负责人)Java (1,583 fork)batch import
help wantedquestion

仓库指标

Star
 (6,985 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

private void initialiseFrameGrabber() { log.info("Starting new stream"); this.frameGrabber = new FFmpegFrameGrabber(RTSP_URL); this.frameGrabber.setFrameRate(1); try { this.frameGrabber.start(); } catch (FrameGrabber.Exception e) { log.error("error during starting frame grabber {}", e.getMessage()); } }

private void grabAndProcessFrame() {
    while (true) {
        try {
            Frame frame = frameGrabber.grab();
            boolean t = frame.keyFrame;
            log.info("t: {}", t);
            if (frame != null) {
                log.info("Getting new frame with time: {}", now());
                byte[] image = imageConverter.convertFrameToByteArray(frame);
                executor.execute(() -> recognitionService.recognizePlate(image));
            }

// frameGrabber.waitForTimestamp() // Thread.sleep(1000); } catch (FrameGrabber.Exception e) { log.error("Exception during getting new frame! {}", e.getMessage()); } catch (InterruptedException e) { throw new RuntimeException(e); } } }

I want actually to grab frame only on each second. This is not valid code because it grabes frames which are in stream queue. Do you have some code or any solution how to handle getting frames only at each second, or to delay them somehow?

贡献者指南