Skip to content

Instantly share code, notes, and snippets.

@raunaqbn
Created June 14, 2016 10:37
Show Gist options
  • Save raunaqbn/739b5fc9a03747ac7c1bf97f0d104a97 to your computer and use it in GitHub Desktop.
Save raunaqbn/739b5fc9a03747ac7c1bf97f0d104a97 to your computer and use it in GitHub Desktop.
#include "chapter2.h"
void display_video(char **argv)
{
// CvCapture structure is used to store the information of the various properties of the
// avi and the create file capture returns a pointer of this type initialized to the beginning
// of the avi
CvCapture *pCapture = cvCreateFileCapture(argv[1]);
// Create a window to display the video frames
cvNamedWindow("2. Present a video", CV_WINDOW_AUTOSIZE );
// We will be reading information frame by frame. This memory is a part of the CvCapture structure and
// we need to create a temporary pointer to point to it.
IplImage *pFrame;
// Get the frame fps
int fps = (int) cvGetCaptureProperty(pCapture, CV_CAP_PROP_FPS);
cout<<"The video fps:"<<fps<<endl;
// We create an infinite loop to read in frames one by one till either the user hits escape or
// the file reaches an end.
while(1)
{
// Read in one frame at a time. Thus frame image returned is a part of the memory allocated to the cvCapture
// Since this is memory of the CvCapture we dont need to deallocate(cvReleaseImage) this memory.
pFrame = cvQueryFrame(pCapture);
// If the end of file is reached the queryFrame will return a null
if (!pFrame)break;
// Show the frame we have like we normally do
cvShowImage("2. Present a video", pFrame);
// Now we have a time gap of approx (1000/fps) ms before we need to show the next frame
char wait = cvWaitKey(1000/fps);
// If the esc key was hit then we break out. Esc => 27 in ASCII
if (wait == 27)break;
}
// Now we proceed to release the capture data and destroy the window
cvReleaseCapture(&pCapture);
cvDestroyWindow("2. Present a video");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment