I am trying to capture video through an external Logitec C922 camera. Using java, I can make this possible through the api webcam.
<dependency> <groupId>com.github.sarxos</groupId> <artifactId>webcam-capture</artifactId> <version>0.3.10</version> </dependency> <dependency> <groupId>xuggle</groupId> <artifactId>xuggle-xuggler</artifactId> <version>5.4</version> </dependency>
However, for the life of me, I cannot record at 60FPS. The video accidentally stutters when saving and is not quite smooth.
I can connect to the camera using the following data.
final List<Webcam> webcams = Webcam.getWebcams(); for (final Webcam cam : webcams) { if (cam.getName().contains("C922")) { System.out.println("### Logitec C922 cam found"); webcam = cam; break; } }
I set the cam size as follows:
final Dimension[] nonStandardResolutions = new Dimension[] { WebcamResolution.HD720.getSize(), }; webcam.setCustomViewSizes(nonStandardResolutions); webcam.setViewSize(WebcamResolution.HD720.getSize()); webcam.open(true);
And then I capture the images:
while (continueRecording) { // capture the webcam image final BufferedImage webcamImage = ConverterFactory.convertToType(webcam.getImage(), BufferedImage.TYPE_3BYTE_BGR); final Date timeOfCapture = new Date(); // convert the image and store final IConverter converter = ConverterFactory.createConverter(webcamImage, IPixelFormat.Type.YUV420P); final IVideoPicture frame = converter.toPicture(webcamImage, (System.currentTimeMillis() - start) * 1000); frame.setKeyFrame(false); frame.setQuality(0); writer.encodeVideo(0, frame); }
My writer is defined as follows:
final Dimension size = WebcamResolution.HD720.getSize(); final IMediaWriter writer = ToolFactory.makeWriter(videoFile.getName()); writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, size.width, size.height);
I'm honestly not sure what could be the reason for this in my code. Given that I am lowering the resolution, I have no problem. (480p) Could the problem be with the codes that I use?