Skip to content

Commit dfa4f71

Browse files
committed
Merge pull request nwjs#4665 from ghostoy/issue-4595
Updated docs for building proprietary codecs easier
2 parents e7e68a7 + f4bb082 commit dfa4f71

File tree

1 file changed

+74
-15
lines changed

1 file changed

+74
-15
lines changed

docs/For Developers/Enable Proprietary Codecs.md

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,85 @@ ogg,matroska,wav
2424
!!! warning "License and Patent Fee"
2525
MP3 and H.264 codecs are licensed under the GPL in `ffmpeg` used by NW.js. Make sure your app are released with compatible license of GPL. And you also have to pay patent licensing royalties for using them. Consult a lawyer if you do not understand the licensing constraints and using patented media formats in your application.
2626

27-
In recent versions of Chromium project, ffmpeg DLL was changed to be builtin. And we don't have license to redistribute the codec in question. So developers don't have any ways to get the codec without compiling. To make things easier, we build ffmpeg as a separate Dll. The Dll we distribute will not contain any proprietary codecs in question. Developers can recompile the Dll for themselves, which is much easier than compiling NW. Or they can get Dll from someone else [from the community](https://github.com/nwjs/nw.js/issues/4492). Note that developers can redistribute binaries containing proprietary codecs as long as they have the license. If a developer doesn't have the license, using this tip or moving to other solutions doesn't make him/her eligible to redistribute the codecs.
27+
!!! warning "Warning"
28+
If you do **NOT** have the license or **NOT** pay the patent fee properly, using this tip below or moving to other solutions does **NOT** make you eligible to redistribute the codecs.
2829

29-
In order to use MP3 and H.264, you'll need to compile ffmpeg with patch and corresponding options.
30+
### Get FFmpeg DLL from Community
3031

31-
**Step 1.** Apply following patch to `third_party/ffmpeg/ffmpeg.gyp` to make `ffmpeg` include the codecs:
32+
In recent versions of Chromium project, ffmpeg was changed to be builtin. So you can't get ffmpeg dll any more from official Chrome. But you can get DLL [from the community](https://github.com/nwjs/nw.js/issues/4492). Or build FFmpeg yourself by following instructions below.
33+
34+
### Build FFmpeg DLL without Building NW.js
35+
36+
If you are using pre-built NW.js, you can just only rebuild FFmpeg DLL and replace the bundled DLL in pre-built binaries. This will save lots of time in download size (~1G) comparing to building entire NW.js (~20G).
37+
38+
**Step 1.** Download zip package of customized Chromium from GitHub. You can find the corresponding version in https://github.com/nwjs/chromium.src/tags. Extract the zip package into a local folder, such as `~/nw`. The unzipped package will include a sub directory. So the source folder is in `~/nw/<sub-directory-name>`.
39+
40+
**Step 2.** Fetch dependencies
41+
42+
Since you are not building entire NW.js, you have to fetch following dependencies manually.
43+
44+
* `build/linux/*-sysroot`: This is Linux only. Use `build/linux/sysroot_scripts/install-sysroot.py --running-as-hook` to install the dependencies.
45+
* `tools/gyp`: See `DEPS` file in the source folder for the repo and commit for this folder.
46+
* `third_party/yasm/sources/patched-yasm`: See `DEPS` file in the source folder for the repo and commit for this folder.
47+
* `third_party/ffmpeg`: see DEPS for commit and repo
48+
* `third_party/llvm-build`: Mac and Linux only. Use `tools/clang/scripts/update.py --if-needed` to download.
49+
50+
**Step 3.** Generate build targets with GYP
51+
52+
!!! tip "For Linux Developers"
53+
Please run `build/install-build-deps.sh` for the first time building FFmpeg DLL or NW.js before proceeding to the instructions below. You only have to run it once. This script will install the build dependencies automatically for you.
54+
55+
!!! tip "For Windows Developers"
56+
Please include `clang=0` in `GYP_DEFINES` below because Clang build is not enabled on Windows.
57+
58+
```bash
59+
cd path/to/nw/source/folder
60+
export GYP_GENERATORS=ninja
61+
export GYP_DEFINES="branding=Chrome ffmpeg_component=shared_library"
62+
export PYTHONPATH="$PWD/build"
63+
./tools/gyp/gyp -I build/common.gypi --depth=. ./third_party/ffmpeg/ffmpeg.gyp
64+
```
65+
66+
**Step 4.** Build ffmpeg DLL
67+
68+
```bash
69+
ninja -C out/Release ffmpeg
70+
```
71+
72+
You will find the DLL in `out/Release` folder. The path and file name varies between platforms:
73+
74+
* Windows: `ffmpeg.dll`
75+
* Mac OS X: `libffmpeg.dylib`
76+
* Linux: `lib/libffmpeg.so`
77+
78+
**Step 5.** Replace the bundled DLL in prebuild NW.js with the one you just built. The path and file name varies between platforms:
79+
80+
* Windows: `ffmpeg.dll`
81+
* Mac OS X: `nwjs.app/Contents/Versions/<chromium-version>/nwjs Framework.framework/libffmpeg.dylib`
82+
* Linux `lib/libffmpeg.so`
83+
84+
### Build Entire NW.js with Proprietary Codecs
85+
86+
If you don't use official pre-built NW.js, you can build entire NW.js with proprietary codecs enabled by following the instructions below.
87+
88+
**Step 1.** Install prerequists and fetch the source code of NW.js. See *Prerequisits* and *Get the Code* sections in [Building NW.js](Building NW.js.md).
89+
90+
**Step 2.** Apply following patch to `third_party/ffmpeg/ffmpeg.gyp` to make `ffmpeg` include the codecs:
3291
```diff
3392
diff --git a/ffmpeg.gyp b/ffmpeg.gyp
3493
index 294dd2e..7dfcd3a 100755
35-
--- a/ffmpeg.gyp
36-
+++ b/ffmpeg.gyp
37-
@@ -72,7 +72,7 @@
38-
['chromeos == 1', {
39-
'ffmpeg_branding%': '<(branding)OS',
40-
}, { # otherwise, assume Chrome/Chromium.
41-
- 'ffmpeg_branding%': '<(branding)',
42-
+ 'ffmpeg_branding%': 'Chrome'
43-
}],
44-
],
94+
--- a/ffmpeg.gyp
95+
+++ b/ffmpeg.gyp
96+
@@ -72,7 +72,7 @@
97+
['chromeos == 1', {
98+
'ffmpeg_branding%': '<(branding)OS',
99+
}, { # otherwise, assume Chrome/Chromium.
100+
- 'ffmpeg_branding%': '<(branding)',
101+
+ 'ffmpeg_branding%': 'Chrome'
102+
}],
103+
],
45104
```
46105

47-
**Step 2.** Regenerate the gyp files again with `gclient runhooks`.
106+
**Step 3.** Regenerate the gyp files again with `gclient runhooks`.
48107

49-
**Step 3.** Rebuild ffmpeg Dll with `ninja -C out/Release ffmpeg`.
108+
**Step 4.** Rebuild NW.js with `ninja -C out/Release nwjs`. Then you will get NW.js as well as FFmpeg DLL with proprietary codecs. If you just want to rebuild the DLL, running `ninja -C out/Release ffmpeg` will do. The generated binaries can be found in `out/Release`.

0 commit comments

Comments
 (0)