Ask Your Question
0

VideoCapture not working in opencv android

asked 2017-07-14 10:37:41 -0600

ambikav gravatar image

I'm trying to use VideoCapture() in an android application. The app makes a JNI call to the cpp file which has the videocapture() call and passes it a video path.

  • I have provided the storage read and write permissions.
  • The path is also in correct format like (/storage/emulated/0/filename.avi)
  • The video file that I put into my device is first encoded as mjpeg and then as avi using ffmpeg on my PC.

Still I get false result when I check VideoCapture.isopened().

Any suggestions to fix this issue?

edit retag flag offensive close merge delete

Comments

extern "C" { void JNICALL Java_com_example_ambikav_opencvvideo_MainActivity_myfun( JNIEnv *env, jobject instance, jstring path) { nPath = env->GetStringUTFChars(path, NULL); LOGD("path: %s \n",nPath);

cv::VideoCapture videoCapture(nPath);
if(videoCapture.isOpened()){
    LOGD("yes");
}
else{
    LOGD("no");
ambikav gravatar imageambikav ( 2017-07-14 10:52:59 -0600 )edit

extern "C"

{

void JNICALL Java_com_example_ambikav_opencvvideo_MainActivity_myfun(

JNIEnv *env, jobject instance, jstring path) {

nPath = env->GetStringUTFChars(path, NULL);

LOGD("path: %s \n",nPath);

cv::VideoCapture videoCapture(nPath);

if(videoCapture.isOpened()){

LOGD("yes");

}

else{

LOGD("no");

ambikav gravatar imageambikav ( 2017-07-14 10:54:24 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-07-14 23:41:21 -0600

berak gravatar image

with opencv3, you can at least read MJPG encoded avi files using VideoCapture.

(unfortunately, no other formats are supported natively)

edit flag offensive delete link more

Comments

Hi

I did try the MJPG encoded avi files but even that did not work. I used ffmpeg command line tool to do that. But still not able to read the file.

Are there particular instructions for ffmpeg tool that you can refer me to?

ambikav gravatar imageambikav ( 2017-07-17 14:43:54 -0600 )edit
0

answered 2017-07-14 20:21:55 -0600

g3org3 gravatar image

updated 2017-07-17 13:12:51 -0600

Asaik, without re-writing some of the wrappers for the VideoCapture class, it does not work inside OpenCV4Android. I have tried several things without changing the source code. I think that it is because of the discrepancies and maintenance required to support various APIs/Devices. Also, maybe the underlying image buffers used by Android cause problems.

As the other answer indicates, you can use it to read from AVI, and some specified file formats. Apologies, I forgot to add that.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-07-14 10:37:41 -0600

Seen: 2,352 times

Last updated: Jul 17 '17