这个程序使用OpenCV提取webp动图里的图片。
WebP 是由 Google 开发的一种现代图像格式,旨在为网页提供更小的文件大小和更高的压缩效率,同时保持与 JPEG、PNG 和 GIF 相当甚至更好的视觉质量。
测试webp动图里面有10张图片,每张图片持续200ms。

程序先播放了这个webp动图,然后单独提取了第6张图片,保存为5.png:

代码:
cpp
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
int main()
{
Animation webp;
bool success = imreadanimation("animation.webp", webp);
if (!success) {
std::cerr << "Failed to load animation frames\n";
return -1;
}
for (size_t i = 0; i < webp.frames.size(); ++i) {
imshow("Animation", webp.frames[i]);
waitKey(webp.durations[i]);
}
imwrite("5.png", webp.frames[5]);
return 0;
}