forked from davedoesdev/ffmpeg.js
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
385 lines (354 loc) · 11.5 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# 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
# Components common to webm and mp4, not for hls, dash and mkvextract
COMMON_FILTERS = aresample scale crop overlay hstack vstack
COMMON_DEMUXERS = matroska ogg mov mp3 wav image2 concat
COMMON_DECODERS = vp8 h264 vorbis opus mp3 aac pcm_s16le mjpeg png
WEBM_MUXERS = webm ogg null
WEBM_ENCODERS = libvpx_vp8 libopus
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
MP4_MUXERS = mp4 mp3 null
MP4_ENCODERS = libx264 libmp3lame aac
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
LIBRARY_HLS_JS = build/library-hls.js
HLS_DEMUXERS = matroska pcm_f32le # add mov for Safari support but beware patents!
HLS_BSFS = # add h264_mp4toannexb for Safari support but beware patents!
HLS_MUXERS = hls
HLS_DECODERS = libopus pcm_f32le # add h264 to get rid of DTS warnings but beware patents!
HLS_ENCODERS = aac
HLS_FILTERS = aresample
HLS_PARSERS = opus
FFMPEG_HLS_BC = build/ffmpeg-hls/ffmpeg.bc
FFMPEG_HLS_PC_PATH = ../opus/dist/lib/pkgconfig
HLS_SHARED_DEPS = build/opus/dist/lib/libopus.so
LIBRARY_DASH_JS = build/library-dash.js
DASH_DEMUXERS = matroska
DASH_BSFS = vp9_superframe
DASH_MUXERS = dash webm
DASH_DECODERS =
DASH_ENCODERS =
DASH_FILTERS =
DASH_PARSERS = vp9 opus
FFMPEG_DASH_BC = build/ffmpeg-dash/ffmpeg.bc
MKVE_DEMUXERS = matroska mov avi
MKVE_MUXERS = matroska mp4 srt ass sup webvtt dvd vob flac mp3 null
FFMPEG_MKVE_BC = build/ffmpeg-mkve/ffmpeg.o
FFMPEG_MKVE_FFPROBE_BC = build/ffmpeg-mkve/ffprobe.o
all: webm mp4 hls dash mkve
webm: ffmpeg-webm.js ffmpeg-worker-webm.js
mp4: ffmpeg-mp4.js ffmpeg-worker-mp4.js
hls: ffmpeg-worker-hls.js ffmpeg-worker-hls.wasm
dash: ffmpeg-worker-dash.js ffmpeg-worker-dash.wasm
mkve: ffmpeg-worker-mkve.js ffmpeg-worker-mkve.wasm ffprobe-worker-mkve.js ffprobe-worker-mkve.wasm
clean: clean-js clean-wasm clean-ffmpeg-mkve
clean-js:
rm -f ffmpeg*.js
clean-wasm:
rm -f ffmpeg*.wasm
clean-ffmpeg-mkve:
cd build/ffmpeg-mkve && 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 -j && \
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 \
--disable-vp8-decoder \
--disable-vp9 \
&& \
emmake make -j && \
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 -j && \
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 -j && \
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_CORE_ARGS = \
--cc=emcc \
--ranlib=emranlib \
--enable-cross-compile \
--target-os=none \
--arch=x86 \
--disable-runtime-cpudetect \
--disable-asm \
--disable-fast-unaligned \
--disable-w32threads \
--disable-os2threads \
--disable-debug \
--disable-stripping \
--disable-safe-bitstream-reader \
\
--disable-all \
--enable-pthreads \
--enable-ffmpeg \
--enable-avcodec \
--enable-avformat \
--enable-avfilter \
--enable-swresample \
--enable-swscale \
--disable-network \
--disable-d3d11va \
--disable-dxva2 \
--disable-vaapi \
--disable-vdpau \
--enable-protocol=file \
--disable-bzlib \
--disable-iconv \
--disable-libxcb \
--disable-lzma \
--disable-sdl2 \
--disable-securetransport \
--disable-xlib
FFMPEG_COMMON_ARGS = \
$(FFMPEG_COMMON_CORE_ARGS) \
$(addprefix --enable-decoder=,$(COMMON_DECODERS)) \
$(addprefix --enable-demuxer=,$(COMMON_DEMUXERS)) \
$(addprefix --enable-filter=,$(COMMON_FILTERS)) \
--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)) \
--enable-libopus \
--enable-libvpx \
--extra-cflags="-s USE_ZLIB=1 -I../libvpx/dist/include" \
--extra-ldflags="-r -L../libvpx/dist/lib" \
&& \
emmake make -j EXESUF=.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)) \
--enable-gpl \
--enable-libmp3lame \
--enable-libx264 \
--extra-cflags="-s USE_ZLIB=1 -I../lame/dist/include" \
--extra-ldflags="-r -L../lame/dist/lib" \
&& \
emmake make -j EXESUF=.bc
build/ffmpeg-hls/ffmpeg.bc: $(HLS_SHARED_DEPS)
cd build/ffmpeg-hls && \
git reset --hard && \
patch -p1 < ../ffmpeg-async-io.patch && \
patch -p1 < ../ffmpeg-hls-configure.patch && \
patch -p1 < ../ffmpeg-async-exit.patch && \
patch -p1 < ../ffmpeg-pthread-exit.patch && \
EM_PKG_CONFIG_PATH=$(FFMPEG_HLS_PC_PATH) emconfigure ./configure \
$(FFMPEG_COMMON_CORE_ARGS) \
$(addprefix --enable-demuxer=,$(HLS_DEMUXERS)) \
$(addprefix --enable-muxer=,$(HLS_MUXERS)) \
$(addprefix --enable-decoder=,$(HLS_DECODERS)) \
$(addprefix --enable-encoder=,$(HLS_ENCODERS)) \
$(addprefix --enable-bsf=,$(HLS_BSFS)) \
$(addprefix --enable-filter=,$(HLS_FILTERS)) \
$(addprefix --enable-parser=,$(HLS_PARSERS)) \
--disable-zlib \
--enable-libopus \
--enable-protocol=pipe \
--extra-ldflags="-r" \
&& \
emmake make -j EXESUF=.bc
build/ffmpeg-dash/ffmpeg.bc:
cd build/ffmpeg-dash && \
git reset --hard && \
patch -p1 < ../ffmpeg-async-io.patch && \
patch -p1 < ../ffmpeg-dash-configure.patch && \
patch -p1 < ../ffmpeg-dash-codecs.patch && \
patch -p1 < ../ffmpeg-async-exit.patch && \
patch -p1 < ../ffmpeg-pthread-exit.patch && \
emconfigure ./configure \
$(FFMPEG_COMMON_CORE_ARGS) \
$(addprefix --enable-demuxer=,$(DASH_DEMUXERS)) \
$(addprefix --enable-muxer=,$(DASH_MUXERS)) \
$(addprefix --enable-decoder=,$(DASH_DECODERS)) \
$(addprefix --enable-encoder=,$(DASH_ENCODERS)) \
$(addprefix --enable-bsf=,$(DASH_BSFS)) \
$(addprefix --enable-filter=,$(DASH_FILTERS)) \
$(addprefix --enable-parser=,$(DASH_PARSERS)) \
--disable-zlib \
--enable-protocol=pipe \
--extra-ldflags="-r" \
&& \
emmake make -j EXESUF=.bc
build/ffmpeg-mkve/ffmpeg.o:
cd build/ffmpeg-mkve && \
git reset --hard && \
patch -p1 < ../ffmpeg-async-io.patch && \
patch -p1 < ../ffmpeg-async-exit.patch && \
patch -p1 < ../ffmpeg-pthread-exit.patch && \
emconfigure ./configure \
$(FFMPEG_COMMON_CORE_ARGS) \
$(addprefix --enable-demuxer=,$(MKVE_DEMUXERS)) \
$(addprefix --enable-muxer=,$(MKVE_MUXERS)) \
--disable-avfilter \
--disable-swresample \
--disable-swscale \
--enable-ffprobe \
--disable-zlib \
--enable-protocol=file \
--extra-ldflags="-r" \
&& \
emmake make -j EXESUF=.o
EMCC_COMMON_CORE_ARGS = \
-O3 \
--closure 1 \
-s WASM_ASYNC_COMPILATION=0 \
-s ASSERTIONS=0 \
-s TOTAL_MEMORY=100MB \
-s STACK_SIZE=5MB \
-s DEFAULT_PTHREAD_STACK_SIZE=5MB \
-s PTHREAD_POOL_SIZE=10 \
-s ASYNCIFY_STACK_SIZE=65536 \
--pre-js $(PRE_JS) \
-o $@
EMCC_COMMON_ARGS = \
$(EMCC_COMMON_CORE_ARGS) \
-s NODEJS_CATCH_EXIT=0 \
-s NODEJS_CATCH_REJECTION=0 \
-lnodefs.js -lworkerfs.js \
-s WASM=0
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
ffmpeg-worker-hls.js ffmpeg-worker-hls.wasm: $(FFMPEG_HLS_BC) $(PRE_JS) $(POST_JS_WORKER) $(LIBRARY_HLS_JS)
emcc $(FFMPEG_HLS_BC) $(HLS_SHARED_DEPS) \
--post-js $(POST_JS_WORKER) \
$(EMCC_COMMON_CORE_ARGS) \
-pthread \
--js-library $(LIBRARY_HLS_JS) \
-s PROXY_TO_PTHREAD \
-s WASM=1 \
-s ASYNCIFY \
-s 'ASYNCIFY_IMPORTS=["emscripten_read_async", "emscripten_close_async", "emscripten_exit_async"]'
ffmpeg-worker-dash.js ffmpeg-worker-dash.wasm: $(FFMPEG_DASH_BC) $(PRE_JS) $(POST_JS_WORKER) $(LIBRARY_DASH_JS)
emcc $(FFMPEG_DASH_BC) \
--post-js $(POST_JS_WORKER) \
$(EMCC_COMMON_CORE_ARGS) \
-pthread \
--js-library $(LIBRARY_DASH_JS) \
-s PROXY_TO_PTHREAD \
-s WASM=1 \
-s ASYNCIFY \
-s 'ASYNCIFY_IMPORTS=["emscripten_read_async", "emscripten_close_async", "emscripten_exit_async"]'
ffmpeg-worker-mkve.js ffmpeg-worker-mkve.wasm: $(FFMPEG_MKVE_BC) $(PRE_JS) $(POST_JS_WORKER)
emcc $(FFMPEG_MKVE_BC) \
--post-js $(POST_JS_WORKER) \
$(EMCC_COMMON_CORE_ARGS) \
-pthread \
-s PROXY_TO_PTHREAD \
-s WASM=1 \
-s ASYNCIFY \
-s 'ASYNCIFY_IMPORTS=["emscripten_read_async", "emscripten_close_async", "emscripten_exit_async"]'
ffprobe-worker-mkve.js ffprobe-worker-mkve.wasm: $(FFMPEG_MKVE_FFPROBE_BC) $(PRE_JS) $(POST_JS_WORKER)
emcc $(FFMPEG_MKVE_BC) \
--post-js $(POST_JS_WORKER) \
$(EMCC_COMMON_CORE_ARGS) \
-pthread \
-s PROXY_TO_PTHREAD \
-s WASM=1 \
-s ASYNCIFY \
-s 'ASYNCIFY_IMPORTS=["emscripten_read_async", "emscripten_close_async", "emscripten_exit_async"]'