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

使用DirectShowLib提取帧时出现过滤器状态错误异常的求助

DirectShowLib提取视频帧时操作结束触发COM异常(HResult=0x80040227)

我用DirectShowLib提取视频帧已有多年,但近期在操作结束时总会触发COM异常,错误信息如下:

System.Runtime.InteropServices.COMException: 'The operation could not be performed because the filter is in the wrong state.'(HResult=0x80040227)

异常发生在WaitUntilDone方法的第168行,具体是DsError.ThrowExceptionForHR(hr)这一行。我尝试谷歌搜索该异常,但未找到有效解决方案,下面附上相关代码和完整堆栈信息,寻求修复方法。

相关代码

// WaitUntilDone方法实现
public void WaitUntilDone()
{
    int hr = _mediaEvent.WaitForCompletion(-1, out _);
    DsError.ThrowExceptionForHR(hr); // 第168行,异常触发点
}

// 停止帧提取的调用逻辑
public void StopExtraction()
{
    _mediaControl.Stop();
    WaitUntilDone(); // 调用此处触发异常
}

完整堆栈跟踪

System.Runtime.InteropServices.COMException (0x80040227): The operation could not be performed because the filter is in the wrong state.
   at DirectShowLib.DsError.ThrowExceptionForHR(Int32 hr)
   at YourNamespace.VideoFrameExtractor.WaitUntilDone() in C:\Projects\YourProject\VideoFrameExtractor.cs:line 168
   at YourNamespace.VideoFrameExtractor.StopExtraction() in C:\Projects\YourProject\VideoFrameExtractor.cs:line 210
   at YourNamespace.MainForm.btnStop_Click(Object sender, EventArgs e) in C:\Projects\YourProject\MainForm.cs:line 156

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 19:52:06