//decode frames by opencv and get timestamp info for each frame
//return the number of frames
int decode_frames(char* filename, int* timestamp, int* width, int* height)
{
//open video file
cv::VideoCapture cap(filename);
if (!cap.isOpened())
{
cout << "Could not open video file" << endl;
return -1;
}
//get video info
int frame_count = (int)cap.get(CV_CAP_PROP_FRAME_COUNT);
int fps = (int)cap.get(CV_CAP_PROP_FPS);
int width_ = (int)cap.get(CV_CAP_PROP_FRAME_WIDTH);
int height_ = (int)cap.get(CV_CAP_PROP_FRAME_HEIGHT);
//get timestamp info for each frame
for (int i = 0; i < frame_count; i++)
{
cap.set(CV_CAP_PROP_POS_FRAMES, i);
timestamp[i] = (int)cap.get(CV_CAP_PROP_POS_MSEC);
}
//return video info
*width = width_;
*height = height_;
return frame_count;
}