我想将视频转换为 jpg 图像

问题描述

我要分析视频。

我想每秒将视频转换为图像。

我的意思是如果我要分析的视频是 1 小时。我要制作的程序将输出3600个图像文件

我该怎么做?

有什么解决办法吗?

最糟糕的情况是我必须每秒运行视频并拍摄快照。

我需要你的帮助。谢谢。

解决方法

您所需要的只是加载视频并在循环中保存单个帧。这不完全是快照,但是,您只是在保存每一帧。

请注意视频的分辨率也会影响帧的处理速度。

我假设您使用的是 C++。为此,代码将如下所示:

VideoCapture cap("Your_Video.mp4");
// Check if camera opened successfully
if(!cap.isOpened())
{
cout << "Error opening the video << endl;
return -1;
}

while(1)
{
Mat frame;
cap.read(frame);
if (frame.empty())
{
break;
}

// This is where you save the frame
imwrite( "Give your File Path",frame );

}
cap.release();
destroyAllWindows();
return 0;
}