如何使用 Media Foundation 或 DirectShow 等 Windows 媒体 API 检测相机帧丢失?

How to detect camera frame loss using Windows media API like Media Foundation or DirectShow?

我正在为 Windows 编写一个运行 CUDA 加速 HDR 算法的应用程序。我设置了一个显示为 UVC 设备的外部图像信号处理器设备,并通过 USB 3.0 每秒向 Windows 机器传送 60 帧。

每 "even" 帧 曝光不足 帧,每 "odd" 帧 曝光过度 frame,它允许我的 CUDA 代码执行修改后的 Mertens 曝光融合算法以生成高质量、高动态范围的图像。

Very abstract example of Mertens exposure fusion algorithm here

我唯一的问题是我不知道如何知道我什么时候丢失帧,因为我在 API 上连接过的唯一相机 API =42=](媒体基金会)并没有明确表示我用 IMFSourceReader::ReadSample 抓取的帧不是我抓取的最后一帧之后收到的帧。

有什么方法可以保证我不会丢失帧,或者至少可以使用 Windows 可用 API 喜欢 Media Foundation 还是 DirectShow?

错过一帧然后必须故意 "skip" 下一帧以便抓取下一个过采样或欠采样帧与我们抓取的最后一帧配对并不是什么大问题,但我需要知道自上次抓取帧以来实际错过了多少帧。

谢谢!

IAMDroppedFrames::GetNumDropped method in DirectShow and chances are that it can be retrieved through Media Foundation as well (never tried - they are possibly obtainable with a method similar to this).

The GetNumDropped method retrieves the total number of frames that the filter has dropped since it started streaming.

但是我会质疑它的可靠性。原因是对于这两个 API,或多或少可靠的属性是帧的时间戳。出于多种原因,捕获设备可以灵活地降低帧速率,包括外部(例如低光照条件)和内部(例如管道下游的缓慢阻塞处理)。这使得很难区分奇数帧和偶数帧,但时间戳仍然准确,您可以应用帧速率数学来转换为帧索引。

然而,在您的场景中,我宁愿检测帧时间中的大间隙以识别可能的间隙和连续性损失,并从那里 运行 算法比较接下来几个连续帧的曝光以恢复同步under-/overexposition。听起来像是一个更可靠的出路。

毕竟,这个暴露问题很可能与您使用的硬件非常相关。

通常MFSampleExtension_Discontinuity是为了这个。当您使用 IMFSourceReader::ReadSample 时,勾选此项。