#!/usr/bin/env bash # Run with Emscripten 4.0.23 active. Pass an empty working directory on a volume # with room for the source, compiler temporary files and build output. set -euo pipefail project="$(cd "$(dirname "$0")/../.." && pwd)" mkdir -p "$1" work="$(cd "$1" && pwd)" cd "$work" export TMPDIR="$work/tmp" mkdir -p "$TMPDIR" version=5.1.10 source="ffmpeg-$version.tar.xz" checksum=392306d6fc45dab0e9e0ea55381e071842e83a2fb31d320aeda40477a7766293 curl --fail --silent --show-error --location "https://ffmpeg.org/releases/$source" --output "$source" printf '%s %s\n' "$checksum" "$source" | shasum -a 256 --check tar -xf "$source" cd "ffmpeg-$version" emconfigure ./configure \ --target-os=none --arch=wasm32 --enable-cross-compile \ --cc=emcc --cxx=em++ --ar=emar --ranlib=emranlib --nm=emnm \ --disable-asm --disable-stripping --disable-debug --disable-doc --disable-autodetect \ --disable-network --disable-pthreads --disable-w32threads --disable-os2threads \ --disable-ffplay --disable-ffprobe --disable-avdevice --disable-postproc \ --disable-everything --enable-ffmpeg --enable-protocol=file --enable-demuxer=mov \ --enable-decoder=h264,hevc,mpeg4 --enable-encoder=gif --enable-muxer=gif \ --enable-filter=buffer,buffersink,trim,setpts,crop,scale,setsar,fps,split,palettegen,paletteuse,format,transpose,hflip,vflip \ --extra-cflags=-Oz # Pass the browser-specific flags only to the final executable link. emmake make -j8 EXESUF=.js ffmpeg_g.js \ LDFLAGS='-Llibavfilter -Llibavformat -Llibavcodec -Llibswresample -Llibswscale -Llibavutil -Oz -sENVIRONMENT=worker -sMODULARIZE=1 -sEXPORT_NAME=createGifCore -sINVOKE_RUN=0 -sINITIAL_MEMORY=33554432 -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=268435456 -sFILESYSTEM=1 -sEXPORTED_RUNTIME_METHODS=FS,WORKERFS,callMain -lworkerfs.js' destination="$project/public/video-to-gif/v1" cp ffmpeg_g.js "$destination/ffmpeg.js" install -m 644 ffmpeg_g.wasm "$destination/ffmpeg_g.wasm" cp COPYING.LGPLv2.1 "$destination/" awk '{ sub(/[[:space:]]+$/, ""); lines[NR] = $0; if (NF) last = NR } END { for (i = 1; i <= last; i++) print lines[i] }' "$EMSDK/upstream/emscripten/LICENSE" > "$destination/EMSCRIPTEN-LICENSE.txt" cp "$work/$source" "$destination/" cp "$project/scripts/video-to-gif/build-core.sh" "$destination/build-core.txt"