Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Displaying video with OpenCV

l1nuxn3wbie
Beginner
262 Views
Hi!
I am trying to play an AVI video using a short program.

// AVI Stream.cpp :
// This program displays an AVI video and performs processing on it
// and thus displays the processed video.
//

#include "stdafx.h"
#include "highgui.h"
#include "cv.h"
#include
#include

using namespace std;


int main(int argc, char** argv)
{
/*IplImage* frame;
int key;

//assert(argc == 2);


CvCapture* capture = cvCaptureFromAVI("music.avi");

if(!capture) return 1;

int framesPerSecond = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FPS);

cvNamedWindow("Video Example",0);

while(key != 'q'){
frame = cvQueryFrame(capture);

if(!frame) break;

cvShowImage("Video Example",frame);

key = cvWaitKey(1000/framesPerSecond);

}


//frame = cvGrabFrame(capture);
//frame1 = cvRetrieveFrame(capture);
//cvShowImage("Example",frame1);
//while(1)
//{
//frame = cvQueryFrame(capture);
//if(!frame) break;
//cvShowImage("Video Example",frame);
//char c = cvWaitKey(1000);
//if(c == 27) break;
//}

cvReleaseCapture(&capture);
cvDestroyWindow("Video Example");

return 0;*/

cvNamedWindow("Video", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateFileCapture("music.avi");

IplImage* frame;
while(1)
{
frame = cvQueryFrame(capture);
if(!frame) break;
cvShowImage("Video",frame);
char c = cvWaitKey(10000000);
if(c == 27) break;


}

//frame = cvQueryFrame(capture);
//cout << "This is what is stored in capture: " << capture;
//cvShowImage("Video",capture);

cvReleaseCapture(&capture);
cvDestroyWindow("Video");
//cout << "This is what is stored in capture: " << capture;

}


Unfortunately, a window displays with the name of the window, but no video plays. HELP ME PLEASE!!
I don't know if there is a codec I need or what. The variable that holds my capture structure is 0.










0 Kudos
1 Reply
Vladimir_Dudnik
Employee
262 Views

As far as I know, OpenCV uses ffmpeg for video decoding. You may need to ensure that compression format used in your AVI file is supported by ffmpeg.

Vladimir
0 Kudos
Reply