Due to licensing issues, NW.js cannot play files encoded with proprietary formats (such as H.264 and AAC) out of the box. However, there is a quick and easy workaround to that problem. This article will tell you what it is.
A bit of background
[TLDR: If you just want the solution, just skip ahead to the step by step recipe.]
NW.js is based on Chromium. Chromium is the open source base off of which Google Chrome is built. The open nature of Chromium forbids it to include support for proprietary codecs and demuxers. This means that the support for codecs in Chromium (and NW.js) is more limited than it is in Google Chrome.
Out of the box, Chromium/NW.js provides supports for the following audio and video codecs:
- VP8 & VP9
- PCM Audio (8bit, 16bit, 24bit & 32bit)
- Free Lossless Audio Codec (.flac)
- MP3 (since version 0.22.1)
These codecs can be used within the following multimedia containers:
Support for the above codecs and demuxers is provided by FFmpeg. The FFmpeg library can be compiled in various ways. One such way excludes all proprietary codecs. This is how it’s built by default for NW.js.
So, to include additional codecs, you would have to recompile FFmpeg with the appropriate options. However, recompiling software can be a complex proposition. Fortunately for us, a good soul has been doing that for each new version of NW.js that comes out.
So, here are the steps to go through to expand codec/container support in NW.js:
- Go to: https://github.com/iteufel/nwjs-ffmpeg-prebuilt/releases
- Download the zip that matches your version of NW.js and target architecture (32bit or 64bit)
- Unzip the package.
- Grab the ffmpeg.dll (Windows), libffmpeg.dylib (Mac) or libffmpeg.so (Linux) and overwrite the one found in the NW.js application folder:
- On Windows, the ffmpeg.dll file to overwrite is right at the root of the folder.
- On Mac, you have to right-click on nwjs.app and select Show Package Contents. This will allow you to navigate to and overwrite Contents/Versions/xx.xx.xx/libffmpeg.dylib.
- On Linux, the file to overwrite is lib/libffmpeg.so.
That’s it! Once you have done that, you should be able to play these additional types of content without issues:
- MP3 (if you had a version older than 0.22.1)
You will also be able to use additional multimedia containers:
- MP4 (.mp4 & .m4a)
- QuickTime (.mov)
If you so wish, you can also recompile FFmpeg yourself. You will find a simple script (and platform-specific instructions) on GitHub. You can also find more information on this topic in the NW.js documentation.
You should note that the ability to play back a proprietary codec does not dispense you to comply with its licensing terms. Here are some pointers for the most popular codecs:
- H.264: before using it, you should check out the H.264 licensing terms on the MPEG-LA website;
- AAC: per the license, unless you are creating an AAC encoder or decoder, you should be able to distribute AAC-encoded content without having to pay any fees;
- MP3: on April 27, 2017, the need to get a license from Technicolor and/or The Fraunhoffer IIS has been lifted. So, NW.js now includes support for MP3 decoding in its binary. The method described in this article still applies for older versions of NW.js that didn’t have built-in support (prior to version 0.22.1).
As of this writing, Chromium still does not include native support for MP3. NW.js has to use its own build of FFmpeg to support it.
You can get more information about the FFmpeg licensing terms on their website. Beware that this article does not contain legal advice. For the final word on licensing, you should consult a specialist.