Read video with VideoCapture in OpenCV 2.4.11

asked 2015-08-10 08:30:50 -0600

Vadim Kantorov gravatar image


I am trying to read a video:

#include <cassert>
#include <opencv2/highgui/highgui.hpp>

int main()
    cv::VideoCapture in("mpi_sintel_final_alley_1.avi");
    cv::Mat frame;

The second assertion fails. I've tried some other videos as well, it doesn't work either. I uploaded this video to my GitHub repo:

The version of OpenCV is 2.4.11 and it is compiled with FFmpeg 2.7.2.

What am I missing?

Thank you, Vadim

edit retag flag offensive close merge delete



May be your issue is with FMP4 codec installation in your PC. You are using the DirectShow version of the codec or a VFW interface compatible codec ?

pklab gravatar imagepklab ( 2015-08-10 09:27:20 -0600 )edit

I am running this example on Linux. I install FFmpeg and OpenCV as follows:

Vadim Kantorov gravatar imageVadim Kantorov ( 2015-08-10 11:16:21 -0600 )edit

here with OpenCV 3.0.0 and ffmpeg 2.7.2 the above code works without problem ;-).

theodore gravatar imagetheodore ( 2015-08-11 06:29:22 -0600 )edit

Is the codec FMP4 available for your opencv installation ?

What's happens if you try to create a video using that codec ? and if you try to create a video file using CV_FOURCC_PROMPT for the codec param (you should see the list of available codec) ?

pklab gravatar imagepklab ( 2015-08-12 05:28:48 -0600 )edit

When I compile this:

#include <cassert>
#include <cstdio>
#include <opencv2/videoio/videoio.hpp>

int main()
    cv::VideoCapture in("mpi_sintel_final_alley_1.avi");
    cv::Mat_<char> frame;

    int fourcc = in.get(cv::CAP_PROP_FOURCC);
    printf("%d\n", fourcc);


with OpenCV 3.0.0 (built with this script:, I get this:

OpenCV Error: Bad argument (Unknown array type) in cvarrToMat, file /.../modules/core/src/matrix.cpp, line 880
terminate called after throwing an instance of 'cv::Exception'
  what():  /.../modules/coresrc/matrix.cpp:880: error: (-5) Unknown array type in function cvarrToMat

Vadim Kantorov gravatar imageVadim Kantorov ( 2015-08-12 09:20:04 -0600 )edit

877677894 corresponds to FMP4

assert(in.isOpened()) check passes fine.

I build the example with this:

g++ bug.cpp -o bug -O3 -D__STDC_CONSTANT_MACROS -lopencv_videoio -lopencv_imgproc -lopencv_imgcodecs -lopencv_core -lopencv_hal -lpng -ldl -lswscale -lavdevice -lavformat -lavcodec -lswresample -lavutil -lpthread -lbz2 -lz -lc -lrt -Iinclude -Llib

The linking is done statically, the resulting binary has no OpenCV/ffmpeg shared lib dependencies.

Vadim Kantorov gravatar imageVadim Kantorov ( 2015-08-12 09:21:08 -0600 )edit

try with;
assert( ! frame.empty() )
pklab gravatar imagepklab ( 2015-08-14 11:40:10 -0600 )edit