无法使用 OpenCV C++从视频中提取帧
Can't extract frames from video using C++ with OpenCV
我想从短.mp4视频中提取所有帧并将它们作为图像保存到文件夹中。但是当我调用函数 cv::VideoCapture::read(( 时,它无法提取帧。我的代码有什么问题?
#include <iostream>
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/videoio.hpp>
int main(int argc, const char * argv[]) {
cv::VideoCapture cap("test.mp4");
if (!cap.isOpened()) {
std::cout << "Cannot open the video file.n";
return -1;
}
for (int frame_count = 0; frame_count < cap.get(cv::CAP_PROP_FRAME_COUNT); frame_count++) {
cap.set(cv::CAP_PROP_POS_FRAMES, frame_count);
cv::Mat frame;
if (!cap.read(frame)) {
std::cout << "Failed to extract a frame.n";
return -1;
}
std::string image_path = "frames/" + std::to_string(frame_count) + ".jpg";
cv::imwrite(image_path, frame);
}
return 0;
}
我的输出总是"无法提取帧"。
在上面提供的教程中,有一个说明:
取消选中WITH_FFMPEG
FFMPEG库包含MP4编解码器,您需要检查WITH_FFMPEG
和USE_FFMPEG
才能读取.mp4和许多其他格式。
相关文章:
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 如何从 std::atomic 中提取指针 T<T>?
- 为什么istream不支持右值提取
- 如何设置一个范围来提取我想要获得的信息
- 如何在c++中录制具有精确帧时间戳的视频
- 如何在QT中的自定义视频小工具t上绘制矩形
- 视觉工作室项目.提取源文件夹名称
- C++17 - 使用自定义分配器的节点提取/重新插入 - 适用于 clang++/libc++,但不适用于 libstd
- 如何使用OpenCV-C++编写*.mp4视频?
- 开放 CV 中的动态内存分配,用于视频处理
- 帧提取 使用OpenCV的视频文件开头只有几秒钟
- 在何处更改参考代码以从 HEVC 编码的视频中提取运动矢量
- 如何使用FFMPEG从编码的视频中提取AVPACKET的重要信息
- 无法使用 OpenCV C++从视频中提取帧
- 如何从视频中快速提取帧内(在C ++或Python中)
- gstreamermm:如何提取 Gst::P layBin 的最后一帧视频
- 从 flv 视频(或任何其他视频)中提取音频的算法.怎么做
- 用opencv从视频中提取帧进行检测
- 如何使用libvlc API或FFmpeg API提取音频/视频剪辑
- 如何从AVI视频中提取帧