我正在尝试编写一个可以无损格式录制视频的应用程序。为此,我使用Webcam-Capture和Xuggler库。一切正常但外播视频有以下工件:
这并不是在所有帧中观察到的,几乎是5个帧中的一个。我的代码:
@FXML
public void record() {
File file = new File("output.wmv");
IMediaWriter writer = ToolFactory.makeWriter(file.getName());
Dimension size = WebcamResolution.VGA.getSize();
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_RAWVIDEO, size.width, size.height);
Webcam webcam = Webcam.getDefault();
webcam.setViewSize(size);
webcam.open(true);
long start = System.currentTimeMillis();
for (int i = 0; i < 50; i++) {
System.out.println("Capture frame " + i);
BufferedImage image = ConverterFactory.convertToType(webcam.getImage(), BufferedImage.TYPE_3BYTE_BGR);
IConverter converter = ConverterFactory.createConverter(image, IPixelFormat.Type.YUV420P);
IVideoPicture frame = converter.toPicture(image, (System.currentTimeMillis() - start) * 1000);
frame.setKeyFrame(i == 0);
frame.setQuality(100);
writer.encodeVideo(0, frame);
// 10 FPS
try {
Thread.sleep(40);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
writer.close();
System.out.println("Video recorded in file: " + file.getAbsolutePath());
}
我做错了什么?
答案 0 :(得分:0)
需要有关您的依赖项的更多信息。链接可能吗?