MFSimpleEncode.exe - This is a command line tool that transcodes files from one media format to another. The source code is provided to use as a reference if you write your own transcode application. This tool uses the Media Foundation transcode API, which was introduced in Windows 7.
Transcoding is converting from one media format to another. Media Foundation provides three ways to perform transcoding:
- Configure the Media Foundation media session directly.
- Use the higher level transcode API to configure the media session.
- Use source reader and sink writer.
Figure 1. Three ways to perform transcoding
Configuring the media session directly is not straightforward. For example, you must understand the different encoders and media sinks to configure them properly. The transcode API provides a set of functions that makes it easier to build a transcode pipeline. It provides a simple profile to configure different encoders and sinks in the same way, and it automatically transfers metadata from the source file to the transcoded file.
Here is how to use the transcode API:
- Create a media source from a URL or bytestream via source resolver.
- Call MFCreateTranscodeProfile to create a transcode profile with output settings.
- Call MFCreateTranscodeTopology to create a transcode topology.
- Set the transcode topology on the media session.
- Start the transcode session by calling Start on the media session and wait for the session to fire the MESessionEnded event.
The transcode API is based on the media session, so you don’t need to manipulate the samples yourself, or understand the low-level details. However, if you need to manipulate the sample data – for example, to add effects to the samples before encoding them -- the source reader and sink writer might be a better choice. We will have some topics about the source reader and sink writer later in this series.
To read more about the transcode API: http://msdn.microsoft.com/en-us/library/dd317903(VS.85).aspx
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.
The main application source file.
This is the encoding engine that the application calls into.
This class handles asynchronous callbacks.
This class is used to create the preferred output media types for transcoding.
This class is used to create a Media Foundation media source from a URL.
MFSimpleEncode.exe -i INPUTFILE -o OUTPUTFILE [-p PROFILE] [-t DURATION] [-splitAudio CONTAINER] [-splitVideo CONTAINER] [-remux CONTAINER]
The path to the input file. The tool supports built-in input file formats: ASF, AVI, WAV, MPEG4, 3GP, MP3 and the registered 3rd party MF sources.
- o OUTPUTFILE
The path to the output file. It is highly recommended that you include the correct file extension, based on the file container. The tool supports built-in output file formats: ASF, MPEG4, 3GP and MP3.
The path to the transcode profile file. Some example profiles are provided under .\profiles. They are in XML format, so that you can easily see the configuration or modify them for your own use. Several example profiles are included:
- TranscodeProfileASF.xml - Transcodes to an ASF file.
- TranscodeProfileMPEG4.xml - Transcodes to an MPEG-4 file.
- TranscodeProfileWMA_64k.xml - Transcode to a 64kbps WMA file.
- TranscodeProfileWMA_128k.xml - Transcode to a 128kbps WMA file.
- TranscodeProfileWMA_160k.xml - Transcode to a 160kbps WMA file.
- TranscodeProfileWMA_196k.xml - Transcode to a 196kbps WMA file.
Specifies a stop time earlier than the end of file, in milliseconds. Use this parameter to get a segment of the original file.
- splitAudio CONTAINER
Splits the audio stream from the original file, without re-encoding.
- splitVideo CONTAINER
Splits the video stream from the original file, without re-encoding.
Remux the streams from the original file, without re-encoding.
CONTAINER specifies the file container type. Currently, the tool supports the following container name strings:
It is highly recommended keeping the same container type as the input file container for remuxing and splitting scenarios. For example, if the input file format is ASF/WMV/WMA, “ASF” will be the preferred CONTAINER name string.
The following options are mutually exclusive: -p, -splitAudio, -splitVideo, -remux.
1. Transcode ASF to MPEG-4:
MFSimpleencode.exe –i Input.wmv –o output.mp4 –p TranscodeProfileMPEG4.xml
2. Transcode MPEG-4 to ASF:
MFSimpleencode.exe –i input.mp4 –o output.wmv –p TranscodeProfileASF.xml
3. Strip audio from ASF:
MFSimpleencode.exe –i input.wmv –o output.wma -splitAudio ASF
4. Strip video from MPEG-4:
MFSimpleencode.exe –i input.mp4 –o output.mp4 –splitVideo MPEG4
5. Get a 2-second segment from a WMA file:
MFSimpleencode.exe -i input.wma –o output.wma –remux ASF –t 2000
- The Media Foundation transcode API supports a maximum of one audio stream and one video stream in the output file.
- This tool does not support DRM transcoding.
- This tool cannot transcode to mp3 file format unless a 3rd party mp3 encoder MFT is installed. This is because the inbox mp3 encoder MFT is licensed for Microsoft applications only and will not work when loaded by 3rd party applications.
- Remuxing/splitting to different containers might fail due to the specific container requirements.
Downloading the Sample
You can download MFSimpleEncode from http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mfblog&DownloadId=8439.
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.