Commit 5f8c868b authored by Jerome Wu's avatar Jerome Wu

Add x264 and fix ffmpeg.js

parent 487f38a5
......@@ -39,3 +39,4 @@
/tools/python/__pycache__/
/wasm/cache
/wasm/dist
/build
[submodule "testdata"]
path = testdata
url = https://github.com/ffmpegwasm/testdata.git
[submodule "third_party/x264"]
path = third_party/x264
url = https://code.videolan.org/videolan/x264.git
......@@ -2,13 +2,16 @@
set -eo pipefail
ROOT=$(dirname $0)
ROOT=$PWD
BUILD_DIR=$ROOT/build
# verify Emscripten version
emcc -v
# build x264
$ROOT/wasm/build-scripts/build-x264.sh $ROOT/third_party/x264 $BUILD_DIR
# configure FFmpeg with Emscripten
$ROOT/wasm/build-scripts/configure.sh
# build dependencies
$ROOT/wasm/build-scripts/configure.sh $BUILD_DIR
# # build dependencies
$ROOT/wasm/build-scripts/make.sh
# build ffmpeg.wasm
$ROOT/wasm/build-scripts/build-ffmpeg.sh
# # build ffmpeg.wasm
$ROOT/wasm/build-scripts/build-ffmpeg.sh $BUILD_DIR
x264 @ db0d4177
Subproject commit db0d417728460c647ed4a847222a535b00d3dbcb
......@@ -2,13 +2,15 @@
set -eo pipefail
BUILD_DIR=$1
mkdir -p wasm/dist
ARGS=(
-I. -I./fftools
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample
-I. -I./fftools -I$BUILD_DIR/include
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib
-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 -lm
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -pthread
-O3 # Optimize code with performance first
-s USE_SDL=2 # use SDL2
-s USE_PTHREADS=1 # enable pthreads support
......@@ -16,6 +18,6 @@ ARGS=(
-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=33554432 # 33554432 bytes = 32 MB
-s INITIAL_MEMORY=268435456 # 268435456 bytes = 256 MB
)
emcc "${ARGS[@]}"
#!/bin/bash -x
set -eo pipefail
ROOT=$1
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
)
emconfigure ./configure "${ARGS[@]}"
emmake make install-lib-static -j4
cd -
......@@ -2,8 +2,9 @@
set -eo pipefail
CFLAGS="-s USE_PTHREADS -O3"
LDFLAGS="$CFLAGS -s INITIAL_MEMORY=33554432" # 33554432 bytes = 32 MB
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
ARGS=(
--target-os=none # use none to prevent any os specific configurations
--arch=x86_32 # use x86_32 to achieve minimal architectural optimization
......@@ -13,6 +14,8 @@ ARGS=(
--disable-stripping # disable stripping
--disable-programs # disable programs build (incl. ffplay, ffprobe & ffmpeg)
--disable-doc # disable doc
--enable-gpl # required by x264
--enable-libx264 # enable x264
--extra-cflags="$CFLAGS"
--extra-cxxflags="$CFLAGS"
--extra-ldflags="$LDFLAGS"
......
......@@ -6,7 +6,7 @@ Module.onRuntimeInitialized = () => {
Module.FS.writeFile('flame.avi', data);
const ffmpeg = Module.cwrap('proxy_main', 'number', ['number', 'number']);
const args = ['ffmpeg', '-hide_banner', '-i', 'flame.avi', 'flame.mp4'];
const args = ['ffmpeg', '-hide_banner', '-report', '-i', 'flame.avi', 'flame.mp4'];
const argsPtr = Module._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT);
args.forEach((s, idx) => {
const buf = Module._malloc(s.length + 1);
......@@ -17,13 +17,17 @@ Module.onRuntimeInitialized = () => {
/*
* The execution of ffmpeg is not synchronized,
* so we need to set a timer to wait for it completes.
* so we need to parse the log file to check if completed.
*/
const timer = setInterval(() => {
if (Module.FS.readdir('.').find(f => f === 'flame.mp4') !== -1) {
clearInterval(timer);
const output = Module.FS.readFile('flame.mp4');
fs.writeFileSync('flame.mp4', output);
const logFileName = Module.FS.readdir('.').find(name => name.endsWith('.log'));
if (typeof logFileName !== 'undefined') {
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);
}
}
}, 500);
};
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