forked from Kagami/ffmpeg.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
257 lines (238 loc) · 7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Compile FFmpeg and all its dependencies to JavaScript.
# You need emsdk environment installed and activated, see:
# <https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html>.
PRE_JS = build/pre.js
POST_JS_SYNC = build/post-sync.js
POST_JS_WORKER = build/post-worker.js
COMMON_FILTERS = aresample scale crop overlay hstack vstack
COMMON_DEMUXERS = matroska ogg mov mp3 wav image2 concat
COMMON_DECODERS = vp8 vp9 h264 vorbis opus mp3 aac pcm_s16le mjpeg png
COMMON_BSFS = vp9_superframe h264_mp4toannexb
WEBM_MUXERS = webm ogg mp4 mp3 null
WEBM_ENCODERS = libvpx_vp9 libopus libx264 libmp3lame aac
FFMPEG_WEBM_BC = build/ffmpeg-webm/ffmpeg.bc
FFMPEG_WEBM_PC_PATH = ../opus/dist/lib/pkgconfig
WEBM_SHARED_DEPS = \
build/opus/dist/lib/libopus.so \
build/libvpx/dist/lib/libvpx.so \
build/lame/dist/lib/libmp3lame.so \
build/x264/dist/lib/libx264.so \
MP4_MUXERS = mp4 mp3 webm null
MP4_ENCODERS = libx264 libmp3lame aac libvpx_vp9 libopus
FFMPEG_MP4_BC = build/ffmpeg-mp4/ffmpeg.bc
FFMPEG_MP4_PC_PATH = ../x264/dist/lib/pkgconfig
MP4_SHARED_DEPS = \
build/lame/dist/lib/libmp3lame.so \
build/x264/dist/lib/libx264.so \
build/opus/dist/lib/libopus.so \
build/libvpx/dist/lib/libvpx.so
all: mp4 webm
webm: ffmpeg-webm.js ffmpeg-worker-webm.js
mp4: ffmpeg-mp4.js ffmpeg-worker-mp4.js
clean: clean-js \
clean-opus clean-libvpx clean-ffmpeg-webm \
clean-lame clean-x264 clean-ffmpeg-mp4
clean-js:
rm -f ffmpeg*.js
clean-opus:
cd build/opus && git clean -xdf
clean-libvpx:
cd build/libvpx && git clean -xdf
clean-ffmpeg-webm:
cd build/ffmpeg-webm && git clean -xdf
clean-lame:
cd build/lame && git clean -xdf
clean-x264:
cd build/x264 && git clean -xdf
clean-ffmpeg-mp4:
cd build/ffmpeg-mp4 && git clean -xdf
build/opus/configure:
cd build/opus && ./autogen.sh
build/opus/dist/lib/libopus.so: build/opus/configure
cd build/opus && \
emconfigure ./configure \
CFLAGS=-O3 \
--prefix="$$(pwd)/dist" \
--disable-static \
--disable-doc \
--disable-extra-programs \
--disable-asm \
--disable-rtcd \
--disable-intrinsics \
--disable-hardening \
--disable-stack-protector \
&& \
emmake make && \
emmake make install
build/libvpx/dist/lib/libvpx.so:
cd build/libvpx && \
git reset --hard && \
patch -p1 < ../libvpx-fix-ld.patch && \
emconfigure ./configure \
--prefix="$$(pwd)/dist" \
--target=generic-gnu \
--disable-dependency-tracking \
--disable-multithread \
--disable-runtime-cpu-detect \
--enable-shared \
--disable-static \
\
--disable-examples \
--disable-docs \
--disable-unit-tests \
--disable-webm-io \
--disable-libyuv \
&& \
emmake make && \
emmake make install
build/lame/dist/lib/libmp3lame.so:
cd build/lame/lame && \
git reset --hard && \
patch -p2 < ../../lame-fix-ld.patch && \
emconfigure ./configure \
CFLAGS="-DNDEBUG -O3" \
--prefix="$$(pwd)/../dist" \
--host=x86-none-linux \
--disable-static \
\
--disable-gtktest \
--disable-analyzer-hooks \
--disable-decoder \
--disable-frontend \
&& \
emmake make && \
emmake make install
build/x264/dist/lib/libx264.so:
cd build/x264 && \
emconfigure ./configure \
--prefix="$$(pwd)/dist" \
--extra-cflags="-Wno-unknown-warning-option" \
--host=x86-none-linux \
--disable-cli \
--enable-shared \
--disable-opencl \
--disable-thread \
--disable-interlaced \
--bit-depth=8 \
--chroma-format=420 \
--disable-asm \
\
--disable-avs \
--disable-swscale \
--disable-lavf \
--disable-ffms \
--disable-gpac \
--disable-lsmash \
&& \
emmake make && \
emmake make install
# TODO(Kagami): Emscripten documentation recommends to always use shared
# libraries but it's not possible in case of ffmpeg because it has
# multiple declarations of `ff_log2_tab` symbol. GCC builds FFmpeg fine
# though because it uses version scripts and so `ff_log2_tag` symbols
# are not exported to the shared libraries. Seems like `emcc` ignores
# them. We need to file bugreport to upstream. See also:
# - <https://kripken.github.io/emscripten-site/docs/compiling/Building-Projects.html>
# - <https://github.com/kripken/emscripten/issues/831>
# - <https://ffmpeg.org/pipermail/libav-user/2013-February/003698.html>
FFMPEG_COMMON_ARGS = \
--cc=emcc \
--ranlib=emranlib \
--enable-cross-compile \
--target-os=none \
--arch=x86 \
--disable-runtime-cpudetect \
--disable-asm \
--disable-fast-unaligned \
--disable-pthreads \
--disable-w32threads \
--disable-os2threads \
--disable-debug \
--disable-stripping \
--disable-safe-bitstream-reader \
\
--disable-all \
--enable-ffmpeg \
--enable-avcodec \
--enable-avformat \
--enable-avfilter \
--enable-swresample \
--enable-swscale \
--disable-network \
--disable-d3d11va \
--disable-dxva2 \
--disable-vaapi \
--disable-vdpau \
$(addprefix --enable-bsf=,$(COMMON_BSFS)) \
$(addprefix --enable-decoder=,$(COMMON_DECODERS)) \
$(addprefix --enable-demuxer=,$(COMMON_DEMUXERS)) \
--enable-protocol=file \
$(addprefix --enable-filter=,$(COMMON_FILTERS)) \
--disable-bzlib \
--disable-iconv \
--disable-libxcb \
--disable-lzma \
--disable-sdl2 \
--disable-securetransport \
--disable-xlib \
--enable-zlib
build/ffmpeg-webm/ffmpeg.bc: $(WEBM_SHARED_DEPS)
cd build/ffmpeg-webm && \
EM_PKG_CONFIG_PATH=$(FFMPEG_WEBM_PC_PATH) emconfigure ./configure \
$(FFMPEG_COMMON_ARGS) \
$(addprefix --enable-encoder=,$(WEBM_ENCODERS)) \
$(addprefix --enable-muxer=,$(WEBM_MUXERS)) \
--pkg-config-flags="--static" \
--enable-libopus \
--enable-libvpx \
--extra-cflags="-s USE_ZLIB=1 -I../libvpx/dist/include" \
--extra-ldflags="-L../libvpx/dist/lib" \
&& \
emmake make && \
cp ffmpeg ffmpeg.bc
build/ffmpeg-mp4/ffmpeg.bc: $(MP4_SHARED_DEPS)
cd build/ffmpeg-mp4 && \
EM_PKG_CONFIG_PATH=$(FFMPEG_MP4_PC_PATH) emconfigure ./configure \
$(FFMPEG_COMMON_ARGS) \
$(addprefix --enable-encoder=,$(MP4_ENCODERS)) \
$(addprefix --enable-muxer=,$(MP4_MUXERS)) \
--pkg-config-flags="--static" \
--enable-gpl \
--enable-libmp3lame \
--enable-libx264 \
--extra-cflags="-s USE_ZLIB=1 -I../lame/dist/include" \
--extra-ldflags="-L../lame/dist/lib" \
&& \
emmake make && \
cp ffmpeg ffmpeg.bc
EMCC_COMMON_ARGS = \
-O3 \
--closure 1 \
--memory-init-file 0 \
-s WASM=0 \
-s WASM_ASYNC_COMPILATION=0 \
-s ASSERTIONS=0 \
-s EXIT_RUNTIME=1 \
-s NODEJS_CATCH_EXIT=0 \
-s NODEJS_CATCH_REJECTION=0 \
-s TOTAL_MEMORY=134217728 \
-s ALLOW_MEMORY_GROWTH=1 \
-lnodefs.js -lworkerfs.js \
--pre-js $(PRE_JS) \
-o $@
ffmpeg-webm.js: $(FFMPEG_WEBM_BC) $(PRE_JS) $(POST_JS_SYNC)
emcc $(FFMPEG_WEBM_BC) $(WEBM_SHARED_DEPS) \
--post-js $(POST_JS_SYNC) \
$(EMCC_COMMON_ARGS)
ffmpeg-worker-webm.js: $(FFMPEG_WEBM_BC) $(PRE_JS) $(POST_JS_WORKER)
emcc $(FFMPEG_WEBM_BC) $(WEBM_SHARED_DEPS) \
--post-js $(POST_JS_WORKER) \
$(EMCC_COMMON_ARGS)
ffmpeg-mp4.js: $(FFMPEG_MP4_BC) $(PRE_JS) $(POST_JS_SYNC)
emcc $(FFMPEG_MP4_BC) $(MP4_SHARED_DEPS) \
--post-js $(POST_JS_SYNC) \
$(EMCC_COMMON_ARGS) -O2
ffmpeg-worker-mp4.js: $(FFMPEG_MP4_BC) $(PRE_JS) $(POST_JS_WORKER)
emcc $(FFMPEG_MP4_BC) $(MP4_SHARED_DEPS) \
--post-js $(POST_JS_WORKER) \
$(EMCC_COMMON_ARGS) -O2