简体   繁体   English

尝试在媒体基础编码中使用 MFT

[英]Trying to use a MFT in Media Foundation Encoding

The idea is to use a Media Foundation Transform, such as the Video Stabilization MFT while transcoding a video with Media Foundation.这个想法是在使用 Media Foundation 对视频进行转码时使用 Media Foundation Transform,例如Video Stabilization MFT

When not using an MFT, the code works fine.不使用 MFT 时,代码工作正常。

  • Create IMFSourceReader for the source file - OK为源文件创建 IMFSourceReader - OK
  • Create IMFSinkWriter for the target file - OK为目标文件创建 IMFSinkWriter - OK
  • Add a stream to the writer describing the Video - OK向描述视频的作者添加流 - 好的
  • Add the audio stream - OK添加音频流 - OK
  • Set input types for video and audio - OK设置视频和音频的输入类型 - OK
  • Loop to read samples and send them to the sink writer, OK.循环读取样本并将它们发送到接收器写入器,OK。

When using the MFT, these are the facts.使用 MFT 时,这些就是事实。 To create the MFT (error checking removed):要创建 MFT(已删除错误检查):

CComPtr<IMFTransform> trs;
trs.CoCreateInstance(CLSID_CMSVideoDSPMFT);
std::vector<DWORD> iids;
std::vector<DWORD> oods;
DWORD is = 0, os = 0;
hr = trs->GetStreamCount(&is, &os);
iids.resize(is);
oods.resize(os);
hr = trs->GetStreamIDs(is, iids.data(), os, oods.data());
CComPtr<IMFMediaType> ptype;
CComPtr<IMFMediaType> ptype2;
MFCreateMediaType(&ptype);
MFCreateMediaType(&ptype2);
SourceVideoType->CopyAllItems(ptype);
SourceVideoType->CopyAllItems(ptype2);

ptype->SetUINT32(MF_VIDEODSP_MODE, MFVideoDSPMode_Stabilization);
//                LogMediaType(ptype);
ptype2->SetUINT32(MF_VIDEODSP_MODE, MFVideoDSPMode_Stabilization);
//              LogMediaType(ptype2);
hr = trs->SetInputType(iids[0], ptype, 0);
auto hr2 = trs->SetOutputType(oods[0], ptype2, 0);
if (SUCCEEDED(hr) && SUCCEEDED(hr2))
{
    VideoStabilizationMFT = trs;
}

This code works - the MFT is successfully configured.此代码有效 - MFT 已成功配置。 However, in my sample processing loop:但是,在我的示例处理循环中:

// pSample = sample got from the reader
CComPtr<IMFSample> pSample2;
LONGLONG dur = 0, tim = 0;
pSample->GetSampleDuration(&dur);
pSample->GetSampleTime(&tim);

trs->ProcessInput(0, pSample, 0);
MFT_OUTPUT_STREAM_INFO si = {};
trs->GetOutputStreamInfo(0, &si);

// Create pSample2 
MFCreateSample(&pSample2);
CComPtr<IMFMediaBuffer> bb;
MFCreateMemoryBuffer(si.cbSize, &bb);
pSample2->AddBuffer(bb);

DWORD st = 0;
hr = trs->ProcessOutput(0, 1, &db, &st);

This last call fails initially with MF_E_TRANSFORM_NEED_MORE_INPUT , I can understand that the MFT needs more than one sample to achieve stabilizization, so I skip this sample for the writer.最后一次调用最初失败了MF_E_TRANSFORM_NEED_MORE_INPUT ,我可以理解 MFT 需要多个样本来实现稳定,所以我跳过了作者的这个样本。

When the call succeeds, I get a sample with no time or duration.当呼叫成功时,我会得到一个没有时间或持续时间的样本。 Even If I set the time and duration manually, the sink writer fails with E_INVALIDARG.即使我手动设置时间和持续时间,接收器编写器也会因 E_INVALIDARG 而失败。

What do I miss?我想念什么?

With this source code I provide, the sink writer returns S_OK :使用我提供的这个源代码,接收器编写器返回 S_OK :

VideoStabilizationMFT 视频稳定MFT

if Microsoft is reading this, what are these guids from CLSID_CMSVideoDSPMFT ?如果Microsoft正在阅读本文,那么来自 CLSID_CMSVideoDSPMFT 的这些 guid 是什么?

Guid : 44A4AB4B-1D0C-4181-9293-E2F37680672E : VT_UI4 = 4指南:44A4AB4B-1D0C-4181-9293-E2F37680672E:VT_UI4 = 4

Guid : 8252D735-8CB3-4A2E-A296-894E7B738059 : VT_R8 = 0.869565指南:8252D735-8CB3-4A2E-A296-894E7B738059:VT_R8 = 0.869565

Guid : 9B2DEAFE-37EC-468C-90FF-024E22BD6BC6 : VT_UI4 = 0指南:9B2DEAFE-37EC-468C-90FF-024E22BD6BC6:VT_UI4 = 0

Guid : B0052692-FC62-4F21-A1DD-B9DFE1CEB9BF : VT_R8 = 0.050000指南:B0052692-FC62-4F21-A1DD-B9DFE1CEB9BF:VT_R8 = 0.050000

Guid : C8DA7888-14AA-43AE-BDF2-BF9CC48E12BE : VT_UI4 = 4指南:C8DA7888-14AA-43AE-BDF2-BF9CC48E12BE:VT_UI4 = 4

Guid : EF77D08F-7C9C-40F3-9127-96F760903367 : VT_UI4 = 0指南:EF77D08F-7C9C-40F3-9127-96F760903367:VT_UI4 = 0

Guid : F67575DF-EA5C-46DB-80C4-CEB7EF3A1701 : VT_UI4 = 1指南:F67575DF-EA5C-46DB-80C4-CEB7EF3A1701:VT_UI4 = 1

Microsoft, are you serious ?微软,你是认真的吗?

according to this documentation : https://docs.microsoft.com/en-us/windows/win32/medfound/video-stabilization-mft根据本文档: https : //docs.microsoft.com/en-us/windows/win32/medfound/video-stabilization-mft

On Win10 :在 Win10 上:

  • Video Stabilization MFT is MF_SA_D3D11_AWARE, the documentation does not speak about this Video Stabilization MFT是MF_SA_D3D11_AWARE,文档没有讲这个
  • Video Stabilization MFT can fallback to software mode, the documentation does not speak about this (see MF_SA_D3D11_AWARE)视频稳定 MFT 可以回退到软件模式,文档没有谈到这个(见 MF_SA_D3D11_AWARE)
  • Video Stabilization MFT has dynamic format change, the MFT_SUPPORT_DYNAMIC_FORMAT_CHANGE is not present on IMFTransform::GetAttributes视频稳定 MFT 具有动态格式更改,IMFTransform::GetAttributes 上不存在 MFT_SUPPORT_DYNAMIC_FORMAT_CHANGE
  • Video Stabilization MFT implements IMFGetService/IMFRealTimeClientEx/IMFShutdown, it is not in the documentation视频稳定 MFT 实现了 IMFGetService/IMFRealTimeClientEx/IMFShutdown,文档中没有
  • Video Stabilization MFT only handles MFVideoFormat_NV12, the documentation speak about MEDIASUBTYPE_YUY2视频稳定 MFT 仅处理 MFVideoFormat_NV12,文档中谈到 MEDIASUBTYPE_YUY2
  • The documentation tells to include Camerauicontrol.h, seriously...该文档告诉包含Camerauicontrol.h,认真......

Having said that, this MTF is really good doing stabilization...话虽如此,这个MTF确实很擅长稳定......

This is strange, you set attribute on IMFMediaType, not on Video Stabilization MFT :这很奇怪,您在 IMFMediaType 上设置属性,而不是在 Video Stabilization MFT 上:

ptype->SetUINT32(MF_VIDEODSP_MODE, MFVideoDSPMode_Stabilization);
ptype2->SetUINT32(MF_VIDEODSP_MODE, MFVideoDSPMode_Stabilization);

Should be :应该 :

Call IMFTransform::GetAttributes on the video stabilization MFT to get an IMFAttributes pointer.
Call IMFAttributes::SetUINT32 to set the attribute.

MF_VIDEODSP_MODE attribute MF_VIDEODSP_MODE 属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft Media Foundation中的多输入MFT - Multiple input MFT in Microsoft Media Foundation 使用DirectX视频加速(DXVA)实施媒体基础转换(MFT) - Implementing a Media Foundation Transform (MFT) with DirectX Video Acceleration (DXVA) Media Foundation - 如何在MFT中更改帧大小(Media Foundation Transform) - Media Foundation - How to change frame-size in MFT (Media Foundation Transform) 如何在Windows应用程序中使用MFT而不使用媒体转换管道 - How use MFT in windows application without using media transform pipeline Windows MFT(Media Foundation Transform)解码器未返回正确的采样时间或持续时间 - Windows MFT (Media Foundation Transform) decoder not returning proper sample time or duration Windows Media Foundation MFT 缓冲和视频质量问题(颜色丢失,曲线不太平滑,尤其是文本) - Windows Media Foundation MFT buffering and video quality issues (Loss of colors, not so smooth curves, especially text) 低质量 H.265 媒体基础编码? - Low quality H.265 Media Foundation encoding? Windows Media Foundation使用原始图像对视频进行编码 - Windows media foundation use raw image to encode video 使用 Media Foundation 时如何读取 - “unsigned char const *”? - How to read from - "unsigned char const *" when use Media Foundation? Media Foundation视频重新编码产生音频流同步偏移 - Media Foundation video re-encoding producing audio stream sync offset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM