MFCopy.exe - This is a command line tool showcasing the Windows 7 Media Foundation source reader and sink writer APIs. This tool copies multimedia files from one multimedia container to another. Copying can involve simply remultiplexing the streams, transcoding to convert the streams to a different format. The source code is provided to use as a reference for learning about the source reader and sink writer.
Techniques:
Transcoding is converting from one media format to another. The previous blog post described three mechanisms that Media Foundation provides to perform transcoding, taking a detailed look at the transcode API.
Figure 1. Three ways to perform transcoding
We will now describe the source reader and sink writer objects, and how they can be used for transcoding.
Source Reader:
The source reader is a Media Foundation component that provides direct access to multimedia data. Applications can use the source reader to extract sample data in the native format (usually compressed, but not necessarily), or can request that the source reader decode the multimedia data and output uncompressed samples. The source reader provides a consistent API regardless or container or format. Since it is built on the Media Foundation platform, the source reader supports any of the media sources and codecs registered with the platform.
How to use the Source Reader:
To read more about the source reader: http://msdn.microsoft.com/en-us/library/dd389281(VS.85).aspx
Sink Writer:
The sink writer is a Media Foundation component that provides a simple way to generate multimedia files. The application configures the target container and format for each stream and then gives each sample received from the source reader to the writer object. Like the source reader, the sink writer provides a consistent API regardless of the destination container or format.
How to use the Sink Writer:
To read more about the sink writer: http://msdn.microsoft.com/en-us/library/dd374642(VS.85).aspx
Project Structure:
MFCopy.vcproj
The Visual Studio project file
main.cpp
Contains the application entry point and all user interaction, including command-line parsing and progress notification.
mfcopy.cpp
Implements the copying engine that configures the source reader and sink writer and processes multimedia samples.
Usage:
mfcopy.exe [-?] [-a audio_format] [-nc num_channels] [-sr sample_rate] [-v video format] [-fs resolution] [-fr framerate] [-im interlace_mode] [-br video_bitrate] [-q] [-s milliseconds] [-d milliseconds] [-d milliseconds] [-hw] [-xa] [-xv] [-xo] [-xm] input_filename output_filename
-? Display usage information. -a audio_format Set the output audio format. Defaults to the native format from the input file. Examples: AAC, WMAudioV8, WMAudioV9, WMAudio_Lossless -nc num_channels Set the number of audio channels. Example: 2 -sr sample_rate Resample the audio to the specified rate. Examples: 44100, 48000 -v video_format Set the output video format. Defaults to the native format from the input file. Examples: H264, WMV2, WMV3, WVC1 -fs resolution Resize the video to the specified width and height. Example: 640x480 -fr framerate Convert the video frame rate to the specified rate. Example: 30:1 -im interlace_mode Set the video interlace mode. Example: Progressive -br video_bitrate Set the average encoded bit rate for the video stream. Example: 5000000 -q Quiet mode. -s milliseconds Specify a start position in milliseconds. -d milliseconds Specify the duration to copy in milliseconds. -hw Enable hardware transforms. -xa Exclude audio streams. -xv Exclude video streams. -xo Exclude non audio/video streams (for example, text or script streams). -xm Exclude metadata. input_filename The path to the source file. output_filename The path to the destination file.
Examples:
Limitations:
Downloading the Sample
You can download MFCopy from http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&DownloadId=8574
Follow the instruction at http://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.