Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 9e96b1c

Browse files
Build some "core" variations. (#16)
* Revert "Upgrade to emscripten v2.0.24" Because of confusing due to API changes. * Build some "core" variations. * add png-to-mp4 * add test for limited-function core Co-authored-by: jeromewu <jeromewus@gmail.com>
1 parent e87c5e2 commit 9e96b1c

File tree

19 files changed

+151
-19
lines changed

19 files changed

+151
-19
lines changed

build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ run-all() {
3333
#build-aom # disabled as it is extremely slow
3434
configure-ffmpeg
3535
build-ffmpeg
36+
configure-ffmpeg.mp4-scale
37+
build-ffmpeg.mp4-scale
38+
configure-ffmpeg.png-to-mp4
39+
build-ffmpeg.png-to-mp4
3640
)
3741
run ${SCRIPTS[@]}
3842
}

wasm/build-scripts/build-ffmpeg.mp4-scale.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,42 @@
33
set -eo pipefail
44
source $(dirname $0)/var.sh
55

6-
mkdir -p wasm/dist
7-
emmake make -j
6+
if [[ "$FFMPEG_ST" != "yes" ]]; then
7+
mkdir -p wasm/packages/core.mp4-scale/dist
8+
EXPORTED_FUNCTIONS="[_main, _proxy_main]"
9+
EXTRA_FLAGS=(
10+
-pthread
11+
-s USE_PTHREADS=1 # enable pthreads support
12+
-s PROXY_TO_PTHREAD=1 # detach main() from browser/UI main thread
13+
-o wasm/packages/core.mp4-scale/dist/ffmpeg-core.js
14+
)
15+
else
16+
mkdir -p wasm/packages/core-st.mp4-scale/dist
17+
EXPORTED_FUNCTIONS="[_main]"
18+
EXTRA_FLAGS=(
19+
-o wasm/packages/core-st.mp4-scale/dist/ffmpeg-core.js
20+
)
21+
fi
22+
823
FLAGS=(
924
-I. -I./fftools -I$BUILD_DIR/include
1025
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib
1126
-Wno-deprecated-declarations -Wno-pointer-sign -Wno-implicit-int-float-conversion -Wno-switch -Wno-parentheses -Qunused-arguments
12-
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -pthread
27+
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264
1328
fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
14-
-o wasm/dist/ffmpeg-core.js
1529
-s USE_SDL=2 # use SDL2
16-
-s USE_PTHREADS=1 # enable pthreads support
17-
-s PROXY_TO_PTHREAD=1 # detach main() from browser/UI main thread
1830
-s INVOKE_RUN=0 # not to run the main() in the beginning
1931
-s EXIT_RUNTIME=1 # exit runtime after execution
2032
-s MODULARIZE=1 # use modularized version to be more flexible
2133
-s EXPORT_NAME="createFFmpegCore" # assign export name for browser
22-
-s EXPORTED_FUNCTIONS="[_main, _proxy_main]" # export main and proxy_main funcs
34+
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" # export main and proxy_main funcs
2335
-s EXTRA_EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, setValue, writeAsciiToMemory]" # export preamble funcs
2436
-s INITIAL_MEMORY=1073741824 # 1073741824 bytes = 1 GB
37+
--post-js wasm/src/post.js
38+
--pre-js wasm/src/pre.js
2539
$OPTIM_FLAGS
40+
${EXTRA_FLAGS[@]}
2641
)
2742
echo "FFMPEG_EM_FLAGS=${FLAGS[@]}"
43+
emmake make -j
2844
emcc "${FLAGS[@]}"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
source $(dirname $0)/var.sh
5+
6+
if [[ "$FFMPEG_ST" != "yes" ]]; then
7+
mkdir -p wasm/packages/core.png-to-mp4/dist
8+
EXPORTED_FUNCTIONS="[_main, _proxy_main]"
9+
EXTRA_FLAGS=(
10+
-pthread
11+
-s USE_PTHREADS=1 # enable pthreads support
12+
-s PROXY_TO_PTHREAD=1 # detach main() from browser/UI main thread
13+
-o wasm/packages/core.png-to-mp4/dist/ffmpeg-core.js
14+
)
15+
else
16+
mkdir -p wasm/packages/core-st.png-to-mp4/dist
17+
EXPORTED_FUNCTIONS="[_main]"
18+
EXTRA_FLAGS=(
19+
-o wasm/packages/core-st.png-to-mp4/dist/ffmpeg-core.js
20+
)
21+
fi
22+
23+
FLAGS=(
24+
-I. -I./fftools -I$BUILD_DIR/include
25+
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib
26+
-Wno-deprecated-declarations -Wno-pointer-sign -Wno-implicit-int-float-conversion -Wno-switch -Wno-parentheses -Qunused-arguments
27+
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -lz
28+
fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
29+
-s USE_SDL=2 # use SDL2
30+
-s INVOKE_RUN=0 # not to run the main() in the beginning
31+
-s EXIT_RUNTIME=1 # exit runtime after execution
32+
-s MODULARIZE=1 # use modularized version to be more flexible
33+
-s EXPORT_NAME="createFFmpegCore" # assign export name for browser
34+
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" # export main and proxy_main funcs
35+
-s EXTRA_EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, setValue, writeAsciiToMemory]" # export preamble funcs
36+
-s INITIAL_MEMORY=1073741824 # 1073741824 bytes = 1 GB
37+
--post-js wasm/src/post.js
38+
--pre-js wasm/src/pre.js
39+
$OPTIM_FLAGS
40+
${EXTRA_FLAGS[@]}
41+
)
42+
echo "FFMPEG_EM_FLAGS=${FLAGS[@]}"
43+
emmake make -j
44+
emcc "${FLAGS[@]}"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
source $(dirname $0)/var.sh
5+
6+
FLAGS=(
7+
"${FFMPEG_CONFIG_FLAGS_BASE[@]}"
8+
--disable-all
9+
--enable-gpl # required by x264
10+
--enable-libx264 # enable x264
11+
--enable-zlib # enable zlib
12+
--enable-avcodec
13+
--enable-avformat
14+
--enable-avfilter
15+
--enable-swresample
16+
--enable-swscale
17+
--enable-decoder=png
18+
--enable-encoder=png,libx264
19+
--enable-parser=h264,png
20+
--enable-protocol=file
21+
--enable-demuxer=image2
22+
--enable-muxer=mp4
23+
--enable-filter=scale,format,null
24+
25+
)
26+
echo "FFMPEG_CONFIG_FLAGS=${FLAGS[@]}"
27+
emconfigure ./configure "${FLAGS[@]}"

wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"start": "serve .",
8-
"test": "node --experimental-wasm-threads --experimental-wasm-bulk-memory ./node_modules/.bin/jest"
8+
"test": "node --experimental-wasm-threads --experimental-wasm-bulk-memory ./node_modules/.bin/jest --verbose"
99
},
1010
"author": "jeromewus@gmail.com",
1111
"license": "MIT",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

wasm/tests/config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const fs = require('fs');
22
const path = require('path');
33
const base = path.join(__dirname, 'data');
4+
const base2 = path.join(__dirname, 'data2');
45
const avi = Uint8Array.from(fs.readFileSync(path.join(base, 'video-1s.avi')));
6+
const mp4 = Uint8Array.from(fs.readFileSync(path.join(base2, 'video-1s.mp4')));
57
const wav = Uint8Array.from(fs.readFileSync(path.join(base, 'audio-1s.wav')));
68
const arial = Uint8Array.from(fs.readFileSync(path.join(base, 'arial.ttf')));
79
const png = Uint8Array.from(fs.readFileSync(path.join(base, 'image.png')));
@@ -229,6 +231,26 @@ const CASES = [
229231
],
230232
st: false,
231233
},
234+
{
235+
name: 'mp4 scale',
236+
args: ['-i', 'video.mp4', '-vf', 'scale=128:-1', 'video-scaled.mp4'],
237+
input: [
238+
{ name: 'video.mp4', data: mp4 },
239+
],
240+
output: [
241+
{ name: 'video-scaled.mp4', type: 'video/mp4' },
242+
]
243+
},
244+
{
245+
name: 'png to mp4',
246+
args: ['-i', 'image.png', 'video.mp4'],
247+
input: [
248+
{ name: 'image.png', data: png },
249+
],
250+
output: [
251+
{ name: 'video.mp4', type: 'video/mp4' },
252+
]
253+
},
232254
];
233255

234256
module.exports = {

0 commit comments

Comments
 (0)