Major refactor to adapt new ffmpeg-core.js

This commit is contained in:
Jerome Wu
2020-04-28 19:35:57 +08:00
parent cd5fe43905
commit b36360f16f
40 changed files with 226 additions and 527 deletions

BIN
tests/assets/StarWars3.wav Normal file

Binary file not shown.

View File

@@ -1,11 +1,9 @@
const TIMEOUT = 30000;
const TIMEOUT = 60000;
const BASE_URL = 'http://localhost:3000/tests/assets';
const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
const OPTIONS = {
corePath: '../node_modules/@ffmpeg/core/ffmpeg-core.js',
...(IS_BROWSER ? { workerPath: '../dist/worker.dev.js' } : {}),
};
const FLAME_MP4_LENGTH = 100374;
if (typeof module !== 'undefined') {
module.exports = {
@@ -13,6 +11,5 @@ if (typeof module !== 'undefined') {
BASE_URL,
IS_BROWSER,
OPTIONS,
FLAME_MP4_LENGTH,
};
}

View File

@@ -1,20 +1,27 @@
const { createWorker } = FFmpeg;
const worker = createWorker(OPTIONS);
const { createFFmpeg } = FFmpeg;
const ffmpeg = createFFmpeg(OPTIONS);
before(async function cb() {
this.timeout(0);
await worker.load();
await ffmpeg.load();
});
describe('transcode()', () => {
describe('should transcode different format', () => {
['flame.avi'].forEach((name) => (
it(`transcode ${name}`, async () => {
await worker.write(name, `${BASE_URL}/${name}`);
await worker.transcode(name, 'output.mp4');
const { data } = await worker.read('output.mp4');
expect(data.length).to.be(FLAME_MP4_LENGTH);
}).timeout(TIMEOUT)
));
[1, 2, 4].forEach((n) => {
[
{ from: 'flame.avi', to: 'flame.mp4' },
{ from: 'flame.avi', to: 'flame.webm' },
{ from: 'StarWars3.wav', to: 'StarWars3.mp3' },
].forEach(({ from, to }) => (
it(`transcode ${from} to ${to} (${n} threads)`, async () => {
await ffmpeg.write(from, `${BASE_URL}/${from}`);
await ffmpeg.transcode(from, to, `-threads ${n}`);
const data = ffmpeg.read(to);
ffmpeg.remove(to);
expect(data.length).not.to.be(0);
}).timeout(TIMEOUT)
));
});
});
});