private void FillAudioProperty(AudioInfo info, MediaFoundation.Misc.PropertyKey key, PropVariant pv) { if (key.IsEqual(SystemProperties.System.Audio.ChannelCount)) { info.ChannelCount = (uint)pv; } if (key.IsEqual(SystemProperties.System.Audio.EncodingBitrate)) { info.EncodingBitrate = (uint)pv; } if (key.IsEqual(SystemProperties.System.Audio.SampleRate)) { info.SampleRate = (uint)pv; } if (key.IsEqual(SystemProperties.System.Audio.Format)) { info.Format = (string)pv; } if (key.IsEqual(SystemProperties.System.Audio.StreamNumber)) { info.StreamNumber = (uint)pv; } }
void TestSetValue() { PropVariant var = new PropVariant("asdf"); PropertyKey key = new PropertyKey(); key.fmtid = Guid.NewGuid(); key.pID = 3; int hr = m_ps.SetValue(key, var); MFError.ThrowExceptionForHR(hr); }
private static void FillVideoProperty(VideoInfo info, MediaFoundation.Misc.PropertyKey key, PropVariant pv) { if (key.IsEqual(SystemProperties.System.Video.Compression)) { info.Compression = (string)pv; } if (key.IsEqual(SystemProperties.System.Video.Director)) { info.Director = (string)pv; } if (key.IsEqual(SystemProperties.System.Video.EncodingBitrate)) { info.EncodingBitrate = (uint)pv; } if (key.IsEqual(SystemProperties.System.Video.FrameHeight)) { info.FrameHeight = (uint)pv; } if (key.IsEqual(SystemProperties.System.Video.FrameWidth)) { info.FrameWidth = (uint)pv; } if (key.IsEqual(SystemProperties.System.Video.FrameRate)) { info.FrameRate = (uint)pv; } if (key.IsEqual(SystemProperties.System.Video.HorizontalAspectRatio)) { info.HorizontalAspectRatio = (uint)pv; } if (key.IsEqual(SystemProperties.System.Video.VerticalAspectRatio)) { info.VerticalAspectRatio = (uint)pv; } if (key.IsEqual(SystemProperties.System.Video.TotalBitrate)) { info.TotalBitrate = (uint)pv; } if (key.IsEqual(SystemProperties.System.Video.StreamNumber)) { info.StreamNumber = (uint)pv; } }
void TestGetAt() { PropVariant var = new PropVariant(); PropertyKey key = new PropertyKey(); int hr = m_ps.GetAt(0, key); MFError.ThrowExceptionForHR(hr); Debug.Assert(key.pID == 3); hr = m_ps.GetValue(key, var); MFError.ThrowExceptionForHR(hr); Debug.Assert(var.GetString() == "asdf"); }
/// <summary> /// Based on https://docs.microsoft.com/en-us/windows/desktop/medfound/shell-metadata-providers /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void infoToolStripMenuItem_Click(object sender, EventArgs e) { IMFSourceResolver pSourceResolver = null; IMFMediaSource pSource = null; object pPropsObject = null; var url = this.listView1.SelectedItems[0].Text; try { // Create the source resolver. HResult hr = MFExtern.MFCreateSourceResolver(out pSourceResolver); Validate(hr); if (pSourceResolver == null) { throw new Exception("pSourceResolver is null"); } // Get a pointer to the IMFMediaSource interface of the media source. hr = pSourceResolver.CreateObjectFromURL(url, MFResolution.MediaSource, null, out pSource); Validate(hr); if (pSource == null) { throw new Exception("pSource is null"); } hr = MFExtern.MFGetService(pSource, MFServices.MF_PROPERTY_HANDLER_SERVICE, typeof(IPropertyStore).GUID, out pPropsObject); Validate(hr); if (pPropsObject == null) { throw new Exception("pPropsObject is null"); } IPropertyStore pProps = pPropsObject as IPropertyStore; hr = pProps.GetCount(out int cProps); Validate(hr); var audioInfo = new AudioInfo(); var videoInfo = new VideoInfo(); for (int i = 0; i < cProps; ++i) { var key = new MediaFoundation.Misc.PropertyKey(); hr = pProps.GetAt(i, key); Validate(hr); using (PropVariant pv = new PropVariant()) { hr = pProps.GetValue(key, pv); Validate(hr); FillAudioProperty(audioInfo, key, pv); FillVideoProperty(videoInfo, key, pv); } } MessageBox.Show("Audio =\n" + audioInfo + ";\nVideo =\n" + videoInfo); } finally { if (pSource != null) { Marshal.ReleaseComObject(pSource); } if (pSourceResolver != null) { Marshal.ReleaseComObject(pSourceResolver); } if (pPropsObject != null) { Marshal.ReleaseComObject(pPropsObject); } } // MessageBox.Show(url); }