-->
This tutorial shows how to use the Transcode API to encode an MP4 file, using H.264 for the video stream and AAC for the audio stream.
To convert such videos, you will need to download the videos and then convert them. Here shows the best stream to MP4 converter, UniConverter, with the step-by-step easy guide. Online and free methods can also be found in the following parts. UniConverter - 2 Steps to Convert Streaming Video to MP4 on Windows and Mac (with Guide!) Part. A free web app that converts video files, allowing you to change the video format, resolution or size right in your browser. Upload files of up to 2Gb. Unlike other services, our app has no limit on the number of files you can convert. Convert as many as you want. Security guaranteed.
- Encode the File
Headers and Library Files
Include the following header files. Bluestacks surface pro 3.
Link the following library files.
Define the Encoding Profiles
One approach to encoding is to define a list of target encoding profiles that are known in advance. For this tutorial, we take a relatively simple approach, and store a list of encoding formats for H.264 video and AAC audio.
For H.264, the most important format attributes are the H.264 profile, the frame rate, the frame size, and the encoded bit rate. The following array contains a list of H.264 encoding formats.
Convert Mp4 To Video Format
H.264 profiles are specified using the eAVEncH264VProfile enumeration. You could also specify the H.264 level, but the Microsoft Media Foundation H.264 Video Encoder can derive the proper level for a given video stream, so it is recommended not to override the encoder's selected level. For interlaced content, you would also specify the interlace mode (see Video Interlacing).
For AAC audio, the most important format attributes are the audio sample rate, the number of channels, the number of bits per sample, and the encoded bit rate. Optionally, you can set the AAC audio profile level indication. For more information, see AAC Encoder. The following array contains a list of AAC encoding formats. Making music with macbook pro.
Note
The H264ProfileInfo
and AACProfileInfo
structures defined here are not part of the Media Foundation API.
Write the wmain Function
The following code shows the entry point for the console application.
Clearview 1 9 5. The wmain
function does the following:
- Calls the CoInitializeEx function to initialize the COM library.
- Calls the MFStartup function to initialize Media Foundation.
- Calls the application-defined
EncodeFile
function. This function transcodes the input file to the output file, and is shown in the next section. - Calls the MFShutdown function to shut down Media Foundation.
- Call the CoUninitialize function to uninitialize the COM library.
Encode the File
The following code shows EncodeFile
function, which performs the transcoding. This function consists mostly of calls to other application-defined functions, which are shown later in this topic.
The EncodeFile
function performs the following steps.
- Creates a media source for the input file, using the URL or file path of the input file. (See Create the Media Source.)
- Gets the duration of the input file. (See Get the Source Duration.)
- Create the transcode profile. (See Create the Transcode Profile.)
- Call MFCreateTranscodeTopology to create the partial transcode topology.
- Create a helper object that manages the Media Session. (See Media Session Helper).
- Run the encoding session and wait for it to complete. (See Run the Encoding Session.)
- Call IMFMediaSource::Shutdown to shut down the media source.
- Release interface pointers. This code uses the SafeRelease function to release interface pointers. Another option is to use a COM smart pointer class, such as CComPtr.
Create the Media Source
The media source is the object that reads and parses the input file. Shortcut of snipping tool. To create the media source, pass the URL of the input file to the Source Resolver. The following code shows how to do this.
For more information, see Using the Source Resolver.
Get the Source Duration
Although not required, it is useful to query the media source for the duration of the input file. This value can be used to track the encoding progress. The duration is stored in the MF_PD_DURATION attribute of the presentation descriptor. Get the presentation descriptor by calling IMFMediaSource::CreatePresentationDescriptor.
Create the Transcode Profile
The transcode profile describes the encoding parameters. For more information about creating a transcode profile, see Using the Transcode API. To create the profile, perform the following steps.
- Call MFCreateTranscodeProfile to create the empty profile.
- Create a media type for the AAC audio stream. Add it to the profile by calling IMFTranscodeProfile::SetAudioAttributes.
- Create a media type for the H.264 video stream. Add it to the profile by calling IMFTranscodeProfile::SetVideoAttributes.
- Call MFCreateAttributes to create an attribute store for the container-level attributes.
- Set the MF_TRANSCODE_CONTAINERTYPE attribute. This is the only required container-level attribute. For MP4 file output, set this attribute to MFTranscodeContainerType_MPEG4.
- Call IMFTranscodeProfile::SetContainerAttributes to set the container-level attributes.
The following code shows these steps.
To specify the attributes for the H.264 video stream, create an attribute store and set the following attributes:
Attribute | Desription |
---|---|
MF_MT_SUBTYPE | Set to MFVideoFormat_H264. |
MF_MT_MPEG2_PROFILE | H.264 profile. |
MF_MT_FRAME_SIZE | Frame size. |
MF_MT_FRAME_RATE | Frame rate. |
MF_MT_AVG_BITRATE | Encoded bit rate. |
To specify the attributes for the AAC audio stream, create an attribute store and set the following attributes:
Encode Video Mp4 Download
Attribute | Desription |
---|---|
MF_MT_SUBTYPE | Set to MFAudioFormat_AAC |
MF_MT_AUDIO_SAMPLES_PER_SECOND | Audio sample rate. |
MF_MT_AUDIO_BITS_PER_SAMPLE | Bits per audio sample. |
MF_MT_AUDIO_NUM_CHANNELS | Number of audio channels. |
MF_MT_AUDIO_AVG_BYTES_PER_SECOND | Encoded bit rate. |
MF_MT_AUDIO_BLOCK_ALIGNMENT | Set to 1. |
MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION | AAC profile level indication (optional). |
The following code creates the video stream attributes.
The following code creates the audio stream attributes.
Note that the transcode API does not require a true media type, although it uses media-type attributes. In particular, the MF_MT_MAJOR_TYPE attribute it not required, because the SetVideoAttributes and SetAudioAttributes methods imply the major type. However, it also valid to pass an actual media type to these methods. (The IMFMediaType interface inherits IMFAttributes.)
Run the Encoding Session
The following code runs the encoding session. It uses the Media Session helper class, which is shown in the next section.
Media Session Helper
The Media Session is described more fully in the Media Foundation Architecture section of this documentation. The Media Session uses an asynchronous event model. In a GUI application, you should respond to session events without blocking the UI thread to wait for the next event. The tutorial How to Play Unprotected Media Files shows how to do this in a playback application. For encoding, the principle is the same, but fewer events are relevant:
Event | Desription |
---|---|
MESessionEnded | Raised when the encoding is complete. |
MESessionClosed | Raised when the IMFMediaSession::Close method completes. After this event is raised, it is safe to shut down the Media Session. |
For a console application, it is reasonable to block and wait for events. Depending on the source file and the encoding settings, it might take awhile to complete the encoding. You can get progress updates as follows:
- Call IMFMediaSession::GetClock to get the presentation clock.
- Query the clock for the IMFPresentationClock interface.
- Call IMFPresentationClock::GetTime to get the current position.
- The position is given in units of time. To get the percentage completed, use the value
(100 * position) / duration
.
Here is the declaration of the CSession
class.
The following code shows the complete implementation of the CSession
class.
Related topics
What is H.264/AVC
H.264/Advanced Video Coding (AVC) is an industry standard for video compression. The H.264 standard is also known as MPEG-4 Part 10 and is a successor to earlier standards such as MPEG-2 and MPEG-4. An ITU standard for compressing video based on MPEG-4 that is popular, especially for high-definition video. AVC stands for Advanced Video Coding. Actually its identical to H.264 so you can find it as H.264, H.264/AVC, H.264/MPEG-4 AVC or MPEG-4 Part 10 (it can be twice as efficient as MPEG-4 Part 2).
Taking advantage of today's high-speed chips, H.264 delivers MPEG-4 quality with a frame size up to four times greater. It can also provide MPEG-2 quality at a reduced data rate, requiring as little as one third the original bandwidths. You can think it as the 'successor' of the existing formats (MPEG-2, DivX, XviD etc) as it aims in offering similar video quality in half the size of the formats mentioned before (this reduction enables burning one HD movie onto a conventional DVD).
What can H.264 Encoder do for you
H.264 Encoder can encode other video files to H.264/AVC encoded video files, with this small but powerful tool, you can create creating an H.264 movie by yourself, it is one good utility for answer the question 'How to create an H.264 video', this software is easy to use very much, help any beginners to create high quality video files in minutes. The incredible quality and efficiency of H.264 really brings video to life on the Internet or mobile phones. H.264/AVC can encode video with approximately 3 times fewer bits than comparable MPEG-2 encoders. This program offers fast encoding speed, professional quality, at the best, it is small and FREE. This software can help more people enjoy the advantage about this advanced video coding.
How to use
|
Encoding Setting Guidelines
Program support encoding settings include:- Full High Definition (1920 x 1080)
- Commonly Used High Definition (1280 x 720)
- Standard Definition (640 x 480)
- Internet-size Content (320 x 240)
- 3G Content (176 x 144, the default)
- High Quality (Same Size with Source)
- Normal Quality (Same Size with Source)
- Fast Speed (Same Size with Source)
- For a frame size of 1920 x 1080 (full high definition), choose a data rate of 7,000-8,000 Kbps.
- For a frame size of 1280 x 720 (commonly-used high definition), choose a data rate of 5,000-6,000 Kbps.
- For a frame size of 640 x 480 (standard definition), choose a data rate of 1,000-2,000 Kbps.
- For a frame size of 320 x 240 (Internet-size content), choose a data rate of 300-500 Kbps.
- For a frame size of 176 x 144 (3G), choose a data rate of 50-60 Kbps for 10-15 fps content, or up to 150-200 Kbps for 24-30 fps content.
File Extension for H264
You may come across all kind of file extensions and still the codec can be H264:- .avi - Yes, people use .avi for H264 videos too.
- .mp4 - Nero Recode and Quicktime use this format. Better than AVI as you can store AAC audio as well (Default).
- .mkv - Matroska container - can support many video and audio formats. Have a look here for more info.
- .h264 - This extension is not commonly used. Maybe in the future.
Download
Download the main version from the Mirror
Last release, License: Freeware
System Requirements
- Windows 8, Windows 7, Windows Vista and Windows XP (Support 32-bits and 64-bits);
- 1000MHz Intel or AMD CPU, or above;
- 300 MB free hard disk space or more (If your source file is large, there need more disk space).
© Copyright H264Encoder.com 2009 - 2014.