Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Merged
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
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ run-all() {
#build-aom # disabled as it is extremely slow
configure-ffmpeg
build-ffmpeg
configure-ffmpeg.mp4-scale
build-ffmpeg.mp4-scale
configure-ffmpeg.png-to-mp4
build-ffmpeg.png-to-mp4
)
run ${SCRIPTS[@]}
}
Expand Down
30 changes: 23 additions & 7 deletions wasm/build-scripts/build-ffmpeg.mp4-scale.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,42 @@
set -eo pipefail
source $(dirname $0)/var.sh

mkdir -p wasm/dist
emmake make -j
if [[ "$FFMPEG_ST" != "yes" ]]; then
mkdir -p wasm/packages/core.mp4-scale/dist
EXPORTED_FUNCTIONS="[_main, _proxy_main]"
EXTRA_FLAGS=(
-pthread
-s USE_PTHREADS=1 # enable pthreads support
-s PROXY_TO_PTHREAD=1 # detach main() from browser/UI main thread
-o wasm/packages/core.mp4-scale/dist/ffmpeg-core.js
)
else
mkdir -p wasm/packages/core-st.mp4-scale/dist
EXPORTED_FUNCTIONS="[_main]"
EXTRA_FLAGS=(
-o wasm/packages/core-st.mp4-scale/dist/ffmpeg-core.js
)
fi

FLAGS=(
-I. -I./fftools -I$BUILD_DIR/include
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib
-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
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lpostproc -lm -lx264
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
-s INVOKE_RUN=0 # not to run the main() in the beginning
-s EXIT_RUNTIME=1 # exit runtime after execution
-s MODULARIZE=1 # use modularized version to be more flexible
-s EXPORT_NAME="createFFmpegCore" # assign export name for browser
-s EXPORTED_FUNCTIONS="[_main, _proxy_main]" # export main and proxy_main funcs
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" # 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
--post-js wasm/src/post.js
--pre-js wasm/src/pre.js
$OPTIM_FLAGS
${EXTRA_FLAGS[@]}
)
echo "FFMPEG_EM_FLAGS=${FLAGS[@]}"
emmake make -j
emcc "${FLAGS[@]}"
44 changes: 44 additions & 0 deletions wasm/build-scripts/build-ffmpeg.png-to-mp4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -eo pipefail
source $(dirname $0)/var.sh

if [[ "$FFMPEG_ST" != "yes" ]]; then
mkdir -p wasm/packages/core.png-to-mp4/dist
EXPORTED_FUNCTIONS="[_main, _proxy_main]"
EXTRA_FLAGS=(
-pthread
-s USE_PTHREADS=1 # enable pthreads support
-s PROXY_TO_PTHREAD=1 # detach main() from browser/UI main thread
-o wasm/packages/core.png-to-mp4/dist/ffmpeg-core.js
)
else
mkdir -p wasm/packages/core-st.png-to-mp4/dist
EXPORTED_FUNCTIONS="[_main]"
EXTRA_FLAGS=(
-o wasm/packages/core-st.png-to-mp4/dist/ffmpeg-core.js
)
fi

FLAGS=(
-I. -I./fftools -I$BUILD_DIR/include
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L$BUILD_DIR/lib
-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 -lz
fftools/ffmpeg_opt.c fftools/ffmpeg_filter.c fftools/ffmpeg_hw.c fftools/cmdutils.c fftools/ffmpeg.c
-s USE_SDL=2 # use SDL2
-s INVOKE_RUN=0 # not to run the main() in the beginning
-s EXIT_RUNTIME=1 # exit runtime after execution
-s MODULARIZE=1 # use modularized version to be more flexible
-s EXPORT_NAME="createFFmpegCore" # assign export name for browser
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" # 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
--post-js wasm/src/post.js
--pre-js wasm/src/pre.js
$OPTIM_FLAGS
${EXTRA_FLAGS[@]}
)
echo "FFMPEG_EM_FLAGS=${FLAGS[@]}"
emmake make -j
emcc "${FLAGS[@]}"
27 changes: 27 additions & 0 deletions wasm/build-scripts/configure-ffmpeg.png-to-mp4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -euo pipefail
source $(dirname $0)/var.sh

FLAGS=(
"${FFMPEG_CONFIG_FLAGS_BASE[@]}"
--disable-all
--enable-gpl # required by x264
--enable-libx264 # enable x264
--enable-zlib # enable zlib
--enable-avcodec
--enable-avformat
--enable-avfilter
--enable-swresample
--enable-swscale
--enable-decoder=png
--enable-encoder=png,libx264
--enable-parser=h264,png
--enable-protocol=file
--enable-demuxer=image2
--enable-muxer=mp4
--enable-filter=scale,format,null

)
echo "FFMPEG_CONFIG_FLAGS=${FLAGS[@]}"
emconfigure ./configure "${FLAGS[@]}"
2 changes: 1 addition & 1 deletion wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "serve .",
"test": "node --experimental-wasm-threads --experimental-wasm-bulk-memory ./node_modules/.bin/jest"
"test": "node --experimental-wasm-threads --experimental-wasm-bulk-memory ./node_modules/.bin/jest --verbose"
},
"author": "[email protected]",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions wasm/packages/core-st.mp4-scale/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
2 changes: 2 additions & 0 deletions wasm/packages/core-st.png-to-mp4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
2 changes: 2 additions & 0 deletions wasm/packages/core.mp4-scale/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
2 changes: 2 additions & 0 deletions wasm/packages/core.png-to-mp4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
22 changes: 22 additions & 0 deletions wasm/tests/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const fs = require('fs');
const path = require('path');
const base = path.join(__dirname, 'data');
const base2 = path.join(__dirname, 'data2');
const avi = Uint8Array.from(fs.readFileSync(path.join(base, 'video-1s.avi')));
const mp4 = Uint8Array.from(fs.readFileSync(path.join(base2, 'video-1s.mp4')));
const wav = Uint8Array.from(fs.readFileSync(path.join(base, 'audio-1s.wav')));
const arial = Uint8Array.from(fs.readFileSync(path.join(base, 'arial.ttf')));
const png = Uint8Array.from(fs.readFileSync(path.join(base, 'image.png')));
Expand Down Expand Up @@ -229,6 +231,26 @@ const CASES = [
],
st: false,
},
{
name: 'mp4 scale',
args: ['-i', 'video.mp4', '-vf', 'scale=128:-1', 'video-scaled.mp4'],
input: [
{ name: 'video.mp4', data: mp4 },
],
output: [
{ name: 'video-scaled.mp4', type: 'video/mp4' },
]
},
{
name: 'png to mp4',
args: ['-i', 'image.png', 'video.mp4'],
input: [
{ name: 'image.png', data: png },
],
output: [
{ name: 'video.mp4', type: 'video/mp4' },
]
},
];

module.exports = {
Expand Down
Binary file added wasm/tests/data2/video-15s.mp4
Binary file not shown.
Binary file added wasm/tests/data2/video-1s.mp4
Binary file not shown.
Binary file added wasm/tests/data2/video-3s.mp4
Binary file not shown.
7 changes: 4 additions & 3 deletions wasm/tests/transcode-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { CASES, TIMEOUT } = require('./config');

require('events').EventEmitter.defaultMaxListeners = 64;

module.exports = (mode) => {
module.exports = (mode, corename, caseFilter = (name) => true) => {
const { getCore, ffmpeg } = require('./utils')(mode);
CASES.forEach(({
name,
Expand All @@ -14,8 +14,9 @@ module.exports = (mode) => {
st,
}) => {
if (mode === 'st' && st === false) { return; }
test(`[${mode}] ${name}`, async () => {
const core = await getCore();
if (!caseFilter(name)){ return; }
test(`[${mode}][${corename}] ${name}`, async () => {
const core = await getCore(corename);
for (let i = 0; i < dirs.length; i++) {
await core.FS.mkdir(dirs[i]);
}
Expand Down
5 changes: 4 additions & 1 deletion wasm/tests/transcode-mt.test.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
require('./transcode-base')('mt');
const base = require('./transcode-base');
base('mt','core');
base('mt','core.mp4-scale',(name) => name == 'mp4 scale');
base('mt','core.png-to-mp4',(name) => name == 'png to mp4');
5 changes: 4 additions & 1 deletion wasm/tests/transcode-st.test.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
require('./transcode-base')('st');
const base = require('./transcode-base');
base('st','core-st');
base('st','core-st.mp4-scale',(name) => name == 'mp4 scale');
base('st','core-st.png-to-mp4',(name) => name == 'png to mp4');
4 changes: 2 additions & 2 deletions wasm/tests/utils/mt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const ffmpeg = ({ core, args }) => new Promise((_resolve) => {

});

const getCore = () => (
require('../../../packages/core/dist/ffmpeg-core')({
const getCore = (corename) => (
require(`../../../packages/${corename}/dist/ffmpeg-core`)({
printErr: () => {},
print: (m) => {
if (m.startsWith('FFMPEG_END')) {
Expand Down
3 changes: 2 additions & 1 deletion wasm/tests/utils/st/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Worker } = require('worker_threads');
const path = require('path');

const getCore = async () => {
const getCore = async (corename) => {
const resolves = {};
let resolveExit = null;
let _id = 0;
Expand All @@ -21,6 +21,7 @@ const getCore = async () => {
resolveExit();
});

await getHandler({ type: 'LOAD', corename });
await getHandler({ type: 'INIT' });

return {
Expand Down
9 changes: 6 additions & 3 deletions wasm/tests/utils/st/worker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const { parentPort } = require('worker_threads');
const createFFmpegCore = require('../../../packages/core-st/dist/ffmpeg-core');
let createFFmpegCore = null;
const parseArgs = require('../parseArgs');
let core = null;

parentPort.on('message', async ({ id, type, cmd, args }) => {
parentPort.on('message', async ({ id, type, cmd, args, corename }) => {
switch(type) {
case 'LOAD':
createFFmpegCore = require(`../../../packages/${corename}/dist/ffmpeg-core`);
parentPort.postMessage({ id, type: 'LOAD' });
break;
case 'INIT':
core = await createFFmpegCore({
printErr: () => {},
Expand Down