直接上代码(需要把OpenCV中ffmpeg相关的dll加上,不然无法解码):
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <chrono>
using namespace cv;
using namespace std;
void main()
{
VideoCapture cap("3.mp4");
if (!cap.isOpened())
return;
int width = cap.get(CAP_PROP_FRAME_WIDTH); //帧宽度
int height = cap.get(CAP_PROP_FRAME_HEIGHT); //帧高度
int frameRate = cap.get(CAP_PROP_FPS); //帧率
int totalFrames = cap.get(CAP_PROP_FRAME_COUNT); //总帧数
cout << "视频宽度=" << width << endl;
cout << "视频高度=" << height << endl;
cout << "视频总帧数=" << totalFrames << endl;
cout << "帧率=" << frameRate << endl;
int playFrames = 0;
Mat frame;
a