我正在使用MediaCapture(Windows.Media.Capture)类向摄像头输入帧添加一些效果。为了应用效果,我正在使用Win2D库。在几次清除并重新应用如下面的代码所示的效果后,引发了异常并且网络摄像头不起作用。
MediaCapture的Failed事件显示如下参数:
MediaCaptureFailedEventArgs
Code : 2147942414
Message : "Not enough memory resources are available to complete this operation."
但是,任务管理器中的性能计数器显示有足够的内存量可供使用。
//Reset Effect Method
private async Task ApplyAllEffects()
{
await ClearAllEffects();
await ApplyRemoveGreenEffect();
}
//Clear All Effects Method
private async Task ClearAllEffects()
{
//_previewMediaCapture is a MediaCapture object
if (_previewMediaCapture == null) return;
await _previewMediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);
}
//Add Effect Method
private async Task ApplyRemoveGreenEffect()
{
if (_previewMediaCapture == null) return;
var properties = new PropertySet();
properties[nameof(RemoveGreenMediaExtension.Value)] = (float)Preferences.RemoveGreen;
var definition = new VideoEffectDefinition(typeof(RemoveGreenVideoEffect).FullName, properties);
await _previewMediaCapture.AddVideoEffectAsync(definition, MediaStreamType.VideoPreview);
}
我检查了MS提供的Win2d Sample的程序和代码。 它也有同样的问题。 有没有办法避免这个问题?
答案 0 :(得分:0)
我可以猜测为什么会这样。
在我初始化MediaCapture对象并将Win2D效果应用于它之前,我通过调用MediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(...)方法对cam使用MJPG编解码器。
我的网络摄像头(Logitech C920)以1080p的30fps支持它。 它导致GPU内存泄漏。当我将原始(YUV)编解码器或NV12编解码器用于输入帧时,不会发生GPU内存泄漏。
我认为,MJPG编码过程已添加到cam的图形管道中,由于某些原因,管道无法正确释放。