使用Media Foundation编码Direct X曲面 [英] Using Media Foundation to encode Direct X surfaces

查看:216
本文介绍了使用Media Foundation编码Direct X曲面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MediaFoundation API对视频进行编码,但是在将样本推送到SinkWriter时遇到问题.

I'm trying to use the MediaFoundation API to encode a video but I'm having problems pushing the samples to the SinkWriter.

我正在获取要通过桌面复制API进行编码的帧.我最终得到的是带有桌面图像的ID3D11Texture2D.

I'm getting the frames to encode through the Desktop Duplication API. What I end up with is an ID3D11Texture2D with the desktop image in it.

我正在尝试创建一个包含该表面的IMFVideoSample,然后将该视频示例推送到SinkWriter.

I'm trying to create an IMFVideoSample containing this surface and then push that video sample to a SinkWriter.

我已经尝试过以不同的方式来解决这个问题:

I've tried going about this in different ways:

  • 我称为MFCreateVideoSampleFromSurface(texture, &pSample),其中纹理是ID3D11Texture2D,填充了SampleTime和SampleDuration,然后将创建的样本传递给SinkWriter. SinkWriter返回了E_INVALIDARG.

  • I called MFCreateVideoSampleFromSurface(texture, &pSample) where texture is the ID3D11Texture2D, filled in the SampleTime and SampleDuration and then passed the created sample to the SinkWriter.
    SinkWriter returned E_INVALIDARG.

我尝试通过将nullptr作为第一个参数传递并使用MFCreateDXGISurfaceBuffer自己创建缓冲区,然后将所得的缓冲区传递到Sample中来创建示例.
那也不起作用.

I tried creating the sample by passing nullptr as the first argument and creating the buffer myself using MFCreateDXGISurfaceBuffer, and then passing the resulting buffer into the Sample.
That didn't work either.

我通读了MediaFoundation文档,找不到有关如何从DirectX纹理中创建示例的详细信息.

I read through the MediaFoundation documentation and couldn't find detailed information on how to create the sample out of a DirectX texture.

我没办法尝试了.
有没有人在那里使用过此API,并且可以想到我应该检查的事情,或者如何进行调试?

I ran out of things to try.
Has anyone out there used this API before and can think of things I should check, or of any way on how I can go about debugging this?

推荐答案

首先,您应该学习使用

First of all you should learn to use mftrace tool. Very likely, it will tell you the problem right away.

但是我的猜测是,可能会出现以下问题.

But my guess is, following problems are likely.

  1. 可能,除了SampleTime/SampleDuration之外,还需要一些其他属性.

  1. Probably, some other attributes are required besides SampleTime / SampleDuration.

可能,SinkWriter需要一个可以在CPU上读取的纹理.要解决此问题,当框架可用时,创建具有相同格式+大小的暂存纹理,调用CopyResource将桌面复制到暂存纹理,然后将该暂存纹理传递给MF.

Probably, SinkWriter needs a texture it can read on CPU. To fix that, when a frame is available, create a staging texture of the same format + size, call CopyResource to copy desktop to staging texture, then pass that staging texture to MF.

即使您使用硬件编码器,以便CPU从未尝试读取纹理数据,我也不认为直接将您的桌面纹理传递给MF是个好主意.

Even if you use a hardware encoder so the CPU never tries to read the texture data, I don’t think it’s a good idea to directly pass your desktop texture to MF.

当您为样本设置D3D纹理时,没有任何数据被复制到任何地方,样本仅保留该纹理.

When you set a D3D texture for sample, no data is copied anywhere, the sample merely retains the texture.

MF是异步工作的,如果愿意,它可以在其拓扑节点中缓冲几个样本.

MF works asynchronously, it may buffer several samples in its topology nodes if they want to.

DD为您同步提供数据,您只能在AcquireNextFrame和ReleaseFrame调用之间访问纹理.

DD gives you data synchronously, you may only access the texture between AcquireNextFrame and ReleaseFrame calls.

这篇关于使用Media Foundation编码Direct X曲面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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