I'm trying to read/write metadata for an MP4 video from a UWP app using the Media Foundation APIs.
I have the following code
co_await winrt::resume_background(); check_hresult(MFStartup(MF_VERSION)); com_ptr<IMFByteStream> pByteStream{ nullptr }; check_hresult(MFCreateMFByteStreamOnStreamEx(inStream.as<IUnknown>().get(), pByteStream.put())); com_ptr<IMFSourceResolver> pSourceResolver{ nullptr }; check_hresult(MFCreateSourceResolver(pSourceResolver.put())); MF_OBJECT_TYPE objectType; com_ptr<IUnknown> pUnknownSource{ nullptr }; check_hresult(pSourceResolver->CreateObjectFromByteStream(pByteStream.get(), nullptr, MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_READ | MF_RESOLUTION_WRITE, nullptr, &objectType, pUnknownSource.put())); if (objectType != MF_OBJECT_MEDIASOURCE) { co_return; } com_ptr<IMFMediaSource> pMediaSource = pUnknownSource.as<IMFMediaSource>(); com_ptr<IMFPresentationDescriptor> pPresentationDescriptor{ nullptr }; check_hresult(pMediaSource->CreatePresentationDescriptor(pPresentationDescriptor.put())); com_ptr<IMFMetadataProvider> pMetadataProvider{ nullptr }; check_hresult(MFGetService(pMediaSource.as<IUnknown>().get(), MF_METADATA_PROVIDER_SERVICE, guid_of<IMFMetadataProvider>(), pMetadataProvider.put_void()));
It fails at the last line with the exception 'The object does not support the specified service'. I've read that you are supposed to use an IPropertyStore instead, like this
com_ptr<IPropertyStore> pPropertyStore{ nullptr }; check_hresult(MFGetService(pMediaSource.as<IUnknown>().get(), MF_PROPERTY_HANDLER_SERVICE, guid_of<IPropertyStore>(), pPropertyStore.put_void()));
However, MF_PROPERTY_HANDLER_SERVICE is in the desktop API partition and cannot be used from UWP apps.
What is the correct way to do this? I can use UWP's VideoProperties class instead, but I wanted a little bit more control. I'm sure the VideoProperties class must use Media Foundation internally.