forked from ffmpegwasm/ffmpeg.wasm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
207 lines (182 loc) · 7.24 KB
/
Dockerfile
File metadata and controls
207 lines (182 loc) · 7.24 KB
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
# syntax=docker/dockerfile-upstream:master-labs
# Global build arg — must be declared before the first FROM to be usable in FROM instructions.
ARG FFMPEG_TARGET=mp3
# Base emsdk image with environment variables.
FROM emscripten/emsdk:3.1.40 AS emsdk-base
ARG EXTRA_CFLAGS
ARG EXTRA_LDFLAGS
ARG FFMPEG_ST
ARG FFMPEG_MT
ARG FFMPEG_TARGET=mp3
ENV INSTALL_DIR=/opt
# We cannot upgrade to n6.0 as ffmpeg bin only supports multithread at the moment.
ENV FFMPEG_VERSION=n5.1.4
ENV CFLAGS="-I$INSTALL_DIR/include $CFLAGS $EXTRA_CFLAGS"
ENV CXXFLAGS="$CFLAGS"
ENV LDFLAGS="-L$INSTALL_DIR/lib $LDFLAGS $CFLAGS $EXTRA_LDFLAGS"
ENV EM_PKG_CONFIG_PATH=$EM_PKG_CONFIG_PATH:$INSTALL_DIR/lib/pkgconfig:/emsdk/upstream/emscripten/system/lib/pkgconfig
ENV EM_TOOLCHAIN_FILE=$EMSDK/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$EM_PKG_CONFIG_PATH
ENV FFMPEG_ST=$FFMPEG_ST
ENV FFMPEG_MT=$FFMPEG_MT
ENV FFMPEG_TARGET=$FFMPEG_TARGET
RUN apt-get update && \
apt-get install -y pkg-config autoconf automake libtool ragel
# Build x264 (used by the video target)
FROM emsdk-base AS x264-builder
ENV X264_BRANCH=4-cores
ADD https://github.com/ffmpegwasm/x264.git#$X264_BRANCH /src
COPY build/x264.sh /src/build.sh
RUN bash -x /src/build.sh
# # Build x265
# FROM emsdk-base AS x265-builder
# ENV X265_BRANCH=3.4
# ADD https://github.com/ffmpegwasm/x265.git#$X265_BRANCH /src
# COPY build/x265.sh /src/build.sh
# RUN bash -x /src/build.sh
# # Build libvpx
# FROM emsdk-base AS libvpx-builder
# ENV LIBVPX_BRANCH=v1.13.1
# ADD https://github.com/ffmpegwasm/libvpx.git#$LIBVPX_BRANCH /src
# COPY build/libvpx.sh /src/build.sh
# RUN bash -x /src/build.sh
# Build lame (only used for the mp3 target)
FROM emsdk-base AS lame-builder
ENV LAME_BRANCH=master
ADD https://github.com/ffmpegwasm/lame.git#$LAME_BRANCH /src
COPY build/lame.sh /src/build.sh
RUN bash -x /src/build.sh
# # Build ogg
# FROM emsdk-base AS ogg-builder
# ENV OGG_BRANCH=v1.3.4
# ADD https://github.com/ffmpegwasm/Ogg.git#$OGG_BRANCH /src
# COPY build/ogg.sh /src/build.sh
# RUN bash -x /src/build.sh
# # Build theora
# FROM emsdk-base AS theora-builder
# COPY --from=ogg-builder $INSTALL_DIR $INSTALL_DIR
# ENV THEORA_BRANCH=v1.1.1
# ADD https://github.com/ffmpegwasm/theora.git#$THEORA_BRANCH /src
# COPY build/theora.sh /src/build.sh
# RUN bash -x /src/build.sh
# # Build opus
# FROM emsdk-base AS opus-builder
# ENV OPUS_BRANCH=v1.3.1
# ADD https://github.com/ffmpegwasm/opus.git#$OPUS_BRANCH /src
# COPY build/opus.sh /src/build.sh
# RUN bash -x /src/build.sh
# # Build vorbis
# FROM emsdk-base AS vorbis-builder
# COPY --from=ogg-builder $INSTALL_DIR $INSTALL_DIR
# ENV VORBIS_BRANCH=v1.3.3
# ADD https://github.com/ffmpegwasm/vorbis.git#$VORBIS_BRANCH /src
# COPY build/vorbis.sh /src/build.sh
# RUN bash -x /src/build.sh
# Build zlib (needed by the video target for PNG decoding)
FROM emsdk-base AS zlib-builder
ENV ZLIB_BRANCH=v1.2.11
ADD https://github.com/ffmpegwasm/zlib.git#$ZLIB_BRANCH /src
COPY build/zlib.sh /src/build.sh
RUN bash -x /src/build.sh
# # Build libwebp
# FROM emsdk-base AS libwebp-builder
# COPY --from=zlib-builder $INSTALL_DIR $INSTALL_DIR
# ENV LIBWEBP_BRANCH=v1.3.2
# ADD https://github.com/ffmpegwasm/libwebp.git#$LIBWEBP_BRANCH /src
# COPY build/libwebp.sh /src/build.sh
# RUN bash -x /src/build.sh
# # Build freetype2
# FROM emsdk-base AS freetype2-builder
# ENV FREETYPE2_BRANCH=VER-2-10-4
# ADD https://github.com/ffmpegwasm/freetype2.git#$FREETYPE2_BRANCH /src
# COPY build/freetype2.sh /src/build.sh
# RUN bash -x /src/build.sh
# # Build fribidi
# FROM emsdk-base AS fribidi-builder
# ENV FRIBIDI_BRANCH=v1.0.9
# ADD https://github.com/fribidi/fribidi.git#$FRIBIDI_BRANCH /src
# COPY build/fribidi.sh /src/build.sh
# RUN bash -x /src/build.sh
# # Build harfbuzz
# FROM emsdk-base AS harfbuzz-builder
# ENV HARFBUZZ_BRANCH=5.2.0
# ADD https://github.com/harfbuzz/harfbuzz.git#$HARFBUZZ_BRANCH /src
# COPY build/harfbuzz.sh /src/build.sh
# RUN bash -x /src/build.sh
# # Build libass
# FROM emsdk-base AS libass-builder
# COPY --from=freetype2-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=fribidi-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=harfbuzz-builder $INSTALL_DIR $INSTALL_DIR
# ENV LIBASS_BRANCH=0.15.0
# ADD https://github.com/libass/libass.git#$LIBASS_BRANCH /src
# COPY build/libass.sh /src/build.sh
# RUN bash -x /src/build.sh
# # Build zimg
# FROM emsdk-base AS zimg-builder
# ENV ZIMG_BRANCH=release-3.0.5
# RUN apt-get update && apt-get install -y git
# RUN git clone --recursive -b $ZIMG_BRANCH https://github.com/sekrit-twc/zimg.git /src
# COPY build/zimg.sh /src/build.sh
# RUN bash -x /src/build.sh
# Dependency selector stages: choose external codec libraries based on FFMPEG_TARGET.
# mp3 target requires libmp3lame; video target relies only on FFmpeg's built-in codecs.
FROM emsdk-base AS deps-mp3
COPY --from=lame-builder $INSTALL_DIR $INSTALL_DIR
FROM emsdk-base AS deps-m4b
# no external libs needed: mp3 decoder and aac encoder are both built into FFmpeg
FROM emsdk-base AS deps-video
# zlib: needed by FFmpeg's PNG decoder
COPY --from=zlib-builder $INSTALL_DIR $INSTALL_DIR
# x264: H.264 encoder
COPY --from=x264-builder $INSTALL_DIR $INSTALL_DIR
# Select the right deps stage based on FFMPEG_TARGET (ARG declared before first FROM, so
# it is available here for use in the FROM instruction).
FROM deps-${FFMPEG_TARGET} AS codec-deps
# Base ffmpeg image: SDL2 + FFmpeg source on top of the selected codec deps.
FROM codec-deps AS ffmpeg-base
RUN embuilder build sdl2 sdl2-mt
ADD https://github.com/FFmpeg/FFmpeg.git#$FFMPEG_VERSION /src
# COPY --from=x264-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=x265-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=libvpx-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=opus-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=theora-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=vorbis-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=libwebp-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=libass-builder $INSTALL_DIR $INSTALL_DIR
# COPY --from=zimg-builder $INSTALL_DIR $INSTALL_DIR
# Build ffmpeg
FROM ffmpeg-base AS ffmpeg-builder
COPY build/ffmpeg.sh /src/build.sh
RUN bash -x /src/build.sh \
--enable-gpl
# Target-specific codec flags (--enable-libmp3lame etc.) are handled inside
# ffmpeg.sh based on $FFMPEG_TARGET, so only the GPL license flag is needed here.
# --enable-libx264 \
# --enable-libx265 \
# --enable-libvpx \
# --enable-libtheora \
# --enable-libvorbis \
# --enable-libopus \
# --enable-zlib \
# --enable-libwebp \
# --enable-libfreetype \
# --enable-libfribidi \
# --enable-libass \
# --enable-libzimg
# Build ffmpeg.wasm
FROM ffmpeg-builder AS ffmpeg-wasm-builder
COPY src/bind /src/src/bind
COPY src/fftools /src/src/fftools
COPY build/ffmpeg-wasm.sh build.sh
# External library linking and swscale (video target) are handled inside ffmpeg-wasm.sh
# based on $FFMPEG_TARGET, so no FFMPEG_LIBS env var is needed here.
RUN mkdir -p /src/dist/umd && bash -x /src/build.sh \
-o dist/umd/ffmpeg-core.js
RUN mkdir -p /src/dist/esm && bash -x /src/build.sh \
-sEXPORT_ES6 \
-o dist/esm/ffmpeg-core.js
# Export ffmpeg-core.wasm to dist/, use `docker buildx build -o . .` to get assets
FROM scratch AS exportor
COPY --from=ffmpeg-wasm-builder /src/dist /dist