Javacv: OpenCVFrameGrabber not opening video file.

Created on 2 Jul 2017  路  3Comments  路  Source: bytedeco/javacv

I want to open a video file and grab frames, but when I start it throws the exception below:

org.bytedeco.javacv.FrameGrabber$Exception: read() Error: Could not read frame in start().
    at org.bytedeco.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:212)
    at com.uatb.javacv.Test.main(Test.java:41)

But when I use camera it works well.

It is my code:

OpenCVFrameConverter converter = new OpenCVFrameConverter.ToMat();
OpenCVFrameGrabber grabber = new OpenCVFrameGrabber("C:\\768x576.avi");
//OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0); // it works well
try {
    grabber.start();
    Frame frame;
    while ((frame = grabber.grab()) != null) {
        Mat mat = converter.convertToMat(frame);
        opencv_highgui.imshow("Video", mat);
        cvWaitKey(30);
    }
} catch (FrameGrabber.Exception e) {
    e.printStackTrace();
} finally {
    try {
        grabber.release();
    } catch (FrameGrabber.Exception e) {
        e.printStackTrace();
    }
}

I think it can be the problem FFmpeg, but I did not any solution online.

question

All 3 comments

Please use FFmpegFrameGrabber instead.

@saudet You mean that for camera use OpenCVFrameGrabber and for video file use FFmpegFrameGrabber am I right?

Yes, that's the idea.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

myScoopAndroidCamera picture myScoopAndroidCamera  路  4Comments

chrisliu12345 picture chrisliu12345  路  4Comments

iamazy picture iamazy  路  4Comments

eldhosengeorge picture eldhosengeorge  路  3Comments

kongqw picture kongqw  路  4Comments