Read video with VideoCapture in OpenCV 2.4.11

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

Vadim Kantorov gravatar image

Hi,

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;
    assert(in.isOpened());
    assert(in.read(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: https://raw.githubusercontent.com/vad...

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

Comments

1

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 -0500 )edit
2

I am running this example on Linux. I install FFmpeg and OpenCV as follows: http://pastebin.com/LP1VzRSJ

Vadim Kantorov gravatar imageVadim Kantorov ( 2015-08-10 11:16:21 -0500 )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 -0500 )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 -0500 )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;
    assert(in.isOpened());

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

    assert(in.read(frame));
}

with OpenCV 3.0.0 (built with this script: http://pastebin.com/sdzH7udG), I get this:

877677894
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

Aborted
Vadim Kantorov gravatar imageVadim Kantorov ( 2015-08-12 09:20:04 -0500 )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 -0500 )edit

try with

in.read(frame);
assert( ! frame.empty() )
pklab gravatar imagepklab ( 2015-08-14 11:40:10 -0500 )edit