[英]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 时,代码工作正常。
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 :
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 上:
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.