使用SharpDX,Direct3D9(硬件加速)进行视频渲染

时间:2015-11-24 19:45:52

标签: c# video-processing sharpdx

小背景故事:
我的一个朋友和我正在尝试制作街机游戏模拟器。 我们有线框'已经设置(资产加载,游戏状态等),但我们完全停留在视频渲染上。

Example(你在背景中看到的钟摆/时钟的东西是一个WMV3无损视频,在后台用前景中的UI渲染这个是我们想要实现的。

我已经尝试使用除SharpDX的媒体基础之外的库(AForge,libvlc),但都没有产生正确的结果(AForge没有寻找功能,libVLC也无法处理视频比特率我可以在libvlc中打开硬件加速。)

TL; DR 尝试渲染&使用SharpDX.MediaFoundation解码高比特率720p WMV3视频,利用硬件加速解码/渲染(仅限D3D9

为什么选择D3D9?:Windows XP - 兼容Windows 10,我们并不急于将DX11.2与MediaEngineEx一起使用,因为这将不再支持Windows XP - Windows 7。 / p>

SharpDX MediaFoundation Docs(自己看看,要么我太愚蠢了,要么我的理解程度太低,无法理解)

我现在有什么:

渲染循环:

        Lib.Render += (RenderForm e) =>
        {
            GameStateManager.Draw();
        };

此事件由以下人员调用:

    public static void Run(float drawRate = 60.0f, float updateRate = 60.0f)
    {
        DrawRate = drawRate;
        UpdateRate = updateRate;

        IsRunning = true;
        Begin = DateTime.Now;

        RenderLoop.Run(Window, () =>
        {
            Lib.BeginUpdate();

           OnUpdate();
            if (!IsResizing)
                OnRender();

            Lib.EndUpdate();
        });
    }

的OnRender

这个函数构成了一个用于简化SharpDX.Direct3D9调用的小型库的一部分,它初始化如下:

    public static DX9Device Initialise(int width = 1280, int height = 720)
    {
        Window = new RenderForm("Test");
        Window.ClientSize = new Size(width, height);
        Window.AllowUserResizing = false;

        TextureCache = new Dictionary<string, Texture>();

        DI = new DirectInput();
        D3D = new Direct3D();
        Device = new DX9Device(D3D, 0, DX9DeviceType.Hardware, Window.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(Window.ClientSize.Width, Window.ClientSize.Height));

        KeyboardDevice = new Keyboard(DI);

        Window.ResizeBegin += Window_ResizeBegin;
        Window.Resize += Window_Resize;
        Window.ResizeEnd += Window_ResizeEnd;

        Foreground = new SharpDX.Direct3D9.Sprite(Device);
        Background = new SharpDX.Direct3D9.Sprite(Device);

        return Device;
    }

您可能需要更多信息来帮助我解决此问题,请询问。

编辑:目标框架是.NET 4客户端配置文件

编辑:到目前为止我已经尝试了这个,但它在行上提供了NullReferenceException&#34; HDDevice dxvaDev_ = ...&#34;:

        public static void Initialise(DX9Device dev)
    {
        ContentDescription cd = new ContentDescription();
        Rational fps = new Rational();
        fps.Denominator = 1;
        fps.Numerator = 30;

        cd.InputFrameFormat = FrameFormat.Progressive;
        cd.InputFrameRate = fps;
        cd.InputWidth = 1280;
        cd.InputHeight = 780;
        cd.OutputFrameRate = fps;
        cd.OutputWidth = 1280;
        cd.OutputHeight = 720;


        HDDevice dxvaDev_ = new HDDevice(dev, cd, DeviceUsage.PlaybackNormal); //--> Why does this return null?!?!?!
    }

VideoHandler类(DX9Device是SharpDX.Direct3D9.DeviceEx的别名)
这似乎是internal issue

编辑:我将尝试使用Managed DirectX 9.0进行C#。
编辑:托管DirectX 9.0 for C#没有成功,在使用RenderToTexture时处理视频会抛出NullReferenceException而Microsoft不会为其API提供有价值的继承者。

编辑:现在尝试使用MediaFoundation for .NET(截至01 / dec / 2015)

0 个答案:

没有答案
相关问题