0
我運行從LIB攝像頭捕捉這個簡單的樣品沒有success.Here是我的代碼和它下面我描述了異常問題java.lang.UnsupportedOperationException:無法與編解碼器編碼:CODEC_ID_MP3
File file = new File("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());
這裏是例外,爲什麼發生這種情況,我該如何解決它?
Exception in thread "main" java.lang.UnsupportedOperationException: cannot encode with codec: CODEC_ID_H264
at com.xuggle.mediatool.MediaWriter.addVideoStream(MediaWriter.java:440)
at com.xuggle.mediatool.MediaWriter.addVideoStream(MediaWriter.java:430)
at com.panos.WebCamRecorder.vRecorder(WebCamRecorder.java:80)
at com.panos.App.main(App.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)