Opencv获取视频并查看相关帧数和时间

#include
#include
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
	VideoCapture video;
	video.open("D:/au/2.mp4");
	if (!video.isOpened())
	{
		cout << "open video failed!" << endl;
		getchar();
		return -1;
	}
	cout << "open video success!" << endl;
	Mat frame;
	namedWindow("video");
	int fps = video.get(CAP_PROP_FPS);//帧率
	int fcount = video.get(CAP_PROP_FRAME_COUNT);//全部帧数
	int width = video.get(CAP_PROP_FRAME_WIDTH);//获取宽度
	int height = video.get(CAP_PROP_FRAME_HEIGHT);//获取高度
	cout << "total height is:" << height << endl;
	cout << "total width is:" << width << endl;
	cout << "total frame is:" << fcount << endl;//全部帧数
	cout << "total sec is:" << fcount/fps << endl;//总时间
	int s = 30;
	if (fps != 0)
	{
		int s = 1000 / fps;
	}
	cout << "fps :" << fps << endl;
	s = s / 2;//两倍速度
	for (;;)
	{
		video.read(frame);

		if (frame.empty())break;
		imshow("video", frame);
		waitKey(s);
	}

	waitKey(0);
	return 0;

}

你可能感兴趣的:(opencv,音视频,c++)