我试图编写自己的IBasicVideoEffect实现来分析Windows10UWP应用程序中的视频帧,最终目标是使用Zxing.NET库来扫描qr代码。
我无法在代码中将视频效果添加到MediaCapture实例中。Win10QR.MainPage.cs中的行"Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"抛出一个说明"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);似乎可以实现视频稳定。
出于好奇,我尝试将任何旧类放入,例如: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或其他地方,我需要做些什么才能找到我的视频效果类?这两个类都位于Win10QR命名空间中。
谢谢你找我。
发布于 2015-08-21 18:41:58
注册问题的主要原因可能是您的类文件与您的应用程序在同一个项目中。是这样吗?由于WinRT激活的工作方式(基本上是屏蔽下的COM激活),需要在单独的WinRT类库项目中实现效果(WinRT将其激活为in-proc组件)。如果您创建了一个单独的WinRT类库,将这个效果类放入其中,然后添加一个引用从主应用程序中使用它,这个问题就会消失。
令人沮丧的是我知道:)。当我们开始实现这项工作时,我自己也遇到了这个问题,人们在开始使用IBasicVideoEffect时遇到这个问题是很常见的。我正在努力研究将来可能的工具或运行时修复,这将消除对此的需求。
如果这没有帮助,请告诉我,我会设法找出其他可能的原因:)。
https://stackoverflow.com/questions/32079858
复制相似问题