MFormats SDK and MPlatform SDK come with an LGPL build of FFmpeg. It does not contain the software encoders libx264 (H.264) and libx265 (HEVC), because they are licensed under the GPL. You can add them yourself: replace one FFmpeg library, avcodec-63.dll, with the same library from a GPL build of FFmpeg.
Licensing
libx264 and libx265 are licensed under the GNU General Public License (GPL). An FFmpeg build that includes them is covered by the GPL as a whole. If you distribute an application together with such a build, the GPL applies to your application too: you must, for example, publish its source code under the GPL. The LGPL build that comes with the SDK allows closed-source applications.
The SDK does not include GPL libraries. If you add them, you are responsible for complying with their licenses. Both encoders are also available under commercial licenses from their developers.
What you need
- A shared GPL build of FFmpeg for Windows with libx264 and libx265 enabled. A build where FFmpeg is a single
.exefile without DLLs does not work. - The same FFmpeg major version as in the SDK. The library in the build must have the same file name as in the SDK:
avcodec-63.dll. If your SDK has another number, use a build with that number. - The x86 build for x86 applications and the x64 build for x64 applications.
A GPL build that matches your SDK version for testing can be requested from support@medialooks.com.
Replace the library
- Close all applications that use the SDK.
- Copy
avcodec-63.dllfrom thebinfolder of the GPL build. - Paste it over each copy of
avcodec-63.dllin the SDK folders below. Writing toC:\Program Files (x86)needs administrator rights.
Only avcodec-63.dll is replaced. The other FFmpeg libraries of the SDK stay as they are. Folders are given relative to the SDK installation folder, by default C:\Program Files (x86)\Medialooks\MFormats SDK or C:\Program Files (x86)\Medialooks\MPlatform SDK:
| SDK | x86 library goes to | x64 library goes to |
|---|---|---|
| MFormats SDK | Bin\x86 |
Bin\x64 |
| MPlatform SDK |
Bin\x86\DecoderLibBin\x86\EncoderLib
|
Bin\x64\DecoderLibBin\x64\EncoderLibBin\x64\XMediaEngine
|
Reinstalling, repairing or updating the SDK restores the LGPL library, so replace it again afterwards. If you redistribute your application, ship the replaced library in the same folders.
Check the result
The writers list only the encoders that the loaded FFmpeg library has. After the replacement, the video codecs of the formats that support them include libx264 with the name "H.264 AVC (libx264, SW)" and libx265 with the name "H.265 HEVC (x265, SW)". If they are missing, check the file name, the bitness and the folders.
MFormats, the video codecs of the MP4 format:
MFWriterClass writer = new MFWriterClass();
writer.WriterOptionSet(eMFWriterOption.eMFWO_Format, "mp4", out IMFProps formatProps);
writer.WriterOptionGetCount(eMFWriterOption.eMFWO_VideoCodec, out int count);
for (int i = 0; i < count; i++)
{
writer.WriterOptionGetByIndex(eMFWriterOption.eMFWO_VideoCodec, i, out string shortName, out string longName);
Console.WriteLine($"{shortName}: {longName}"); // libx264: H.264 AVC (libx264, SW)
}
Marshal.ReleaseComObject(formatProps);
Marshal.ReleaseComObject(writer);
MPlatform, the same list:
MWriterClass writer = new MWriterClass();
writer.ConfigSet("format", "mp4", out IMAttributes formatProps);
writer.ConfigGetCount("format::video", out int count);
for (int i = 0; i < count; i++)
{
writer.ConfigGetByIndex("format::video", i, out string name);
Console.WriteLine(name); // H.264 AVC (libx264, SW)
}
Marshal.ReleaseComObject(formatProps);
Marshal.ReleaseComObject(writer);
To encode with them, set video::codec='libx264' or video::codec='libx265' in the writer configuration. Their options are listed in Audio and video codecs: libx264 and Audio and video codecs: x265.
Still have questions?
Tell us what didn’t work or what you’d like clarified.