Win10 UWP 自定义视频效果,IBasicVideoEffect
Win10 UWP Custom Video Effect, IBasicVideoEffect
我正在尝试编写自己的 IBasicVideoEffect 实现来分析 Windows 10 UWP 应用程序中的视频帧,最终目标是使用 Zxing.NET 库扫描二维码.
我无法在我的代码中将视频效果添加到 MediaCapture 的实例中。 Win10QR.MainPage.cs 中的 var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition(typeof(MyVideoEffect).FullName), MediaStreamType.VideoPreview);
行抛出异常 "Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"
MyVideoEffect.cs:
namespace Win10QR
{
public class MyVideoEffect : IBasicVideoEffect
{
public bool IsReadOnly
{
get
{
return false;
}
}
public IReadOnlyList<VideoEncodingProperties> SupportedEncodingProperties
{
get
{
var properties = new List<VideoEncodingProperties>();
properties.Add(VideoEncodingProperties.CreateUncompressed("ARGB32", 640, 480));
return properties;
}
}
public MediaMemoryTypes SupportedMemoryTypes
{
get
{
return MediaMemoryTypes.GpuAndCpu;
}
}
public bool TimeIndependent
{
get
{
return false;
}
}
public void Close(MediaEffectClosedReason reason)
{
}
public void DiscardQueuedFrames()
{
}
public void ProcessFrame(ProcessVideoFrameContext context)
{
var resultString = AnalyzeBitmap(context.InputFrame.SoftwareBitmap);
if (resultString != null)
{
Debug.WriteLine(resultString);
}
}
public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device)
{
}
public void SetProperties(IPropertySet configuration)
{
}
private string AnalyzeBitmap(SoftwareBitmap bitmap)
{
var reader = new BarcodeReader();
var writableBitmap = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
bitmap.CopyToBuffer(writableBitmap.PixelBuffer);
var result = reader.Decode(writableBitmap);
if (result != null)
{
return result.Text;
}
return null;
}
}
}
我试过 var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("MyVideoEffect", MediaStreamType.VideoPreview);
和 var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Win10QR.MyVideoEffect", MediaStreamType.VideoPreview);
,都抛出与上面相同的异常。
但是,var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Windows.Media.VideoStabilizationEffect", MediaStreamType.VideoPreview);
似乎对视频稳定有效。
出于好奇,我尝试将任何旧的 class 放入,例如:var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Windows.UI.Xaml.DataTemplate", MediaStreamType.VideoPreview);
并抛出一个不同的异常:"No such interface supported\r\n\r\nFailed to activate video effect"
,这是有道理的。这让我相信我的接口实现不是问题。
我的 Package.appxmanifest 或其他地方是否需要做些什么才能找到我的视频效果 class?两个 class 都在 Win10QR 命名空间中。
感谢观看。
注册问题的主要原因可能是您的 class 文件与您的应用位于同一项目中。是这样吗?由于 WinRT 激活的工作方式(基本上是引擎盖下的 COM 激活),效果需要在单独的 WinRT Class 库项目中实现(WinRT 将其作为进程内组件激活)。如果您创建一个单独的 WinRT Class 库,将此效果 class 放入其中,然后添加一个引用以从主应用程序使用它,这个问题应该会消失。
我知道很沮丧 :)。当我们开始实施这项工作时,我自己 运行 陷入这个问题,人们在开始使用 IBasicVideoEffect 时 运行 陷入这个问题是很常见的。我正在尝试研究未来可能的工具或 运行时间修复,以消除对此的需求。
如果这没有帮助,请告诉我,我会设法找出其他可能的原因:)。
我正在尝试编写自己的 IBasicVideoEffect 实现来分析 Windows 10 UWP 应用程序中的视频帧,最终目标是使用 Zxing.NET 库扫描二维码.
我无法在我的代码中将视频效果添加到 MediaCapture 的实例中。 Win10QR.MainPage.cs 中的 var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition(typeof(MyVideoEffect).FullName), MediaStreamType.VideoPreview);
行抛出异常 "Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"
MyVideoEffect.cs:
namespace Win10QR
{
public class MyVideoEffect : IBasicVideoEffect
{
public bool IsReadOnly
{
get
{
return false;
}
}
public IReadOnlyList<VideoEncodingProperties> SupportedEncodingProperties
{
get
{
var properties = new List<VideoEncodingProperties>();
properties.Add(VideoEncodingProperties.CreateUncompressed("ARGB32", 640, 480));
return properties;
}
}
public MediaMemoryTypes SupportedMemoryTypes
{
get
{
return MediaMemoryTypes.GpuAndCpu;
}
}
public bool TimeIndependent
{
get
{
return false;
}
}
public void Close(MediaEffectClosedReason reason)
{
}
public void DiscardQueuedFrames()
{
}
public void ProcessFrame(ProcessVideoFrameContext context)
{
var resultString = AnalyzeBitmap(context.InputFrame.SoftwareBitmap);
if (resultString != null)
{
Debug.WriteLine(resultString);
}
}
public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device)
{
}
public void SetProperties(IPropertySet configuration)
{
}
private string AnalyzeBitmap(SoftwareBitmap bitmap)
{
var reader = new BarcodeReader();
var writableBitmap = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight);
bitmap.CopyToBuffer(writableBitmap.PixelBuffer);
var result = reader.Decode(writableBitmap);
if (result != null)
{
return result.Text;
}
return null;
}
}
}
我试过 var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("MyVideoEffect", MediaStreamType.VideoPreview);
和 var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Win10QR.MyVideoEffect", MediaStreamType.VideoPreview);
,都抛出与上面相同的异常。
但是,var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Windows.Media.VideoStabilizationEffect", MediaStreamType.VideoPreview);
似乎对视频稳定有效。
出于好奇,我尝试将任何旧的 class 放入,例如:var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Windows.UI.Xaml.DataTemplate", MediaStreamType.VideoPreview);
并抛出一个不同的异常:"No such interface supported\r\n\r\nFailed to activate video effect"
,这是有道理的。这让我相信我的接口实现不是问题。
我的 Package.appxmanifest 或其他地方是否需要做些什么才能找到我的视频效果 class?两个 class 都在 Win10QR 命名空间中。
感谢观看。
注册问题的主要原因可能是您的 class 文件与您的应用位于同一项目中。是这样吗?由于 WinRT 激活的工作方式(基本上是引擎盖下的 COM 激活),效果需要在单独的 WinRT Class 库项目中实现(WinRT 将其作为进程内组件激活)。如果您创建一个单独的 WinRT Class 库,将此效果 class 放入其中,然后添加一个引用以从主应用程序使用它,这个问题应该会消失。
我知道很沮丧 :)。当我们开始实施这项工作时,我自己 运行 陷入这个问题,人们在开始使用 IBasicVideoEffect 时 运行 陷入这个问题是很常见的。我正在尝试研究未来可能的工具或 运行时间修复,以消除对此的需求。
如果这没有帮助,请告诉我,我会设法找出其他可能的原因:)。