Win10 UWP自定义视频效果,IBasicVideoEffect

本文关键字:IBasicVideoEffect 视频 UWP 自定义 Win10 | 更新日期: 2023-09-27 18:08:29

我正在尝试编写我自己的IBasicVideoEffect实现来分析Windows 10 UWP应用程序中的视频帧,最终目标是使用Zxing。. NET库扫描qr码。

我无法在我的代码中向mediaccapture实例添加视频效果。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",这是有意义的。这使我相信我的接口实现不是问题所在。

我的包里有什么东西吗?appxmanifest或其他地方,我需要做什么才能找到我的视频效果类?这两个类都在Win10QR命名空间中。

Win10 UWP自定义视频效果,IBasicVideoEffect

注册问题的主要原因可能是您的类文件与应用程序在同一个项目中。是这种情况吗?由于WinRT激活的工作方式(基本上是底层的COM激活),效果需要在单独的WinRT类库项目中实现(WinRT将其作为进程内组件激活)。如果你创建一个单独的WinRT类库,把这个效果类放进去,然后添加一个引用从主应用程序中使用它,这个问题就会消失。

令人沮丧,我知道:)。我自己在我们开始实现这个工作时遇到了这个人们在开始使用IBasicVideoEffect时遇到这个问题是很常见的。我正在尝试调查未来可能的工具或运行时修复,以消除对此的需要。

如果这没有帮助,让我知道,我会试图找出其他可能的原因:)。

相关文章:
  • 没有找到相关文章