You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/website/docs/contribution/core.md
+86Lines changed: 86 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,92 @@ $ make prd-mt
31
31
32
32
The output file locates at **/packages/core** or **/packages/core-mt**.
33
33
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:
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!
34
120
## Publish
35
121
36
122
Simply run `npm publish` under **packages/core** or **/packages/core-mt**.
0 commit comments