Commit d712e15d authored by Jerome Wu's avatar Jerome Wu

Upgrade to emscripten v2.0.24

parent 09ebfee7
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
set -euo pipefail set -euo pipefail
EM_VERSION=2.0.8 EM_VERSION=2.0.24
docker pull emscripten/emsdk:$EM_VERSION docker pull emscripten/emsdk:$EM_VERSION
docker run \ docker run \
......
...@@ -5,7 +5,6 @@ source $(dirname $0)/var.sh ...@@ -5,7 +5,6 @@ source $(dirname $0)/var.sh
if [[ "$FFMPEG_ST" != "yes" ]]; then if [[ "$FFMPEG_ST" != "yes" ]]; then
mkdir -p wasm/packages/core/dist mkdir -p wasm/packages/core/dist
EXPORTED_FUNCTIONS="[_main, _proxy_main]"
EXTRA_FLAGS=( EXTRA_FLAGS=(
-pthread -pthread
-s USE_PTHREADS=1 # enable pthreads support -s USE_PTHREADS=1 # enable pthreads support
...@@ -14,7 +13,6 @@ if [[ "$FFMPEG_ST" != "yes" ]]; then ...@@ -14,7 +13,6 @@ if [[ "$FFMPEG_ST" != "yes" ]]; then
) )
else else
mkdir -p wasm/packages/core-st/dist mkdir -p wasm/packages/core-st/dist
EXPORTED_FUNCTIONS="[_main]"
EXTRA_FLAGS=( EXTRA_FLAGS=(
-o wasm/packages/core-st/dist/ffmpeg-core.js -o wasm/packages/core-st/dist/ffmpeg-core.js
) )
...@@ -30,11 +28,11 @@ FLAGS=( ...@@ -30,11 +28,11 @@ FLAGS=(
-s EXIT_RUNTIME=1 # exit runtime after execution -s EXIT_RUNTIME=1 # exit runtime after execution
-s MODULARIZE=1 # use modularized version to be more flexible -s MODULARIZE=1 # use modularized version to be more flexible
-s EXPORT_NAME="createFFmpegCore" # assign export name for browser -s EXPORT_NAME="createFFmpegCore" # assign export name for browser
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" # export main and proxy_main funcs -s EXPORTED_FUNCTIONS="[_main]" # export main and proxy_main funcs
-s EXTRA_EXPORTED_RUNTIME_METHODS="[FS, cwrap, ccall, setValue, writeAsciiToMemory]" # export preamble 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 -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 --pre-js wasm/src/pre.js
--post-js wasm/src/post.js
$OPTIM_FLAGS $OPTIM_FLAGS
${EXTRA_FLAGS[@]} ${EXTRA_FLAGS[@]}
) )
......
...@@ -7,3 +7,11 @@ Module['quit'] = function(status) { ...@@ -7,3 +7,11 @@ Module['quit'] = function(status) {
if (Module["onExit"]) Module["onExit"](status); if (Module["onExit"]) Module["onExit"](status);
throw new ExitStatus(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'); ...@@ -3,10 +3,8 @@ const { CASES, TIMEOUT } = require('./config');
require('events').EventEmitter.defaultMaxListeners = 64; require('events').EventEmitter.defaultMaxListeners = 64;
[ module.exports = (mode) => {
{ mode: 'mt', ...require('./utils')('mt') }, const { getCore, ffmpeg } = require('./utils')(mode);
{ mode: 'st', ...require('./utils')('st') },
].forEach(({ mode, getCore, ffmpeg }) => {
CASES.forEach(({ CASES.forEach(({
name, name,
args, args,
...@@ -38,5 +36,4 @@ require('events').EventEmitter.defaultMaxListeners = 64; ...@@ -38,5 +36,4 @@ require('events').EventEmitter.defaultMaxListeners = 64;
} catch(e) {} } catch(e) {}
}, TIMEOUT); }, TIMEOUT);
}); });
}) };
require('./transcode-base')('mt');
require('./transcode-base')('st');
...@@ -5,6 +5,8 @@ if (process.argv.length > 2) { ...@@ -5,6 +5,8 @@ if (process.argv.length > 2) {
mode = process.argv[2]; mode = process.argv[2];
} }
require('events').EventEmitter.defaultMaxListeners = 64;
const { getCore, ffmpeg } = require('./utils')(mode); const { getCore, ffmpeg } = require('./utils')(mode);
(async () => { (async () => {
......
const parseArgs = require('../parseArgs'); const parseArgs = require('../parseArgs');
let resolve = null; let resolve = null;
const ffmpeg = ({ core, args }) => { const ffmpeg = ({ core, args }) => new Promise((_resolve) => {
try {
core.ccall( core.ccall(
'proxy_main', // use emscripten_proxy_main if emscripten upgraded 'emscripten_proxy_main', // use emscripten_proxy_main if emscripten upgraded
'number', 'number',
['number', 'number'], ['number', 'number'],
parseArgs(core, ['ffmpeg', '-hide_banner', '-nostdin', ...args]), parseArgs(core, ['ffmpeg', '-hide_banner', '-nostdin', ...args]),
); );
} catch(e) { resolve = _resolve;
// TODO: only ignore certain exceptions
} });
return new Promise((_resolve) => { resolve = _resolve; });
};
const getCore = () => ( const getCore = () => (
require('../../../packages/core/dist/ffmpeg-core')({ 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