-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Description
I use FFmpegFrameGrabber to grab the camera (whether it's a local camera or a USB camera), and I can only grab a few frames and it's over. But when I add 100ms delay, it can keep capturing pictures.
- debug and It looks like
av_read_frame
、avcodec_receive_frame
caused it.
but I don't know how to solve it.
Tips: I tried several versions (1.5.3 ~ 1.5.7), v1 5.3 work success without 100ms delay.
- dependencies
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>openblas</artifactId>
<version>0.3.19-1.5.7</version>
<classifier>macosx-x86_64</classifier>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>opencv</artifactId>
<version>4.5.5-1.5.7</version>
<classifier>macosx-x86_64</classifier>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>ffmpeg</artifactId>
<version>5.0-1.5.7</version>
<classifier>macosx-x86_64</classifier>
</dependency>
- code
avutil.av_log_set_level(avutil.AV_LOG_TRACE);
FFmpegLogCallback.set();
FFmpegFrameGrabber.tryLoad();
FFmpegFrameGrabber grabber = FFmpegFrameGrabber.createDefault("N300");
grabber.setFormat("avfoundation");
grabber.setImageWidth(captureWidth);
grabber.setImageHeight(captureHeight);
grabber.setFrameRate(25);
// grabber.start();
grabber.startUnsafe();
final CanvasFrame cFrame = new CanvasFrame("UsbCamera", CanvasFrame.getDefaultGamma() / grabber.getGamma());
cFrame.setCanvasSize(1280, 720);
Frame capturedFrame = null;
while ((capturedFrame = grabber.grabImage()) != null) {
if (cFrame.isVisible()) {
log.info("frame grabbed at {}", grabber.getTimestamp());
cFrame.showImage(capturedFrame);
}
// TimeUnit.MILLISECONDS.sleep(100); // work with it.
}