You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下OpenCV C++的VideoWriter无法打开求助

Windows10 + Visual Studio环境下OpenCV C++ VideoWriter无法打开的问题

在Windows10系统的Visual Studio环境中,尝试使用OpenCV C的VideoWriter,但无法打开并输出错误。Python版本的VideoWriter可以正常工作,本人刚接触C,可能忽略了基础问题,求帮助。

使用的代码

#include <iostream> // for standard I/O
#include <string>   // for strings
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
    VideoWriter outputVideo1;
    outputVideo1.open("testing.avi", VideoWriter::fourcc('M', 'J', 'P', 'G'), 10, Size(1936, 1216), false);
    if (!outputVideo1.isOpened())
    {
        cout << "failed opening" << endl;
    }
   
}

出现的错误

error: (-215:Assertion failed) !filename_pattern.empty() in function 'cv::CvVideoWriter_Images::open'

已尝试的操作

  • 更换不同的文件路径、名称、扩展名
  • 切换不同的fourcc编码
  • 运行OpenCV官方教程中的源码,仍出现相同错误
  • 调整open调用方式后,得到错误:

    OpenCV(4.9.0) C:\GHA-OCV-1_work\ci-gha-workflow\ci-gha-workflow\opencv\modules\videoio\src\cap_images.cpp:216: error: (-215:Assertion failed) !filename.empty() in function 'cv::icvExtractPattern'

补充日志信息

启用日志后发现两个插件加载失败:

cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
\OpenCV\build\x64\vc16\bin\opencv_videoio_gstreamer4100_64.dll => FAILED

cv::plugin::impl::DynamicLib::libraryLoad load C:\OpenCV\build\x64\vc16\bin\opencv_videoio_intel_mfx4100_64.dll => FAILED

但以下插件加载成功,个人认为不是问题根源:

cv::plugin::impl::DynamicLib::libraryLoad load C:\OpenCV\build\x64\vc16\bin\opencv_videoio_msmf4100_64.dll => OK

后续步骤抛出异常:

cv::impl::PluginBackend::initWriterAPI Video I/O: plugin is ready to use 'Microsoft Media Foundation OpenCV Video I/O plugin'

[ WARN:0@0.011] global cap.cpp:645 cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

430: error: (-215:Assertion failed) !filename_pattern.empty() in function 'cv::CvVideoWriter_Images::open'

日志未明确指出错误根源,若无关可忽略此补充。


内容的提问来源于stack exchange,提问作者TheSloth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 04:33:22