Ask Your Question

Android platform, cvCreateFileCapture return null

asked 2018-12-04 00:31:18 -0500

JohnnyWang gravatar image

updated 2018-12-04 00:34:08 -0500

IDE: Android studio

Source code: Java + JNI + C

I would like to use cvCreateFileCapture in c section. However, cvCreateFileCapture return null.

Is it possible to use cvCreateFileCapture for opencv343 in android platform? if so, which source code is incorrect?

key source code is as below,

sint32 daOpenAVI_OpenCV( const char* filename )
    opencv_capture = cvCreateFileCapture(filename);
    if( !opencv_capture ) {
        return -1;
    return 0;


set(libs "${PROJECT_SOURCE_DIR}/../../jniLibs")

add_library(libopencv_java3 SHARED IMPORTED ) set_target_properties(libopencv_java3 PROPERTIES IMPORTED_LOCATION "${libs}/libs/${ANDROID_ABI}/")

add_library(libopencv_calib3d STATIC IMPORTED ) set_target_properties(libopencv_calib3d PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_calib3d.a")

add_library(libopencv_core STATIC IMPORTED ) set_target_properties(libopencv_core PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_core.a")

add_library(libopencv_features2d STATIC IMPORTED ) set_target_properties(libopencv_features2d PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_features2d.a")

add_library(libopencv_flann STATIC IMPORTED ) set_target_properties(libopencv_flann PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_flann.a")

add_library(libopencv_highgui STATIC IMPORTED ) set_target_properties(libopencv_highgui PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_highgui.a")

add_library(libopencv_imgcodecs STATIC IMPORTED ) set_target_properties(libopencv_imgcodecs PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_imgcodecs.a")

add_library(libopencv_imgproc STATIC IMPORTED ) set_target_properties(libopencv_imgproc PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_imgproc.a")

add_library(libopencv_ml STATIC IMPORTED ) set_target_properties(libopencv_ml PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_ml.a")

add_library(libopencv_objdetect STATIC IMPORTED ) set_target_properties(libopencv_objdetect PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_objdetect.a")

add_library(libopencv_photo STATIC IMPORTED ) set_target_properties(libopencv_photo PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_photo.a")

add_library(libopencv_shape STATIC IMPORTED ) set_target_properties(libopencv_shape PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_shape.a")

add_library(libopencv_stitching STATIC IMPORTED ) set_target_properties(libopencv_stitching PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_stitching.a")

add_library(libopencv_superres STATIC IMPORTED ) set_target_properties(libopencv_superres PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_superres.a")

add_library(libopencv_video STATIC IMPORTED ) set_target_properties(libopencv_video PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_video.a")

add_library(libopencv_videoio STATIC IMPORTED ) set_target_properties(libopencv_videoio PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_videoio.a")

add_library(libopencv_videostab STATIC IMPORTED ) set_target_properties(libopencv_videostab PROPERTIES IMPORTED_LOCATION "${libs}/staticlibs/${ANDROID_ABI}/libopencv_videostab.a")

... target_link_libraries( ${PROJECT_NAME} ${SERVICE_USED_LIBS} -L${PROJECT_SOURCE_DIR}/../libs/${ANDROID_ABI} -L${PROJECT_SOURCE_DIR}/../../jniLibs/libs/${ANDROID_ABI} opencv_java3 libopencv_calib3d libopencv_core libopencv_features2d libopencv_flann libopencv_highgui libopencv_imgcodecs libopencv_imgproc libopencv_ml libopencv_objdetect libopencv_photo libopencv_shape libopencv_stitching libopencv_superres libopencv_video libopencv_videoio libopencv_videostab avcodec avfilter avformat avutil fdk-aac swresample swscale ffmpeg

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-12-04 00:35:39 -0500

berak gravatar image

updated 2018-12-04 00:41:27 -0500

there is no support for video files (apart from MJPEG/avi) in the opencv android sdk, lacking any backend for this (like FFMPEG/GSTREAMER), so you won't be able to read/write files or ip streams.

also, the C-api you're trying with was deprecated long ago, you MUST not use it.

(please use cv::VideoCapture and the c++ api in general)

edit flag offensive delete link more


Yes, the format of video file is AVI. I have add the dependency(ffmpeg) to target file. it should be OK, isn't it? i will investigate how to use cv::VideoCapture, however, i hope i can use cvCreateFileCapture API.

the C-api you're trying with was deprecated long ago oh, there is no instruction about this info in Opencv website.

Thank you for your feedback.

JohnnyWang gravatar imageJohnnyWang ( 2018-12-04 00:52:24 -0500 )edit

again, the only codec supported is MJPEG (in an avi container), not arbitrary avi files.

I have add the dependency(ffmpeg) to target file.

what did you do there, exactly ? you would have to build ffmpeg libs locally for android, and rebuild the opencv sdk with those.

berak gravatar imageberak ( 2018-12-04 01:00:54 -0500 )edit

there is no instruction about this info in Opencv website.

because that was in 2010 already ;(

berak gravatar imageberak ( 2018-12-04 01:02:25 -0500 )edit

you would have to build ffmpeg libs locally for android, and rebuild the opencv sdk with those. Got it, this may be the key point. Could you give me a good url to rebuild opencv with ffmpeg? Thank you very much.

JohnnyWang gravatar imageJohnnyWang ( 2018-12-04 01:11:03 -0500 )edit

sorry, no idea about the ffmpeg part, but you'd have to use the platform scripts from here to rebuild the sdk

berak gravatar imageberak ( 2018-12-04 01:13:13 -0500 )edit

Thank you very much. I will try it.

JohnnyWang gravatar imageJohnnyWang ( 2018-12-04 01:17:50 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-12-04 00:31:18 -0500

Seen: 17 times

Last updated: Dec 04