Skip to content

Commit

Permalink
Add FFmpeg WASM dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
squishyhuman committed Oct 7, 2023
1 parent 261216d commit e44ff7b
Show file tree
Hide file tree
Showing 15 changed files with 1,052 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ jobs:
- name: Build environment information
run: 'echo "Matrix OS: ${{ matrix.os }} on $HOSTNAME with $(getconf _NPROCESSORS_ONLN) cores"'

- name: Set git credentials
run: |
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
# Check-out the repository under $GITHUB_WORKSPACE, so the job can
# access it
- name: Checkout main repo
Expand All @@ -66,7 +71,7 @@ jobs:
frontend/src/generated
tools/dist
tools/repos/emsdk
key: restore-depends-${{ matrix.os }}-${{ hashFiles('tools/depends/native/emscripten/*', 'tools/depends/wasm/ade/*', 'tools/depends/wasm/opencv/*') }}
key: restore-depends-${{ matrix.os }}-${{ hashFiles('tools/depends/native/emscripten/*', 'tools/depends/wasm/ade/*', 'tools/depends/wasm/codecbox.js/*', 'tools/depends/wasm/ffmpeg/*', 'tools/depends/wasm/libvpx/*', 'tools/depends/wasm/opencv/*', 'tools/depends/wasm/x264/*') }}

- name: Build depends
if: steps.restore-depends.outputs.cache-hit != 'true'
Expand Down
26 changes: 26 additions & 0 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ SHELL := /bin/bash

include depends/native/emscripten/package.mk
include depends/wasm/ade/package.mk
include depends/wasm/codecbox.js/package.mk
include depends/wasm/ffmpeg/package.mk
include depends/wasm/libvpx/package.mk
include depends/wasm/opencv/package.mk
include depends/wasm/x264/package.mk

################################################################################
#
Expand All @@ -73,22 +77,28 @@ include depends/wasm/opencv/package.mk

CHECKOUT_DEPENDS = \
$(S)/checkout-ade \
$(S)/checkout-codecbox.js \
$(S)/checkout-emscripten \
$(S)/checkout-ffmpeg \
$(S)/checkout-libvpx \
$(S)/checkout-opencv \
$(S)/checkout-x264 \
$(S)/patch-opencv \

#
# Define targets for "make build"
#

BUILD_DEPENDS = \
$(S)/build-ffmpeg \
$(S)/build-opencv \

#
# Define targets for "make install"
#

INSTALL_DEPENDS = \
$(S)/install-ffmpeg \
$(S)/install-opencv \

#
Expand All @@ -104,18 +114,34 @@ install: $(INSTALL_DEPENDS)
#

.PHONY: ade
.PHONY: codecbox.js
.PHONY: emscripten
.PHONY: ffmpeg
.PHONY: libvpx
.PHONY: opencv
.PHONY: x264

ade: \
$(S)/install-ade

codecbox.js: \
$(S)/install-codecbox.js

emscripten: \
$(S)/build-emscripten

ffmpeg: \
$(S)/install-ffmpeg

libvpx: \
$(S)/install-libvpx

opencv: \
$(S)/install-opencv

x264: \
$(S)/install-x264

################################################################################
#
# Build system procedures
Expand Down
19 changes: 19 additions & 0 deletions tools/build-depends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source "${SCRIPT_DIR}/build-paths.sh"

function install_npm_utilies() {
cd "${SCRIPT_DIR}"
yarn install
}

#
# Dispatch function
#
Expand Down Expand Up @@ -61,6 +66,8 @@ function dispatch() {
}

function depends-all() {
install_npm_utilies

# Dependencies to build
BUILD_DEPENDS="emscripten "

Expand All @@ -71,18 +78,30 @@ function depends-all() {
BUILD_DEPENDS+="opencv "
fi

# Build FFmpeg
if [ ! -f "${DISTRIBUTION_LIB_DIR}/libavutil.a.a" ]; then
rm -f "${STAMP_DIR}/build-ffmpeg"
BUILD_DEPENDS+="ffmpeg "
fi

make -C "${TOOL_DIR}" -j$(getconf _NPROCESSORS_ONLN) ${BUILD_DEPENDS}
}

function depends-checkout() {
install_npm_utilies

make -C "${TOOL_DIR}" checkout -j10
}

function depends-build() {
install_npm_utilies

make -C "${TOOL_DIR}" build -j$(getconf _NPROCESSORS_ONLN)
}

function depends-install() {
install_npm_utilies

make -C "${TOOL_DIR}" install
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 4e97a5d5673d8e496634da9b2ba3b9ed1513c04e Mon Sep 17 00:00:00 2001
From: juztamau5 <[email protected]>
Date: Sat, 11 Jul 2020 11:03:54 -0700
Subject: [PATCH 1/2] Fix error building OpenH264

Error was:

codec/common/mips/copy_mb_mmi.c:94:35: error: invalid use of a cast in
a inline asm context requiring an l-value: remove the cast or build
with -fheinous-gnu-extensions

: [pDst]"+&r"((unsigned char *)pDst), [pSrc]"+&r"((unsigned char *)pSrc)
~~~~~~~~~~~~~~~~~^~~~
---
Gruntfile.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index 7f0d90d..123f403 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -251,8 +251,8 @@ module.exports = function (grunt) {
},
openh264: {
repo: 'https://github.com/cisco/openh264.git',
- make: 'emmake make SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector" -j' + 1, //paraMake,
- install: 'emmake make ARCH=mips PREFIX=' + distPath + ' install-headers install-shared',
+ make: 'emmake make USE_ASM=No SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector" -j' + 1, //paraMake,
+ install: 'emmake make USE_ASM=No ARCH=mips PREFIX=' + distPath + ' install-headers install-shared',
},
zlib: {
repo: 'https://github.com/madler/zlib.git',
--
2.20.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From e7df34d0fcb6f2f3ebd924fd5afa372181a4e4c1 Mon Sep 17 00:00:00 2001
From: juztamau5 <[email protected]>
Date: Sun, 12 Jul 2020 20:16:28 -0700
Subject: [PATCH 2/2] Fix errors building with latest llvm

Errors were:

[lame]

>> error: undefined symbol: popen (referenced by top-level compiled C/C++ code)

[openh264]

>> error: undefined symbol: pthread_attr_setscope (referenced by top-level compiled C/C++ code)
---
Gruntfile.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index 123f403..35de85c 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -231,7 +231,7 @@ module.exports = function (grunt) {
},
lame: {
repo: 'https://github.com/rbrito/lame.git',
- configure: 'emconfigure ./configure CFLAGS=-O3 --prefix=' + distPath + ' --enable-shared=no --disable-gtktest ' +
+ configure: 'emconfigure ./configure CFLAGS="-O3 -s ERROR_ON_UNDEFINED_SYMBOLS=0" --prefix=' + distPath + ' --enable-shared=no --disable-gtktest ' +
' --disable-decoder --disable-cpml',
},
libvpx: {
@@ -251,7 +251,7 @@ module.exports = function (grunt) {
},
openh264: {
repo: 'https://github.com/cisco/openh264.git',
- make: 'emmake make USE_ASM=No SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector" -j' + 1, //paraMake,
+ make: 'emmake make USE_ASM=No SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector -s ERROR_ON_UNDEFINED_SYMBOLS=0" LDFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" -j' + 1, //paraMake,
install: 'emmake make USE_ASM=No ARCH=mips PREFIX=' + distPath + ' install-headers install-shared',
},
zlib: {
--
2.20.1

24 changes: 24 additions & 0 deletions tools/depends/wasm/codecbox.js/0003-Enable-select-filter.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From 2b2406260b117af9dc08b66de42f1990c48cd842 Mon Sep 17 00:00:00 2001
From: juztamau5 <[email protected]>
Date: Sun, 26 Jul 2020 13:26:54 -0700
Subject: [PATCH 3/3] Enable select filter

---
Gruntfile.js | 1 +
1 file changed, 1 insertion(+)

diff --git a/Gruntfile.js b/Gruntfile.js
index 35de85c..e1f615d 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -176,6 +176,7 @@ module.exports = function (grunt) {
'pad',
'rotate',
'scale',
+ 'select',
'setdar',
'setsar',
'showinfo',
--
2.17.1

46 changes: 46 additions & 0 deletions tools/depends/wasm/codecbox.js/0004-Don-t-call-bash-with-x.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From e74a69bac5b0861ac22ce0b105a8457d66729a3b Mon Sep 17 00:00:00 2001
From: juztamau5 <[email protected]>
Date: Fri, 31 Jul 2020 20:43:59 -0700
Subject: [PATCH 4/4] Don't call bash with -x

---
Gruntfile.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index e1f615d..1357ebe 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -240,7 +240,7 @@ module.exports = function (grunt) {
needPatch: false,
configure: 'emconfigure ./configure --prefix=' + distPath + ' --disable-examples --disable-docs ' +
' --disable-runtime-cpu-detect --disable-multithread --target=generic-gnu --extra-cflags=-O3',
- make: 'emmake make SHELL="/bin/bash -x" -j' + paraMake,
+ make: 'emmake make SHELL="/bin/bash" -j' + paraMake,
postMake: 'emranlib libvpx.a', // https://github.com/emscripten-core/emscripten/issues/9705
},
x264: {
@@ -248,17 +248,17 @@ module.exports = function (grunt) {
needPatch: false,
configure: 'emconfigure ./configure --disable-thread --disable-asm --disable-opencl ' +
' --host=i686-pc-linux-gnu --disable-cli --enable-shared --disable-gpl --prefix=' + distPath,
- make: 'emmake make SHELL="/bin/bash -x" -j' + paraMake
+ make: 'emmake make SHELL="/bin/bash" -j' + paraMake
},
openh264: {
repo: 'https://github.com/cisco/openh264.git',
- make: 'emmake make USE_ASM=No SHELL="/bin/bash -x" ARCH=mips CFLAGS="-O3 -fno-stack-protector -s ERROR_ON_UNDEFINED_SYMBOLS=0" LDFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" -j' + 1, //paraMake,
+ make: 'emmake make USE_ASM=No SHELL="/bin/bash" ARCH=mips CFLAGS="-O3 -fno-stack-protector -s ERROR_ON_UNDEFINED_SYMBOLS=0" LDFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" -j' + 1, //paraMake,
install: 'emmake make USE_ASM=No ARCH=mips PREFIX=' + distPath + ' install-headers install-shared',
},
zlib: {
repo: 'https://github.com/madler/zlib.git',
configure: 'emconfigure ./configure --prefix=' + distPath + ' --static',
- make: 'emmake make CFLAGS="-O3" SHELL="/bin/bash -x" -j' + paraMake,
+ make: 'emmake make CFLAGS="-O3" SHELL="/bin/bash" -j' + paraMake,
},
ffmpeg: {
repo: 'https://github.com/FFmpeg/FFmpeg.git',
--
2.17.1

29 changes: 29 additions & 0 deletions tools/depends/wasm/codecbox.js/0005-Don-t-download-FFmpeg.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 031f2a2b50a187a68b130bf6da1f8d0d39de445e Mon Sep 17 00:00:00 2001
From: juztamau5 <[email protected]>
Date: Sat, 1 Aug 2020 12:33:14 -0700
Subject: [PATCH 5/5] Don't download FFmpeg

---
Gruntfile.js | 6 ------
1 file changed, 6 deletions(-)

diff --git a/Gruntfile.js b/Gruntfile.js
index 1357ebe..e60efa9 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -260,12 +260,6 @@ module.exports = function (grunt) {
configure: 'emconfigure ./configure --prefix=' + distPath + ' --static',
make: 'emmake make CFLAGS="-O3" SHELL="/bin/bash" -j' + paraMake,
},
- ffmpeg: {
- repo: 'https://github.com/FFmpeg/FFmpeg.git',
- // select your ffmpeg config
- configure: ffmpegCustomConfig,
- //configure: ffmpegFullConfig,
- },
};

var cloneDepth = 50;
--
2.17.1

Loading

0 comments on commit e44ff7b

Please sign in to comment.