Video Properties
Example
Minimum Origin Version Required: Origin 2016 SR0
The following example shows how to use OpenCV's cvGetCaptureProperty to get information about an existing video file.
#if _OC_VER >= 0x0920
#include <..\originlab\opencv.h>
#else
#include <opencv.h>
#endif
void Video_Properties_ex1(LPCSTR fileName)
{
CvCapture* cap = cvCreateFileCapture(fileName);
if (cap)
{
int width, height, fourcc;
double fps, frcount;
// Call OpenCV's cvGetCaptureProperty function to get a property
// of the video. All the CV_CAP_PROP_* IDs are enumerated in the
// opencv_highgui.h header file.
fourcc = (int)cvGetCaptureProperty(cap, CV_CAP_PROP_FOURCC);
width = (int)cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH);
height = (int)cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT);
fps = cvGetCaptureProperty(cap, CV_CAP_PROP_FPS);
frcount = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_COUNT);
printf("Four CC = %d,%d,%d,%d\n",
LOBYTE(LOWORD(fourcc)), HIBYTE(LOWORD(fourcc)),
LOBYTE(HIWORD(fourcc)), HIBYTE(HIWORD(fourcc)));
printf("Size = %d x %d\n", width, height);
printf("FPS = %f\n", fps);
printf("Frame Count = %f\n", frcount);
printf("Length = %f second(s)\n", frcount / fps);
cvReleaseCapture(&cap);
}
}
void test_Video_Properties_ex1()
{
// Assuming you have a video named 'myvideo.avi' in your User Files folder.
string fileName = GetAppPath() + "myvideo.avi";
Video_Properties_ex1(fileName);
}
Minimum Origin Version Required: Origin 9.1 SR0
The following example shows how to use Origin C's new SystemShellItem class to get information about an existing video file.
Note: The SystemShellItem class uses features available only in Windows Vista and later or Windows Server 2008 and later.
#if _OC_VER >= 0x0920
#include <..\originlab\opencv.h>
#else
#include <opencv.h>
#endif
#include <..\OriginLab\SystemShellItem.h>
void Video_Properties_ex2(LPCSTR fileName)
{
SystemShellItem shellItem;
if( shellItem.Open(fileName) )
{
string str;
ULONG ui;
if( shellItem.GetString(OSHELLITEM_KEY_TITLE, str) )
printf("Title = %s\n", str);
else
printf("Error %d\n", shellItem.LastError());
if( shellItem.GetString(OSHELLITEM_KEY_SUBTITLE, str) )
printf("Subtitle = %s\n", str);
else
printf("Error %d\n", shellItem.LastError());
if( shellItem.GetUInt32(OSHELLITEM_KEY_RATING, &ui) )
printf("Rating = %u\n", ui);
else
printf("Error %d\n", shellItem.LastError());
if( shellItem.GetString(OSHELLITEM_KEY_COMMENT, str) )
printf("Comments = %s\n", str);
else
printf("Error %d\n", shellItem.LastError());
shellItem.Close();
}
}
void test_Video_Properties_ex2()
{
// Assuming you have a video named 'myvideo.mp4' in your User Files folder.
string fileName = GetAppPath() + "myvideo.mp4";
Video_Properties_ex2(fileName);
}
|