【问题标题】:Win10 UWP Custom Video Effect, IBasicVideoEffectWin10 UWP自定义视频效果,IBasicVideoEffect
【发布时间】: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 命名空间中。

感谢收看。

【问题讨论】:

标签: c# .net windows-phone uwp


【解决方案1】:

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

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

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

【讨论】:

  • 这就是问题所在!我曾尝试将效果放在类库(通用 Windows)中,而不是 Windows 运行时组件(通用 Windows)中。把它放在一个新的 WinRT 组件中就可以了。
猜你喜欢
  • 2016-04-17
  • 2019-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多