MFMediaPropDump

This is a command line tool showcasing the Windows 7 Media Foundation APIs to read media source attributes and metadata. It also shows how to leverage the Windows Media Format SDK to read DRM properties. The source code can be useful for learning about Media Foundation. The built executable can be useful for dumping media file properties for debugging, or simply to get information about a media file, such as the frame size, frame rate, bit rate, or sample rate.

This sample can display properties for any media file format that is supported by Media Foundation.

Media Foundation does not currently have support for reading DRM properties, so the legacy Format SDK is used for that reason in the sample. Using Format SDK is otherwise discouraged, as it supports only Windows Media file formats and has some other key disadvantages. Media Foundation supports a much wider set of media file formats.

Here’s a sample screenshot of MFMediaPropDump:

clip_image002[1]

Figure 1. Dumping media properties of a WMV file using MFMediaPropDump

Techniques:

Media files contain numerous properties that apply to the file as a whole. Some properties specify the parameters with which the file was encoded (media source attributes), some contain descriptive information (metadata), and some contain information on usage restrictions (DRM properties).

Although metadata contains descriptive information for the media content, it might also contain information about the file encoding. Sometimes it’s faster to access file-encoding information through metadata than through media source attributes.

DRM properties are available only for a Windows Media DRM protected file and reside in the DRM license.

Examples of encoding parameters are encoding algorithm (media subtype), video frame size, video frame rate, audio bit rate, and audio sample rate. Encoding parameters are read using MF attributes.

Examples of metadata are title, artist, composer, genre, and movie director. There are two ways to read metadata: by using Media Foundation with the IMFMetadata interface (Media Foundation metadata), and by using the Windows Shell IPropertyStore interface (shell metadata). Media Foundation metadata and shell metadata complement each other. Shell metadata pertains not only to media files but to a much wider range of files on the system and the set of properties even for media files is richer than Media Foundation metadata. Media Foundation metadata on the other hand pertains only to media files and has support for per-stream metadata in a media file that shell metadata doesn’t have.

Examples of DRM properties are the number of allowed playbacks and the number of synchronizations to portable devices.

How to read media source attributes:

  • Create a media source (IMFMediaSource) from the media content URL.
  • Get the presentation descriptor (IMFPresentationDescriptor) from the media source.
    • Read presentation descriptor attributes (IMFAttributes).
  • Get the stream descriptor (IMFStreamDescriptor) for each stream in presentation descriptor.
    • Read stream descriptor attributes (IMFAttributes).
  • Get the media type (IMFMediaType) for each stream descriptor.
    • Read media type attributes (IMFAttributes).

How to read metadata:

  • Create the media source (IMFMediaSource) from the media content URL.
  • To read Media Foundation metadata, use the IMFGetService interface to get the IMFMetadata interface from the media source. Use the IMFMetadata interface to read the metadata.
  • To read shell metadata, use IMFGetService to get the IPropertyStore interface from the media source. Use the IPropertyStore interface to read the metadata.

How to read DRM properties:

  • Create the Format SDK metadata editor (IWMMetadataEditor) from the media content path.
  • Get the DRM editor (IWMDRMEditor) from the metadata editor.
  • Query the DRM editor for every DRM property.

To read more about presentation descriptors and stream descriptors: https://msdn.microsoft.com/en-us/library/ms698961(VS.85).aspx

To read more about media types: https://msdn.microsoft.com/en-us/library/bb530109(VS.85).aspx

To read more about media attributes: https://msdn.microsoft.com/en-us/library/dd206754(VS.85).aspx

To read more about media properties: https://msdn.microsoft.com/en-us/library/dd206755(VS.85).aspx

To read more about metadata: https://msdn.microsoft.com/en-us/library/aa368930(VS.85).aspx

To read more about reading DRM properties: https://msdn.microsoft.com/en-us/library/dd743976(VS.85).aspx

Project Structure:

  • MediaPropDump.vcproj
    The main project file for VC++ projects generated using an Application Wizard. It contains information about the version of Visual C++ that generated the file, and information about the platforms, configurations, and project features selected with the Application Wizard.
  • wmain.cpp
    Contains the application entry point, command line parsing, and error reporting.
  • MediaPropDump.cpp
    Contains routines to display media type, metadata, and DRM properties.
  • SourceResolver.cpp
    Contains a function that creates an IMFMediaSource instance from a from file path, by using the IMFSourceResolver interface.
  • MediaTypeDump.cpp
    Displays media attributes from the presentation descriptor, stream descriptors, and media types exposed by a media source.
  • MetadataDump.cpp
    Displays both Media Foundation metadata and shell metadata.
  • DRMDump.cpp
    Displays DRM properties by using Format SDK.
  • Helper.cpp
    Contains helper routines for output formatting.

Usage:

MFMediaPropDump.exe [-?] -f file

Examples:

  • Dump WMV file properties:
    MFMediaPropDump.exe -f input.wmv
  • Dump MPEG-4 file properties:
    MFMediaPropDump.exe -f input.mp4
  • Dump MP3 file properties:
    MFMediaPropDump.exe -f input.mp3
  • Dump AVI file properties:
    MFMediaPropDump.exe -f input.avi

Limitations:

  1. For DRM properties in a file, the DRM license should be acquired first. This can be done simply by playing the file in Windows Media Player, which will trigger license acquisition (either silent or non-silent, which prompts the user to acquire the license). Once the license is acquired, you can use MFMediaPropDump to display DRM properties in the file.
  2. The tool fails if the file format is not supported by Media Foundation.
  3. For ASF files with multi-language Media Foundation metadata the tool currently dumps only the default language metadata.

Downloading the Sample

You can download MFMediaPropDump from https://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&DownloadId=8757.

Follow the instructions at https://code.msdn.microsoft.com/mfblog for tips and instructions to build the sample.

This posting is provided "AS IS" with no warranties and confers no rights.