0
votes

I want to be able to encode video frames using Media Foundation IMFTransform for H264 Video Encoding. That's easily doable in Win32, where you can use MFTEnumEx to enumerate the transforms and find the H264 encoder.

However, on WinRT (Store Apps), I can't find a way to instantiate. I've noticed there's a class CMSH264EncoderMFT, but there's no definition for the CLSID to use on CoCreateInstance.

With:

CoCreateInstance(CLSID_CMSH264EncoderMFT, nullptr, CLSCTX_INPROC_SERVER, __uuidof(IUnknown), (void **)&pUnknown);

CLSID_CMSH264EncoderMFT is undefined for WinRT apps.

And tried:

ComPtr<CMSH264EncoderMFT> encoder = Make<CMSH264EncoderMFT>();

It says the class CMSH264EncoderMFT is incomplete, and says "use of undefined type 'CMSH264EncoderMFT'". Don't even know if the syntax for Make is correct or appropriate...

Does anyone have a clue on how to do this for WinRT?

2
Hi, I cannot give you the correct advice, but while I faces with similar problem I have decided to use the next trick Using Free-COM DLL in Windows Store C++ Project. Ideas is that from code of WindowsStore application for Desktop versions of Windows possible call some COM DLL. IT DOES NOT WORK for Windows WinRT, but amount of devices with such version of Windows is very low. This solution is not for Universal App - only Desktop. - Evgeny Pereguda
Hi @EvgenyPereguda, thank you. It's interesting to know I can free load a COM. But I really need this for mobile. The only way I know I can encode for mobile is with a Sink Writer, but that gives me the overhead of the file format (say mp4).. I really wanted to get the sample from the IMFTransform::ProcessOutput to work with... - João Carrion

2 Answers

0
votes

Use MFCreateSinkWriterFromURL to create a file writer first. Then, use MFCreateMediaType to create an IMFMediaType. Set up its properties, one of which will be the output format: use SetGUID method on the media type with MF_MT_SUBTYPE guid and specify MFVideoFormat_H264 as the argument. Finally, use AddStream method on the sink writer to set the media type to it.

There's an example here (you'll need to modify it a bit when it sets MF_MT_SUBTYPE).

-1
votes

you cannot instantiate object via CMSH264EncoderMFT because it DOES NOT have some interfaces which MUST have object in WinRT for example IInspectable - Provides functionality required for all Windows Runtime classes. CMSH264EncoderMFT IS NOT WinRT class. You can try resolve your task by function MFCreateSinkWriterFromMediaSink - this function takes an object with interface IMFMediaSink. It is possible write code for object with IMFMediaSink interface and receive samples from IMFTransform::ProcessOutput. I just point your attention - you cannot instantiate in WindowsStore code objects which IS NOT Windows Runtime classes.

Regards, Evgeny Pereguda