You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static void recordCamera(String outputFile, double frameRate) throws java.lang.Exception{
//Loader.load(opencv_objdetect.class);
int captureWidth = 1280;
int captureHeight = 720;
// 0 = default camera, 1 = next, etc.
FrameGrabber grabber = new OpenCVFrameGrabber(0);
grabber.setImageWidth(captureWidth);
grabber.setImageHeight(captureHeight);
grabber.start();
OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
IplImage grabbedImage = converter.convert(grabber.grab());
int width = grabbedImage.width();
int height = grabbedImage.height();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputFile, width, height);
//recorder.setInterleaved(true);
recorder.setFormat("flv");
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264); // avcodec.AV_CODEC_ID_H264
recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
recorder.setFrameRate(frameRate);
recorder.start();
CanvasFrame canvasframe = new CanvasFrame("Video Live", CanvasFrame.getDefaultGamma() / grabber.getGamma());
canvasframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
canvasframe.setAlwaysOnTop(true);
Frame rotatedFrame=converter.convert(grabbedImage);
long startTime=0;
long videoTS=0;
while(canvasframe.isVisible() && (grabbedImage = converter.convert(grabber.grab())) != null){
rotatedFrame = converter.convert(grabbedImage);
canvasframe.showImage(rotatedFrame);
// 视频时长
if (startTime == 0) {
startTime = System.currentTimeMillis();
}
videoTS = 1000 * (System.currentTimeMillis() - startTime);
recorder.setTimestamp(videoTS);
recorder.record(rotatedFrame);
}
//释放资源
canvasframe.dispose();
recorder.stop();
recorder.release();
grabber.stop();
}
occur exception
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.bytedeco.javacpp.Loader.load(Loader.java:464)
at org.bytedeco.javacpp.Loader.load(Loader.java:409)
at org.bytedeco.javacpp.avcodec$AVPacket.(avcodec.java:1559)
at org.bytedeco.javacv.FFmpegFrameRecorder.(FFmpegFrameRecorder.java:149)
at org.bytedeco.javacv.FFmpegFrameRecorder.(FFmpegFrameRecorder.java:126)
at com.xlinyu.javacv.HelloWorld.recordCamera(HelloWorld.java:49)
at com.xlinyu.javacv.HelloWorld.main(HelloWorld.java:30)
The text was updated successfully, but these errors were encountered:
my pom.xml file and my os is win8.1
recordCamera method
occur exception
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.bytedeco.javacpp.Loader.load(Loader.java:464)
at org.bytedeco.javacpp.Loader.load(Loader.java:409)
at org.bytedeco.javacpp.avcodec$AVPacket.(avcodec.java:1559)
at org.bytedeco.javacv.FFmpegFrameRecorder.(FFmpegFrameRecorder.java:149)
at org.bytedeco.javacv.FFmpegFrameRecorder.(FFmpegFrameRecorder.java:126)
at com.xlinyu.javacv.HelloWorld.recordCamera(HelloWorld.java:49)
at com.xlinyu.javacv.HelloWorld.main(HelloWorld.java:30)
The text was updated successfully, but these errors were encountered: