opencv: VideoCapture cannot open video file in Java

Transferred from http://code.opencv.org/issues/4298

|| Bahramuidn Adil on 2015-04-28 05:17
|| Priority: High
|| Affected: branch 'master' (3.0-dev)
|| Category: java bindings
|| Tracker: Bug
|| Difficulty: Medium
|| PR: 
|| Platform: x64 / Windows

VideoCapture cannot open video file in Java


History

Bahramuidn Adil on 2015-04-28 05:20
OpenCV 3.0 VideoCapture doesn't open video file in Java, but there is no problem if open camera.
-   Target version set to 3.0
Maksim Shabunin on 2015-04-28 12:35
-   Category set to java bindings

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 18 (3 by maintainers)

Most upvoted comments

You are missing the loading ffmpeg dll. If use 64 add opencv_ffmpeg300_64.dll. If you use 32 add opencv_ffmpeg300.dll. Add this the your code.

System.loadLibrary("opencv_ffmpeg300_64");

System.loadLibrary is not required. Just put opencv_ffmpeg*.dll file(s) near opencv_java*.dll or update PATH environment variable which should point to opencv_ffmpeg*.dll

Using OpenCV 3.0 on windows:

        Mat matOrig = new Mat();
        VideoCapture capture = new VideoCapture("resources/Hummingbird.MP4");
        if( capture.isOpened()){
            while (true){  
                capture.read(matOrig);  
                // get some meta data about frame.              
                double fps = capture.get(Videoio.CAP_PROP_FPS);
                double frameCount = capture.get(Videoio.CAP_PROP_FRAME_COUNT);
                double h = capture.get(Videoio.CAP_PROP_FRAME_HEIGHT);
                double w = capture.get(Videoio.CAP_PROP_FRAME_WIDTH);
                double posFrames = capture.get(Videoio.CAP_PROP_POS_FRAMES);
                double posMsec = capture.get(Videoio.CAP_PROP_POS_MSEC);
                double speed = capture.get(Videoio.CAP_PROP_SPEED);
                if( !matOrig.empty() ) {
                    // do stuff
                }
            }
        }

I have same issue on Ubuntu. I’ve tried to compile ffmpeg from source as shared lib. It creates some libav*.so, but OpenCV Java code still cannot open the mp4/avi file with no errror or warning. What should I do?