Commit b426683e authored by Jerome Wu's avatar Jerome Wu

Add closure flag, documents and update test data

parent 48e9a933
......@@ -11,13 +11,14 @@ ARGS=(
-Qunused-arguments
-o wasm/dist/ffmpeg-core.js fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -pthread
-O3 # Optimize code with performance first
-O3 # optimize code with performance first
--closure 1 # code size optimization
-s USE_SDL=2 # use SDL2
-s USE_PTHREADS=1 # enable pthreads support
-s PROXY_TO_PTHREAD=1 # detach main() from browser/UI main thread
-s INVOKE_RUN=0 # not to run the main() in the beginning
-s EXPORTED_FUNCTIONS="[_main, _proxy_main]" # export main and proxy_main funcs
-s EXTRA_EXPORTED_RUNTIME_METHODS="[FS, cwrap, setValue, writeAsciiToMemory]" # export preamble funcs
-s INITIAL_MEMORY=268435456 # 268435456 bytes = 256 MB
-s INITIAL_MEMORY=1073741824 # 1073741824 bytes = 1 GB
)
emcc "${ARGS[@]}"
......@@ -7,12 +7,12 @@ BUILD_DIR=$2
cd $ROOT
ARGS=(
--prefix=$BUILD_DIR # install library in a build directory for FFmpeg to include
--host=i686-gnu # use i686 linux
--enable-static # enable building static library
--disable-cli # disable cli tools
--disable-asm # disable asm optimization
--extra-cflags="-s USE_PTHREADS=1" # pass this flags for using pthreads
--prefix=$BUILD_DIR # install library in a build directory for FFmpeg to include
--host=i686-gnu # use i686 linux
--enable-static # enable building static library
--disable-cli # disable cli tools
--disable-asm # disable asm optimization
--extra-cflags="-s USE_PTHREADS=1 -O3 --closure 1" # flags to use pthread and code optimization
)
emconfigure ./configure "${ARGS[@]}"
emmake make install-lib-static -j4
......
......@@ -3,8 +3,8 @@
set -eo pipefail
BUILD_DIR=$1
CFLAGS="-s USE_PTHREADS -O3 -I$BUILD_DIR/include"
LDFLAGS="$CFLAGS -L$BUILD_DIR/lib -s INITIAL_MEMORY=33554432" # 33554432 bytes = 32 MB
CFLAGS="-s USE_PTHREADS -I$BUILD_DIR/include -O3 --closure 1"
LDFLAGS="$CFLAGS -L$BUILD_DIR/lib"
ARGS=(
--target-os=none # use none to prevent any os specific configurations
--arch=x86_32 # use x86_32 to achieve minimal architectural optimization
......@@ -16,6 +16,7 @@ ARGS=(
--disable-doc # disable doc
--enable-gpl # required by x264
--enable-libx264 # enable x264
--disable-debug # disable debug info, required by closure
--extra-cflags="$CFLAGS"
--extra-cxxflags="$CFLAGS"
--extra-ldflags="$LDFLAGS"
......
# Optimization Flags
Statistics of using different flags to optimize code:
| flags | build time | execution time | ffmpeg-core.js size | ffmpeg-core.wasm size | ffmpeg.worker.js size |
| ----- | ---------- | ---------------| ------------------- | --------------------- | --------------------- |
| N/A | 6m 19s | 7.5s | 584,269 bytes | 30,406,730 bytes | 9,048 bytes |
| -Oz | 7m 40s | 6s | 295,674 bytes | 14,919,062 bytes | 3,363 bytes |
| -O3 | 8m 36s | 5s | 295,676 bytes | 17,746,341 bytes | 3,363 bytes |
| -O3 --closure 1 | 10m 20s | 5s | 142,076 bytes | 17,746,766 bytes | 3,624 bytes |
| -O3 --closure 1 -flto | 12m 36s | 5s | 141,516 bytes | 18,960,830 bytes | 3,624 bytes |
The best one to use in case of performance is `-O3 --closure 1`.
const path = require('path');
const fs = require('fs');
const Module = require('./dist/ffmpeg-core');
Module.onRuntimeInitialized = () => {
const data = Uint8Array.from(fs.readFileSync('tests/data/flame.avi'));
Module.FS.writeFile('flame.avi', data);
const filePath = path.join(__dirname, 'tests', 'data', 'video-15s.avi');
const data = Uint8Array.from(fs.readFileSync(filePath));
Module.FS.writeFile('video.avi', data);
const ffmpeg = Module.cwrap('proxy_main', 'number', ['number', 'number']);
const args = ['ffmpeg', '-hide_banner', '-report', '-i', 'flame.avi', 'flame.mp4'];
const args = ['ffmpeg', '-hide_banner', '-report', '-i', 'video.avi', 'video.mp4'];
const argsPtr = Module._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT);
args.forEach((s, idx) => {
const buf = Module._malloc(s.length + 1);
......@@ -26,8 +28,8 @@ Module.onRuntimeInitialized = () => {
const log = String.fromCharCode.apply(null, Module.FS.readFile(logFileName));
if (log.includes("frames successfully decoded")) {
clearInterval(timer);
const output = Module.FS.readFile('flame.mp4');
fs.writeFileSync('flame.mp4', output);
const output = Module.FS.readFile('video.mp4');
fs.writeFileSync('video.mp4', output);
console.timeEnd('execution time');
process.exit(1);
}
......
Subproject commit de37794135511be2806ff02bd4dea28adbbf27db
Subproject commit e5e817520bcba4b56b394989ba3d136d9f110b1c
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment