Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add web demo and emscripten configs #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 29 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ COPY --from=x264-builder $INSTALL_DIR $INSTALL_DIR

# Build libav
FROM libav-base AS libav-builder
RUN emconfigure ./configure \
RUN make distclean; emconfigure ./configure \
--target-os=none \
--arch=x86_32 \
--enable-cross-compile \
Expand All @@ -54,6 +54,22 @@ RUN emconfigure ./configure \
--disable-pthreads \
--disable-w32threads \
--disable-os2threads \
--disable-swscale-alpha \
--disable-swresample \
--disable-swscale \
--disable-postproc \
--disable-avfilter \
--disable-avdevice \
--disable-network \
--disable-dct \
--disable-dwt \
--disable-lsp \
--disable-mdct \
--disable-rdft \
--disable-fft \
--disable-faan \
--disable-pixelutils \
--enable-small \
--extra-cflags="$CFLAGS" \
--extra-cxxflags="$CFLAGS" \
--nm="llvm-nm" \
Expand All @@ -64,7 +80,17 @@ RUN emconfigure ./configure \
--objcc=emcc \
--dep-cc=emcc \
--enable-gpl \
--enable-libx264 \
--disable-encoders \
--disable-decoders \
--enable-decoder=h264 \
--disable-hwaccels \
--disable-muxers \
--disable-parsers \
--disable-bsfs \
--disable-indevs \
--disable-outdevs \
--disable-devices \
--disable-filters \
&& \
emmake make -j

Expand All @@ -78,28 +104,18 @@ RUN emcc \
-I$INSTALL_DIR/include \
-L$INSTALL_DIR/lib \
-Llibavcodec \
-Llibavdevice \
-Llibavfilter \
-Llibavformat \
-Llibavutil \
-Llibpostproc \
-Llibswresample \
-Llibswscale \
-lavcodec \
-lavdevice \
-lavfilter \
-lavformat \
-lavutil \
-lpostproc \
-lswresample \
-lswscale \
-lx264 \
-Wno-deprecated-declarations \
$LDFLAGS \
-sMODULARIZE \
-sALLOW_MEMORY_GROWTH \
-sEXPORTED_FUNCTIONS=$(node src/bind/export.js) \
-sEXPORTED_RUNTIME_METHODS=$(node src/bind/export-runtime.js) \
-sENVIRONMENT="worker" \
--pre-js src/bind/bind.js \
-o dist/libav-core.js \
src/bind/**/*.c
Expand Down
28 changes: 28 additions & 0 deletions apps/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<div class="input">
<input type="file" name="video" accept="video/*" id="file" />
<canvas id="yuv"></canvas>
</div>
<script type="module">
import {main} from '/dist/index.js'
const file = document.getElementById('file');
file.addEventListener('change', e => {
if (e.target.files.length > 0) {
const f = e.target.files[0];
const url = URL.createObjectURL(f);
main(url,'dist');
}
})
</script>
</body>

</html>
33 changes: 33 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "web",
"version": "0.0.0",
"description": "libav.wasm web demo apps",
"main": "dist/index.js",
"module": "dist/index.js",
"scripts": {
"dev": "concurrently --names \"Watch,Http\" -c \"bgBlue.bold,bgGreen.bold\" \"rollup -c rollup.config.mjs -w -m inline\" \"servez -p 8280\"",
"build": "rollup -c rollup.config.mjs",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@ffmpeg/libav": "^0.0.1-alpha.0",
"@ffmpeg/libav-core": "^0.0.1-alpha.1",
"@ffmpeg/libav-core-mt": "^0.0.1-alpha.1",
"@types/ffmpeg__libav-core": "^0.0.0",
"yuv-buffer": "^1.0.0",
"yuv-canvas": "^1.2.11"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"concurrently": "^7.6.0",
"rollup": "^3.12.1",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-esbuild": "^5.0.0",
"rollup-plugin-node-externals": "^5.1.2",
"servez": "^1.14.1"
}
}
36 changes: 36 additions & 0 deletions apps/web/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import esbuild from 'rollup-plugin-esbuild';
import externals from 'rollup-plugin-node-externals'
import copy from 'rollup-plugin-copy'

const plugins = [
nodeResolve(),
commonjs(),
esbuild({
target: 'es2017',
minify: false,
define: {
},
}),
];

export default [
{
input: 'src/index.js',
output: {
file: 'dist/index.js',
format: 'esm',
},
plugins,
external:['path','fs','ws']
},
{
input: 'src/index.js',
output: {
file: 'dist/index.iife.js',
format: 'iife',
},
plugins,
}
];
Loading