Win10 UWP自定义视频效果,IBasicVideoEffect [英] Win10 UWP Custom Video Effect, IBasicVideoEffect

查看:110
本文介绍了Win10 UWP自定义视频效果,IBasicVideoEffect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to write my own implementation of IBasicVideoEffect to analyze video frames in a Windows 10 UWP application, the end goal is using the Zxing.NET library to scan qr codes.

我无法将视频效果添加到 MediaCapture 在我的代码中.Win10QR.MainPage.cs中的行 var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition(typeof(MyVideoEffect).FullName),MediaStreamType.VideoPreview); 引发异常,指出未注册类(来自HRESULT的异常:0x80040154(REGDB_E_CLASSNOTREG))"

I cannot add the video effect to the instance of MediaCapture in my code. The line var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition(typeof(MyVideoEffect).FullName), MediaStreamType.VideoPreview); in Win10QR.MainPage.cs throws an exception stating "Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"

MyVideoEffect.cs:

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); ,都抛出与上面相同的异常.

I have tried var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("MyVideoEffect", MediaStreamType.VideoPreview); and var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Win10QR.MyVideoEffect", MediaStreamType.VideoPreview);, both throw the same exception as above.

但是, var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Windows.Media.VideoStabilizationEffect",MediaStreamType.VideoPreview); 似乎可以稳定视频.

However, var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Windows.Media.VideoStabilizationEffect", MediaStreamType.VideoPreview); seems to work for video stabilization.

出于好奇,我尝试放入任何旧类,例如: var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Windows.UI.Xaml.DataTemplate",MediaStreamType.VideoPreview); 并引发了另一个异常:不支持这样的接口\ r \ n \ r \ n无法激活视频效果" ,这是有道理的.这使我相信我的接口实现不是问题.

Out of curiosity, I tried putting any old class in, ex: var effect = await _mediaCapture.AddVideoEffectAsync(new VideoEffectDefinition("Windows.UI.Xaml.DataTemplate", MediaStreamType.VideoPreview); and a different exception was thrown: "No such interface supported\r\n\r\nFailed to activate video effect", which makes sense. This leads me to believe that my implementation of the interface is not the problem.

我的Package.appxmanifest或其他地方是否有一些东西需要我找到它才能找到我的视频效果类?这两个类都在Win10QR命名空间中.

Is there something in my Package.appxmanifest or elsewhere that I need to do to get it to find my video effect class? Both classes are in the Win10QR namespace.

感谢您的光临.

推荐答案

注册问题的主要原因可能是您的类文件与应用程序位于同一项目中.是这样吗由于WinRT激活的工作方式(基本上是在后台进行COM激活),因此需要在单独的WinRT类库项目中实现效果(WinRT将其作为In-proc组件激活).如果您创建一个单独的WinRT类库,则将该效果类放入其中,然后从主应用程序中添加要使用它的引用,则此问题将消失.

The leading cause of the registration issue is likely that you have your class file in the same project as your app. Is that the case? Due to the way WinRT activation works (basically COM activation under the hood), effects need to be implemented in a separate WinRT Class Library project (WinRT activates it as an in-proc component). If you create a separate WinRT Class Library, put this effect class in it, and then add a reference to use it from the main app, this problem should go away.

令人沮丧,我知道:).当我们开始实施这项工作时,我本人就遇到了这个问题,当人们开始使用IBasicVideoEffect时,遇到这个问题是很常见的.我试图在将来研究可能的工具或运行时修复程序,以消除对此的需要.

Frustrating I know :). I ran into this myself when we started implementing this work and it's very common for folks to run into this issue when they start working with IBasicVideoEffect. I'm trying to investigate possible tooling or runtime fixes in the future that will eliminate the need for this.

如果这没有帮助,请告诉我,我将尝试找出其他可能的原因:).

If this doesn't help, let me know and I'll try to figure out other possible reasons :).

这篇关于Win10 UWP自定义视频效果,IBasicVideoEffect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆