VideoCapture not working on Android with C++

Viewed 431

I have a video file saved on my Android device.

Using a getPath() function I got "sdcard/video_app/sample_video.avi".

I'm now trying to use this video file in my OpenCV C++ code (I'm using NDK and JNI) with this :

VideoCapture capture("sdcard/video_app/sample_video.avi");

if(capture.isOpened()){
    //return true
   }else{
    //return false
    }

I added :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

It always returns false. What am I doing wrong ? I read that OpenCV on android only supports MJPEG codec in avi container so I'm using this kind of video file and it's still not working.

EDIT :

I've changed the path :

VideoCapture capture("/storage/emulated/0/turning_pages.avi"); 

This path is the response from a call to Environment.getExternalDirectory.getPath() The path is correct, I've verified it with this :

File file = new File("/storage/emulated/0/turning_pages.avi");
if(file.exists()){
     //returns true
  }

I've done some more testing and imread and imwrite are wroking fine using similar path, I can conclude that the problem with VideoCapture is not from the path.

Mat m = imread("/storage/emulated/0/sbuinex21fyy.jpg"); 

if(!m.empty()){
   //returns true
   } 

imwrite("/storage/emulated/0/sbuinex21fyy.jpg", m); 

I can then see a duplicate of the picture in my device storage.

0 Answers
Related