Skip to content

Commit 20790e4

Browse files
committed
Reorg folders and use core as ffmpeg from now on
1 parent 4f03229 commit 20790e4

File tree

138 files changed

+19101
-9819
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+19101
-9819
lines changed

Diff for: .eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
project: [
1111
"./tsconfig.eslint.json",
1212
"./packages/*/tsconfig.json",
13+
"./packages/*/tsconfig-*.json",
1314
"./apps/*/tsconfig.json",
1415
],
1516
},

Diff for: .gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "testdata"]
2+
path = testdata
3+
url = https://github.com/ffmpegwasm/testdata

Diff for: Dockerfile

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,49 @@
1+
# syntax=docker/dockerfile-upstream:master-labs
2+
13
# Base emsdk image with environment variables.
24
FROM emscripten/emsdk:3.1.18 AS emsdk-base
35
ARG EXTRA_CFLAGS
46
ARG EXTRA_LDFLAGS
7+
ARG FFMPEG_ST
58
ARG FFMPEG_MT
69
ENV INSTALL_DIR=/src/build
710
ENV FFMPEG_VERSION=n5.1
11+
ENV X264_BRANCH=stable-wasm
812
ENV CFLAGS="$CFLAGS $EXTRA_CFLAGS"
913
ENV LDFLAGS="$LDFLAGS $CFLAGS $EXTRA_LDFLAGS"
1014
ENV EM_PKG_CONFIG_PATH=$EM_PKG_CONFIG_PATH:$INSTALL_DIR/lib/pkgconfig:/emsdk/upstream/emscripten/system/lib/pkgconfig
1115
ENV PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$EM_PKG_CONFIG_PATH
16+
ENV FFMPEG_ST=$FFMPEG_ST
1217
ENV FFMPEG_MT=$FFMPEG_MT
1318

1419
# Build x264
1520
FROM emsdk-base AS x264-builder
16-
RUN git clone \
17-
--branch stable \
18-
--depth 1 \
19-
https://github.com/ffmpegwasm/x264 \
20-
/src
21+
ADD https://github.com/ffmpegwasm/x264.git#$X264_BRANCH /src
2122
COPY build/x264.sh /src/build.sh
2223
RUN bash /src/build.sh
2324

2425
# Base ffmpeg image with dependencies and source code populated.
2526
FROM emsdk-base AS ffmpeg-base
2627
RUN apt-get update && \
2728
apt-get install -y pkg-config
28-
RUN embuilder build sdl2
29-
RUN git clone \
30-
--branch $FFMPEG_VERSION \
31-
--depth 1 \
32-
https://github.com/FFmpeg/FFmpeg \
33-
/src
29+
RUN embuilder build sdl2 sdl2-mt
30+
ADD https://github.com/FFmpeg/FFmpeg.git#$FFMPEG_VERSION /src
3431
COPY --from=x264-builder $INSTALL_DIR $INSTALL_DIR
3532

3633
# Build ffmpeg
3734
FROM ffmpeg-base AS ffmpeg-builder
3835
COPY build/ffmpeg.sh /src/build.sh
3936
RUN bash /src/build.sh
4037

41-
# Build ffmpeg-core.wasm
38+
# Build ffmpeg.wasm
4239
FROM ffmpeg-builder AS ffmpeg-wasm-builder
4340
COPY src/bind /src/wasm/bind
4441
COPY src/fftools /src/wasm/fftools
4542
RUN mkdir -p /src/dist
4643
COPY build/ffmpeg-wasm.sh build.sh
4744
# FIXME: find a way to export both entry points in one command.
48-
RUN bash /src/build.sh -o dist/ffmpeg-core.cjs
49-
RUN bash /src/build.sh -sEXPORT_ES6 -o dist/ffmpeg-core.js
45+
RUN bash /src/build.sh -o dist/ffmpeg.cjs
46+
RUN bash /src/build.sh -sEXPORT_ES6 -o dist/ffmpeg.js
5047

5148
# Export ffmpeg-core.wasm to dist/, use `docker buildx build -o . .` to get assets
5249
FROM scratch AS exportor

Diff for: Makefile

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,52 @@
1-
all: dev dev-mt
1+
all: dev
22

3+
MT_FLAGS := -sUSE_PTHREADS -pthread
4+
MT_LDFLAGS := -sPTHREAD_POOL_SIZE=8
5+
6+
DEV_CFLAGS := --profiling
7+
DEV_MT_CFLAGS := $(DEV_CFLAGS) $(MT_FLAGS)
38
PROD_CFLAGS := -O3 -msimd128
9+
PROD_MT_CFLAGS := $(PROD_CFLAGS) $(MT_FLAGS)
410

511
clean:
6-
rm -rf ./packages/core$(PKG_SUFFIX)/dist
7-
rm -rf ./packages/core$(PKG_SUFFIX)/types
12+
rm -rf ./packages/ffmpeg$(PKG_SUFFIX)/dist
13+
rm -rf ./packages/ffmpeg$(PKG_SUFFIX)/types
814

915
.PHONY: build
1016
build:
1117
make clean PKG_SUFFIX="$(PKG_SUFFIX)"
18+
cp -r src/types/ffmpeg packages/ffmpeg$(PKG_SUFFIX)/types
1219
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
1320
EXTRA_LDLAGS="$(EXTRA_LDLAGS)" \
21+
FFMPEG_ST="$(FFMPEG_ST)" \
1422
FFMPEG_MT="$(FFMPEG_MT)" \
1523
docker buildx build \
1624
--build-arg EXTRA_CFLAGS \
1725
--build-arg EXTRA_LDLAGS \
1826
--build-arg FFMPEG_MT \
19-
-o ./packages/core$(PKG_SUFFIX) \
27+
--build-arg FFMPEG_ST \
28+
-o ./packages/ffmpeg$(PKG_SUFFIX) \
2029
$(EXTRA_ARGS) \
2130
.
22-
cp -r src/types/core packages/core$(PKG_SUFFIX)/types
31+
32+
build-st:
33+
make build \
34+
FFMPEG_ST=yes
2335

2436
build-mt:
2537
make build \
2638
PKG_SUFFIX=-mt \
2739
FFMPEG_MT=yes \
28-
EXTRA_CFLAGS="-sUSE_PTHREADS -pthread" \
29-
EXTRA_LDLAGS="-sPTHREAD_POOL_SIZE=8"
40+
EXTRA_LDLAGS="$(MT_LDFLAGS)"
3041

3142
dev:
32-
make build
43+
make build-st EXTRA_CFLAGS="$(DEV_CFLAGS)"
3344

3445
dev-mt:
35-
make build-mt
46+
make build-mt EXTRA_CFLAGS="$(DEV_MT_CFLAGS)"
3647

3748
prd:
38-
make build EXTRA_CFLAGS="$(PROD_CFLAGS)"
49+
make build-st EXTRA_CFLAGS="$(PROD_CFLAGS)"
3950

4051
prd-mt:
41-
make build-mt EXTRA_CFLAGS="$(PROD_CFLAGS)"
52+
make build-mt EXTRA_CFLAGS="$(PROD_MT_CFLAGS)"

Diff for: apps/node-ts/ffmpeg/help.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import createFFmpeg from "@ffmpeg/ffmpeg";
2+
3+
void (async () => {
4+
const ffmpeg = await createFFmpeg();
5+
ffmpeg.setLogger(({ message }) => console.log(message));
6+
console.log("return code: ", ffmpeg.exec(["-h"]));
7+
})();

Diff for: apps/node-ts/ffmpeg/transcode-audio.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import createFFmpeg from "@ffmpeg/ffmpeg";
4+
5+
void (async () => {
6+
const wav = Uint8Array.from(
7+
fs.readFileSync(path.join(__dirname, "../../../testdata/audio-15s.wav"))
8+
);
9+
10+
const ffmpeg = await createFFmpeg();
11+
ffmpeg.setProgress((progress) =>
12+
console.log(`transcoding progress: ${progress * 100} %`)
13+
);
14+
15+
ffmpeg.FS.writeFile("audio.wav", wav);
16+
console.log("return code: ", ffmpeg.exec(["-i", "audio.wav", "audio.mp4"]));
17+
})();

Diff for: apps/node-ts/ffmpeg/transcode-video.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import createFFmpeg from "@ffmpeg/ffmpeg";
4+
5+
void (async () => {
6+
const avi = Uint8Array.from(
7+
fs.readFileSync(path.join(__dirname, "../../../testdata/video-15s.avi"))
8+
);
9+
10+
const ffmpeg = await createFFmpeg();
11+
ffmpeg.setProgress((progress) =>
12+
console.log(`transcoding progress: ${progress * 100} %`)
13+
);
14+
15+
ffmpeg.FS.writeFile("video.avi", avi);
16+
console.log("return code: ", ffmpeg.exec(["-i", "video.avi", "video.mp4"]));
17+
})();

Diff for: apps/node-ts/index.ts

Whitespace-only changes.

Diff for: apps/node-ts/load-core-mt.ts

-6
This file was deleted.

Diff for: apps/node-ts/load-core.ts

-6
This file was deleted.

Diff for: apps/node-ts/package.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22
"name": "node-ts",
33
"version": "0.0.1",
44
"description": "node example",
5-
"main": "index.ts",
65
"scripts": {
76
"lint": "eslint .",
8-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"help": "ts-node ffmpeg/help.ts",
8+
"transcode:video": "ts-node ffmpeg/transcode-video.ts",
9+
"transcode:audio": "ts-node ffmpeg/transcode-audio.ts"
910
},
1011
"author": "Jerome Wu <[email protected]>",
1112
"license": "MIT",
1213
"dependencies": {
13-
"@ffmpeg/core": "^0.11.0"
14+
"@ffmpeg/core": "^0.11.0",
15+
"@ffmpeg/ffmpeg": "^0.11.5",
16+
"ts-node": "^10.9.1"
1417
},
1518
"devDependencies": {
1619
"@typescript-eslint/eslint-plugin": "^5.37.0",
1720
"@typescript-eslint/parser": "^5.37.0",
1821
"eslint": "^8.23.1",
22+
"ts-node": "^10.9.1",
1923
"typescript": "^4.8.3"
2024
}
2125
}

Diff for: build/ffmpeg-wasm.sh

+46-48
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,50 @@
11
#!/bin/bash
2+
# `-o <OUTPUT_FILE_NAME>` must be provided when using this build script.
3+
# ex:
4+
# bash ffmpeg-wasm.sh -o ffmpeg.js
25

3-
EXTRA_CONF_FLAGS=(
4-
-sINITIAL_MEMORY=32MB
5-
-sALLOW_MEMORY_GROWTH
6-
)
6+
EXPORT_NAME="createFFmpeg"
77

8-
if [[ ! -z "$FFMPEG_MT" ]]; then
9-
EXTRA_CONF_FLAGS=(
10-
-sINITIAL_MEMORY=1024MB
11-
)
12-
fi
8+
CONF_FLAGS=(
9+
-I.
10+
-I./wasm/fftools
11+
-I$INSTALL_DIR/include
12+
-L$INSTALL_DIR/lib
13+
-Llibavcodec
14+
-Llibavdevice
15+
-Llibavfilter
16+
-Llibavformat
17+
-Llibavutil
18+
-Llibpostproc
19+
-Llibswresample
20+
-Llibswscale
21+
-lavcodec
22+
-lavdevice
23+
-lavfilter
24+
-lavformat
25+
-lavutil
26+
-lpostproc
27+
-lswresample
28+
-lswscale
29+
-lx264
30+
-Wno-deprecated-declarations
31+
$LDFLAGS
32+
-sUSE_SDL=2 # use emscripten SDL2 lib port
33+
-sMODULARIZE # modularized to use as a library
34+
${FFMPEG_MT:+ -sINITIAL_MEMORY=1024MB} # ALLOW_MEMORY_GROWTH is not recommended when using threads, thus we use a large initial memory
35+
${FFMPEG_ST:+ -sINITIAL_MEMORY=32MB -sALLOW_MEMORY_GROWTH} # Use just enough memory as memory usage can grow
36+
-sEXPORT_NAME="$EXPORT_NAME" # required in browser env, so that user can access this module from window.createFFmpeg
37+
-sEXPORTED_FUNCTIONS=$(node wasm/bind/ffmpeg/export.js) # exported functions
38+
-sEXPORTED_RUNTIME_METHODS=$(node wasm/bind/ffmpeg/export-runtime.js) # exported built-in functions
39+
--pre-js wasm/bind/ffmpeg/bind.js # extra bindings, contains most of the ffmpeg.wasm javascript code
40+
# ffmpeg source code
41+
wasm/fftools/cmdutils.c
42+
wasm/fftools/ffmpeg.c
43+
wasm/fftools/ffmpeg_filter.c
44+
wasm/fftools/ffmpeg_hw.c
45+
wasm/fftools/ffmpeg_mux.c
46+
wasm/fftools/ffmpeg_opt.c
47+
wasm/fftools/opt_common.c
48+
)
1349

14-
emcc \
15-
-I. \
16-
-I./wasm/fftools \
17-
-I$INSTALL_DIR/include \
18-
-L$INSTALL_DIR/lib \
19-
-Llibavcodec \
20-
-Llibavdevice \
21-
-Llibavfilter \
22-
-Llibavformat \
23-
-Llibavutil \
24-
-Llibpostproc \
25-
-Llibswresample \
26-
-Llibswscale \
27-
-lavcodec \
28-
-lavdevice \
29-
-lavfilter \
30-
-lavformat \
31-
-lavutil \
32-
-lpostproc \
33-
-lswresample \
34-
-lswscale \
35-
-lx264 \
36-
-Wno-deprecated-declarations \
37-
$LDFLAGS \
38-
-sUSE_SDL=2 \
39-
-sMODULARIZE \
40-
-sEXPORT_NAME="createFFmpegCore" \
41-
-sEXPORTED_FUNCTIONS=$(node wasm/bind/export.js) \
42-
-sEXPORTED_RUNTIME_METHODS=$(node wasm/bind/export-runtime.js) \
43-
--pre-js wasm/bind/bind.js \
44-
wasm/fftools/ffmpeg.c \
45-
wasm/fftools/ffmpeg_filter.c \
46-
wasm/fftools/ffmpeg_hw.c \
47-
wasm/fftools/ffmpeg_mux.c \
48-
wasm/fftools/ffmpeg_opt.c \
49-
wasm/fftools/cmdutils.c \
50-
wasm/fftools/opt_common.c \
51-
${EXTRA_CONF_FLAGS[@]} \
52-
$@
50+
emcc "${CONF_FLAGS[@]}" $@

Diff for: build/ffmpeg.sh

+28-30
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
#!/bin/bash
22

3-
EXTRA_CONF_FLAGS=(
4-
--disable-pthreads
5-
--disable-w32threads
6-
--disable-os2threads
7-
)
3+
CONF_FLAGS=(
4+
--target-os=none # disable target specific configs
5+
--arch=x86_32 # use x86_32 arch
6+
--enable-cross-compile # use cross compile configs
7+
--disable-asm # disable asm
8+
--disable-stripping # disable stripping as it won't work
9+
--disable-programs # disable ffmpeg, ffprobe and ffplay build
10+
--disable-doc # disable doc build
11+
--disable-debug # disable debug mode
12+
--disable-runtime-cpudetect # disable cpu detection
13+
--disable-autodetect # disable env auto detect
14+
15+
# assign toolchains and extra flags
16+
--nm="llvm-nm"
17+
--ar=emar
18+
--ranlib=emranlib
19+
--cc=emcc
20+
--cxx=em++
21+
--objcc=emcc
22+
--dep-cc=emcc
23+
--extra-cflags="$CFLAGS"
24+
--extra-cxxflags="$CFLAGS"
825

9-
if [[ ! -z "$FFMPEG_MT" ]]; then
10-
EXTRA_CONF_FLAGS=()
11-
fi
26+
# disable thread when FFMPEG_ST is NOT defined
27+
${FFMPEG_ST:+ --disable-pthreads --disable-w32threads --disable-os2threads}
1228

13-
emconfigure ./configure \
14-
--target-os=none \
15-
--arch=x86_32 \
16-
--enable-cross-compile \
17-
--disable-asm \
18-
--disable-stripping \
19-
--disable-programs \
20-
--disable-doc \
21-
--disable-debug \
22-
--disable-runtime-cpudetect \
23-
--disable-autodetect \
24-
--extra-cflags="$CFLAGS" \
25-
--extra-cxxflags="$CFLAGS" \
26-
--nm="llvm-nm" \
27-
--ar=emar \
28-
--ranlib=emranlib \
29-
--cc=emcc \
30-
--cxx=em++ \
31-
--objcc=emcc \
32-
--dep-cc=emcc \
33-
${EXTRA_CONF_FLAGS[@]} \
34-
--enable-gpl \
29+
# extra libraries
30+
--enable-gpl
3531
--enable-libx264
32+
)
3633

34+
emconfigure ./configure "${CONF_FLAGS[@]}"
3735
emmake make -j

0 commit comments

Comments
 (0)