Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions recipes/recipes_emscripten/ffmpeg/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,44 @@ export PYTHON="${BUILD_PREFIX}/bin/python3"
# Makefile variable of the same name.
unset SUBDIR

export CFLAGS="-I${PREFIX}/include ${CFLAGS:-}"
export LDFLAGS="-L${PREFIX}/lib ${LDFLAGS:-}"
export CFLAGS="-I${PREFIX}/include -pthread ${CFLAGS:-}"
export LDFLAGS="-L${PREFIX}/lib -pthread ${LDFLAGS:-}"

# llvm-nm avoids the broken packaged emnm Python launcher.
./configure \
--prefix="${PREFIX}" \
--target-os=none --arch=x86_32 --enable-cross-compile \
--disable-asm --disable-stripping --disable-programs \
--target-os=none --arch=wasm --enable-cross-compile \
--disable-stripping \
--disable-doc --disable-debug --disable-runtime-cpudetect \
--disable-autodetect --disable-pthreads --disable-w32threads \
--disable-autodetect --enable-pthreads --disable-w32threads \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are threads absolutely needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can't compile the CLI without it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that mean the pthread symbols are only dragged into the binary or are the libs also have them?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the recipe to have two pacakges now, one for the libs and another one for the CLI. I can create two packages which don't share the same core and so have the libs without pthread and the CLI with it

--disable-os2threads --disable-ffplay --disable-network \
--enable-static --disable-shared \
--enable-gpl --enable-version3 \
--enable-ffmpeg --enable-ffprobe \
--nm=llvm-nm --ar=emar --ranlib=emranlib \
--cc=emcc --cxx=em++ --objcc=emcc --dep-cc=emcc \
--enable-avcodec --enable-avformat --enable-avutil \
--enable-swscale --enable-swresample \
--enable-avfilter --enable-avdevice \
--enable-protocol=file

make -j"${CPU_COUNT:-4}"
make install
make EXESUF=.js -j"${CPU_COUNT:-4}"
make EXESUF=.js install

# FFmpeg's Emscripten link creates *_g.wasm and copies only the JavaScript
# launcher during install. Give each launcher a stable adjacent wasm file.
for tool in ffmpeg ffprobe; do
if [[ ! -s "${tool}_g.wasm" || ! -s "${PREFIX}/bin/${tool}.js" ]]; then
echo "error: ${tool} CLI was not built; expected ${tool}_g.wasm and ${PREFIX}/bin/${tool}.js" >&2
exit 1
fi
install -Dm755 "${tool}_g.wasm" "${PREFIX}/bin/${tool}.wasm"
sed -i "s/${tool}_g\\.wasm/${tool}.wasm/g" "${PREFIX}/bin/${tool}.js"
if [[ ! -s "${PREFIX}/bin/${tool}.wasm" ]]; then
echo "error: failed to install ${PREFIX}/bin/${tool}.wasm" >&2
exit 1
fi
done

install -Dm644 "${RECIPE_DIR}/cmake/FFmpegConfig.cmake" \
"${PREFIX}/lib/cmake/FFmpeg/FFmpegConfig.cmake"
Expand Down
4 changes: 4 additions & 0 deletions recipes/recipes_emscripten/ffmpeg/build_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ echo "Building FFmpeg tests..."
echo "=========================================="

export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
export CFLAGS="${CFLAGS:-}"
export LDFLAGS="${LDFLAGS:-}"

mkdir -p build_tests
cd build_tests
Expand All @@ -20,6 +22,8 @@ emmake ninja

echo "Running FFmpeg tests..."
node test_ffmpeg.js
node "${PREFIX}/bin/ffmpeg.js" -version
node "${PREFIX}/bin/ffprobe.js" -version

echo "=========================================="
echo "All FFmpeg tests passed!"
Expand Down
12 changes: 11 additions & 1 deletion recipes/recipes_emscripten/ffmpeg/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source:
sha256: b6863adde98898f42602017462871b5f6333e65aec803fdd7a6308639c52edf3

build:
number: 0
number: 1
script: build.sh

requirements:
Expand All @@ -33,6 +33,16 @@ tests:
- libswresample.a
- libavfilter.a
- libavdevice.a
bin:
# Rattler adds .js and .wasm for Emscripten bin entries.
- ffmpeg
- ffprobe
files:
# Check both members of each Emscripten executable explicitly.
- bin/ffmpeg.js
- bin/ffmpeg.wasm
- bin/ffprobe.js
- bin/ffprobe.wasm
include:
- libavcodec/avcodec.h
- libavformat/avformat.h
Expand Down