我想使用Github API和Xuggler API从网络摄像头(IP摄像头)捕获视频。
代码:
public static void main(String[] args) throws Throwable{
System.out.println("I am inside main()");
File file = new File("d:/output.ts");
IMediaWriter writer = ToolFactory.makeWriter(file.getName());
Dimension size = WebcamResolution.QVGA.getSize();
writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_H264, 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(0);
writer.encodeVideo(0, frame);
// 10 FPS
Thread.sleep(100);
}
writer.close();
System.out.println("Video recorded in file: " + file.getAbsolutePath());
}
}
错误:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.xuggle.ferry.FerryJNI.IBuffer_make__SWIG_0(JLcom/xuggle/ferry/RefCounted;I)J
at com.xuggle.ferry.FerryJNI.IBuffer_make__SWIG_0(Native Method)
at com.xuggle.ferry.IBuffer.make(IBuffer.java:1088)
at com.xuggle.ferry.FerryJNI.<clinit>(FerryJNI.java:21)
at com.xuggle.ferry.JNIMemoryManager.setMemoryModel(JNIMemoryManager.java:1190)
at com.xuggle.mediatool.MediaWriter.<clinit>(MediaWriter.java:119)
at com.xuggle.mediatool.ToolFactory.makeWriter(ToolFactory.java:149)
at javaapplication10.VideoRecord.main(VideoRecord.java:34)