Skip to content

Commit d6a25ec

Browse files
authored
Merge pull request #889 from rina-rgb/docs/core-custombuild-docker
Update core docs to include Docker custom build
2 parents 158e59f + f0e5b8f commit d6a25ec

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

apps/website/docs/contribution/core.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,92 @@ $ make prd-mt
3131
3232
The output file locates at **/packages/core** or **/packages/core-mt**.
3333

34+
## Custom Build / Reduce Build Size
35+
36+
You can customize your build to include only the libraries you need, which can significantly reduce the final build size. This is done by modifying the `Dockerfile`.
37+
38+
---
39+
40+
### Step-by-Step Example: Removing WebP Support
41+
42+
Here's how to remove `libwebp` (WebP image support) from the build. The same principle applies to other libraries.
43+
44+
You need to make changes in **4 places** in the `Dockerfile`:
45+
46+
#### 1. Remove the library builder stage
47+
48+
Find the stage that builds the library you want to remove and delete the entire block:
49+
50+
```dockerfile
51+
# Remove this entire block
52+
FROM emsdk-base AS libwebp-builder
53+
COPY --from=zlib-builder $INSTALL_DIR $INSTALL_DIR
54+
ENV LIBWEBP_BRANCH=v1.3.2
55+
ADD https://github.com/ffmpegwasm/libwebp.git#$LIBWEBP_BRANCH /src
56+
COPY build/libwebp.sh /src/build.sh
57+
RUN bash -x /src/build.sh
58+
```
59+
60+
#### 2. Remove the COPY instruction
61+
62+
In the `ffmpeg-base` stage, remove the line that copies the built library:
63+
64+
```dockerfile
65+
# Remove this line
66+
COPY --from=libwebp-builder $INSTALL_DIR $INSTALL_DIR
67+
```
68+
69+
#### 3. Remove the configure flag
70+
71+
In the `ffmpeg-builder` stage, remove the corresponding `--enable-lib...` flag:
72+
73+
```dockerfile
74+
# Remove this line from the ffmpeg-builder stage
75+
--enable-libwebp \
76+
```
77+
78+
#### 4. Remove the linker flags
79+
80+
In the `ffmpeg-wasm-builder` stage, remove the library from `FFMPEG_LIBS`:
81+
82+
```dockerfile
83+
# Remove these lines from FFMPEG_LIBS
84+
-lwebpmux \
85+
-lwebp \
86+
-lsharpyuv \
87+
```
88+
89+
> **💡 Pro Tip:** Start by removing just the main library flag (e.g., `-lwebp`). If the build fails with "undefined reference" errors, those errors will tell you exactly which additional libraries to remove.
90+
91+
#### 5. Build and test
92+
93+
```bash
94+
# Run the build command
95+
make prd
96+
97+
# Output will be in packages/core/dist/
98+
```
99+
---
100+
101+
**Additional Build Size Optimization:**
102+
103+
You can sometimes play around with `build/ffmpeg-wasm.sh` and `build/ffmpeg.sh` to disable things you are not using to make the size smaller.
104+
105+
### More Advance Customization Example: Creating a Minimal Build
106+
107+
For more advanced customization, you might want to create a minimal build that only includes the features you need. A good example is creating a build that can create a video from a sequence of images (e.g., from an HTML canvas), handle MP4 encoding/decoding, and support audio.
108+
109+
A community member, @Kaizodo, shared an approach that resulted in a build size of only 4.80MB. You can find the full details and a discussion in [GitHub Issue #866](https://github.com/ffmpegwasm/ffmpeg.wasm/issues/866).
110+
111+
The general strategy is to:
112+
113+
1. **Start with a minimal configuration:** Instead of removing libraries one by one, a more effective approach is to start with a minimal ffmpeg configuration. This can be achieved by using flags like `--disable-everything` in the ffmpeg configuration step within the `Dockerfile`.
114+
2. **Enable specific components:** After disabling everything, you can selectively enable only the encoders, decoders, muxers, demuxers, and protocols you need for your specific use case. For example: `--enable-encoder=libx264`, `--enable-decoder=png`, `--enable-muxer=mp4`, etc.
115+
3. **Include only necessary libraries:** Make sure your `Dockerfile` only builds and links the external libraries that correspond to the features you enabled (e.g., `libx264`). You can remove the build stages for any other libraries.
116+
117+
This approach gives you control over the build content and its final size.
118+
119+
We would like to thank @Kaizodo, @harkdawg and other community members for sharing their knowledge!
34120
## Publish
35121

36122
Simply run `npm publish` under **packages/core** or **/packages/core-mt**.

apps/website/docusaurus.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ const config = {
133133
prism: {
134134
theme: lightCodeTheme,
135135
darkTheme: darkCodeTheme,
136+
additionalLanguages: ['docker'],
136137
},
137138
}),
138139
plugins: [

0 commit comments

Comments
 (0)