bytedeco/javacv

grabbing frames only in each second

Open

#2,211 opened on Mar 28, 2024

View on GitHub
 (9 comments) (0 reactions) (0 assignees)Java (1,583 forks)batch import
help wantedquestion

Repository metrics

Stars
 (6,985 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

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?

Contributor guide