Search code examples
androidopencvvideo-capture

Can't read a video file using Videocapture() on android


I'm new to android and don't have much knowledge about using opencv in android. I want to read a video from storage and extract the frames but I can't read the video. I used videocapture but it is always showing failed. Here is the code snippet I'm using. The video file path is /storage/emulated/0/Android/data/demoVid/Demo.avi. The file size is 250MB

        VideoCapture cap = new VideoCapture();
//        cap.open(vpath.toString());
        cap.open(imFile);
        Mat frame = new Mat();
        int framecount = 0;

        if(cap.isOpened()){
            Log.d("VideoCapture","Videocapture successful");
        }
        else
        {
            Log.d("VideoCapture","Videocapture failed");
        }

Solution

  • So basically I just wanted to read a video file in android using videocapture of opencv. I was using opencv version 3.4.10 which was giving error of file not found. I tried to change paths and checked if the path was properly defined but still couldn't read the file. After wasting a lot of time on it I upgraded to opencv version 4.5.0 (upgraded to get sift features) and my issue was resolved for the same code. So maybe some older versions opencv don't support videocapture. Also I would like to mention that the frames I read from the videocapture take a lot of time due to which I wasn't able to get a real-time experience.