Commit 9a04374f authored by Jerome Wu's avatar Jerome Wu

Optimize bash scripts

parent 74e8907e
#!/bin/bash -x
#!/bin/bash
set -eo pipefail
set -euo pipefail
EM_VERSION=1.39.18-upstream
......@@ -10,4 +10,4 @@ docker run \
-v $PWD:/src \
-v $PWD/wasm/cache:/emsdk_portable/.data/cache/wasm \
trzeci/emscripten:$EM_VERSION \
sh -c 'bash -x ./build.sh'
sh -c 'bash ./build.sh'
#!/bin/bash -x
#!/bin/bash
set -eo pipefail
ROOT=$PWD
BUILD_DIR=$ROOT/build
SCRIPT_ROOT=$(dirname $0)/wasm/build-scripts
# verify Emscripten version
emcc -v
# build x264
$ROOT/wasm/build-scripts/build-x264.sh $ROOT/third_party/x264 $BUILD_DIR
$SCRIPT_ROOT/build-x264.sh
# configure FFmpeg with Emscripten
$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_DIR
$SCRIPT_ROOT/configure-ffmpeg.sh
# build ffmpeg.wasm
$SCRIPT_ROOT/build-ffmpeg.sh
#!/bin/bash -x
#!/bin/bash
set -eo pipefail
BUILD_DIR=$1
source $(dirname $0)/var.sh
mkdir -p wasm/dist
ARGS=(
emmake make -j
FLAGS=(
-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
-Wno-deprecated-declarations -Wno-pointer-sign -Wno-implicit-int-float-conversion -Wno-switch -Wno-parentheses -Qunused-arguments
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264 -pthread
-O3 # optimize code with performance first
--closure 1 # code size optimization
fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
-o wasm/dist/ffmpeg-core.js
-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
......@@ -22,5 +21,7 @@ ARGS=(
-s EXPORTED_FUNCTIONS="[_main, _proxy_main]" # export main and proxy_main funcs
-s EXTRA_EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, setValue, writeAsciiToMemory]" # export preamble funcs
-s INITIAL_MEMORY=1073741824 # 1073741824 bytes = 1 GB
$OPTIM_FLAGS
)
emcc "${ARGS[@]}"
echo "FFMPEG_EM_FLAGS=${FLAGS[@]}"
emcc "${FLAGS[@]}"
#!/bin/bash -x
#!/bin/bash
set -eo pipefail
set -euo pipefail
source $(dirname $0)/var.sh
ROOT=$1
BUILD_DIR=$2
OPT_FLAGS="-O3 --closure 1"
if [[ "$OSTYPE" == "darwin"* ]]; then
# As closure compiler requires java 6 and
# I don't find a way to install it in github actions
OPT_FLAGS="-O3"
fi
cd $ROOT
ARGS=(
X264_PATH=third_party/x264
FLAGS=(
--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 $OPT_FLAGS" # flags to use pthread and code optimization
--extra-cflags="-c -s USE_PTHREADS=1 $OPTIM_FLAGS" # flags to use pthread and code optimization
)
emconfigure ./configure "${ARGS[@]}"
emmake make install-lib-static -j4
cd -
echo "FLAGS=${FLAGS[@]}"
(cd $X264_PATH && emconfigure ./configure "${FLAGS[@]}")
emmake make -C $X264_PATH install-lib-static -j
#!/bin/bash -x
#!/bin/bash
set -eo pipefail
set -euo pipefail
source $(dirname $0)/var.sh
BUILD_DIR=$1
CFLAGS="-s USE_PTHREADS -I$BUILD_DIR/include -O3 --closure 1"
CFLAGS="-s USE_PTHREADS=1 -I$BUILD_DIR/include $OPTIM_FLAGS"
LDFLAGS="$CFLAGS -L$BUILD_DIR/lib"
ARGS=(
FLAGS=(
--target-os=none # use none to prevent any os specific configurations
--arch=x86_32 # use x86_32 to achieve minimal architectural optimization
--enable-cross-compile # enable cross compile
......@@ -17,6 +17,8 @@ ARGS=(
--enable-gpl # required by x264
--enable-libx264 # enable x264
--disable-debug # disable debug info, required by closure
--disable-runtime-cpudetect # disable runtime cpu detect
--disable-autodetect # disable external libraries auto detect
--extra-cflags="$CFLAGS"
--extra-cxxflags="$CFLAGS"
--extra-ldflags="$LDFLAGS"
......@@ -29,4 +31,5 @@ ARGS=(
--objcc=emcc
--dep-cc=emcc
)
emconfigure ./configure "${ARGS[@]}"
echo "FFMPEG_CONFIG_FLAGS=${FLAGS[@]}"
emconfigure ./configure "${FLAGS[@]}"
#!/bin/bash -x
set -eo pipefail
emmake make -j4
#!/bin/bash
#
# Common variables for all scripts
set -euo pipefail
# Flags for code optimization, focus on speed instead
# of size
OPTIM_FLAGS=(
-O3
)
# Directory to install headers and libraries
BUILD_DIR=build
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Use closure complier only in linux environment
OPTIM_FLAGS=(
"${OPTIM_FLAGS[@]}"
--closure 1
)
fi
# Convert array to string
OPTIM_FLAGS="${OPTIM_FLAGS[@]}"
echo "OPTIM_FLAGS=$OPTIM_FLAGS"
echo "BUILD_DIR=$BUILD_DIR"
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