【发布时间】:2015-08-18 18:17:29
【问题描述】:
我正在尝试编写自己的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); 似乎适用于视频稳定功能。
出于好奇,我尝试将任何旧类放入其中,例如: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 命名空间中。
感谢收看。
【问题讨论】:
-
github.com/jolson88/media-contrib/tree/master/Examples/…这个项目成功实现了IBasicVideoEffect,但我似乎找不到它和我的代码的区别
-
social.msdn.microsoft.com/Forums/en-US/… 这里有人遇到了类似的问题,但我不知道在清单文件中为
标记放置什么。 -
我尝试逐字使用您的代码(在 RT 库中),但出于某种原因,在 InputFrame 上 SoftwareBitmap 始终为空。知道是什么原因造成的吗?
标签: c# .net windows-phone uwp