Commit d712e15d authored by Jerome Wu's avatar Jerome Wu

Upgrade to emscripten v2.0.24

parent 09ebfee7
......@@ -2,7 +2,7 @@
set -euo pipefail
EM_VERSION=2.0.8
EM_VERSION=2.0.24
docker pull emscripten/emsdk:$EM_VERSION
docker run \
......
......@@ -5,7 +5,6 @@ source $(dirname $0)/var.sh
if [[ "$FFMPEG_ST" != "yes" ]]; then
mkdir -p wasm/packages/core/dist
EXPORTED_FUNCTIONS="[_main, _proxy_main]"
EXTRA_FLAGS=(
-pthread
-s USE_PTHREADS=1 # enable pthreads support
......@@ -14,7 +13,6 @@ if [[ "$FFMPEG_ST" != "yes" ]]; then
)
else
mkdir -p wasm/packages/core-st/dist
EXPORTED_FUNCTIONS="[_main]"
EXTRA_FLAGS=(
-o wasm/packages/core-st/dist/ffmpeg-core.js
)
......@@ -30,11 +28,11 @@ FLAGS=(
-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 EXPORTED_FUNCTIONS="[_main]" # export main and proxy_main funcs
-s EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, setValue, writeAsciiToMemory]" # export preamble funcs
-s INITIAL_MEMORY=2146435072 # 64 KB * 1024 * 16 * 2047 = 2146435072 bytes ~= 2 GB
--post-js wasm/src/post.js
--pre-js wasm/src/pre.js
--post-js wasm/src/post.js
$OPTIM_FLAGS
${EXTRA_FLAGS[@]}
)
......
......@@ -7,3 +7,11 @@ Module['quit'] = function(status) {
if (Module["onExit"]) Module["onExit"](status);
throw new ExitStatus(status);
}
Module['exit'] = exit;
/**
* Disable all console output, might need to enable it
* for debugging
*/
out = err = function() {}
const fs = require('fs');
const path = require('path');
const { TIMEOUT } = require('./config');
const { runFFmpeg } = require('./utils');
const IN_FILE_NAME = 'video-1s.avi';
const OUT_FILE_NAME = 'video.mp4';
const FILE_SIZE = 38372;
let aviData = null;
beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('transcode avi to x264 mp4 with exit', async () => {
const processExit = process.exit;
global.process.exit = jest.fn();
const args = ['-i', IN_FILE_NAME, OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME, [], [], 1000);
expect(fileSize).not.toBe(FILE_SIZE);
global.process.exit = processExit;
}, TIMEOUT);
const fs = require('fs');
const path = require('path');
const createFFmpegCore = require('../packages/core/dist/ffmpeg-core');
const { TIMEOUT } = require('./config');
const { runFFmpeg, ffmpeg } = require('./utils');
const IN_FILE_NAME = 'video-1s.avi';
const OUT_FILE_NAME = 'video.mp4';
const MP4_SIZE = 38372;
let aviData = null;
let resolve = null;
let Core = null;
beforeAll(async () => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
Core = await createFFmpegCore({
printErr: (m) => {
},
print: (m) => {
if (m.startsWith('FFMPEG_END')) {
resolve();
}
}
});
}, TIMEOUT);
test('should transcode to mp4 twice', async () => {
const args = ['-i', IN_FILE_NAME, OUT_FILE_NAME];
Core.FS.writeFile(IN_FILE_NAME, aviData);
for (let i = 0; i < 2; i++) {
ffmpeg(Core, args);
await new Promise((_resolve) => { resolve = _resolve });
expect(Core.FS.readFile(OUT_FILE_NAME).length).toBe(MP4_SIZE);
Core.FS.unlink(OUT_FILE_NAME);
}
}, TIMEOUT);
......@@ -3,10 +3,8 @@ const { CASES, TIMEOUT } = require('./config');
require('events').EventEmitter.defaultMaxListeners = 64;
[
{ mode: 'mt', ...require('./utils')('mt') },
{ mode: 'st', ...require('./utils')('st') },
].forEach(({ mode, getCore, ffmpeg }) => {
module.exports = (mode) => {
const { getCore, ffmpeg } = require('./utils')(mode);
CASES.forEach(({
name,
args,
......@@ -38,5 +36,4 @@ require('events').EventEmitter.defaultMaxListeners = 64;
} catch(e) {}
}, TIMEOUT);
});
})
};
require('./transcode-base')('mt');
require('./transcode-base')('st');
......@@ -5,6 +5,8 @@ if (process.argv.length > 2) {
mode = process.argv[2];
}
require('events').EventEmitter.defaultMaxListeners = 64;
const { getCore, ffmpeg } = require('./utils')(mode);
(async () => {
......
const parseArgs = require('../parseArgs');
let resolve = null;
const ffmpeg = ({ core, args }) => {
try {
const ffmpeg = ({ core, args }) => new Promise((_resolve) => {
core.ccall(
'proxy_main', // use emscripten_proxy_main if emscripten upgraded
'emscripten_proxy_main', // use emscripten_proxy_main if emscripten upgraded
'number',
['number', 'number'],
parseArgs(core, ['ffmpeg', '-hide_banner', '-nostdin', ...args]),
);
} catch(e) {
// TODO: only ignore certain exceptions
}
return new Promise((_resolve) => { resolve = _resolve; });
};
resolve = _resolve;
});
const getCore = () => (
require('../../../packages/core/dist/ffmpeg-core')({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment