Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recordCamera("rtmp://localhost/oflaDemo/aa", 25); #301

Closed
fdtomn opened this issue Oct 14, 2016 · 1 comment
Closed

recordCamera("rtmp://localhost/oflaDemo/aa", 25); #301

fdtomn opened this issue Oct 14, 2016 · 1 comment

Comments

@fdtomn
Copy link

fdtomn commented Oct 14, 2016

my pom.xml file

    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>javacv</artifactId>
        <version>1.2</version>
    </dependency>

recordCamera method

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)

@saudet
Copy link
Member

saudet commented Oct 15, 2016

Probably a duplicate of #225. Declare a dependency on ffmpeg-3.1.2-1.2 explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants