Commit 58470441 authored by Jerome Wu's avatar Jerome Wu

Refactor tests

parent acd70a80
Subproject commit 96cca2e2666bd1a82c9bc46b95e50e195f438c23
Subproject commit ef325bd0249c65d10614e87bff335c79cc3cea44
const fs = require('fs');
const path = require('path');
const { TIMEOUT } = require('./config');
const { runFFmpeg } = require('./utils');
const aviFilePath = path.join(__dirname, 'data', 'video-1s.avi');
const IN_FILE_NAME = 'video-1s.avi';
const OUT_FILE_NAME = 'video.webm';
const WEBM_SIZE = 41904;
const WEBM_SIZE_MT = 41878;
let aviData = null;
let BASELINE_TIME = 0;
beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('transcode avi to vp9 webm', async () => {
const args = ['-i', IN_FILE_NAME, OUT_FILE_NAME];
const start = Date.now();
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME);
BASELINE_TIME = Date.now() - start;
expect(fileSize).toBe(WEBM_SIZE);
}, TIMEOUT);
test('transcode avi to vp9 webm with multithread', async () => {
const args = ['-i', IN_FILE_NAME, '-row-mt', '1', OUT_FILE_NAME];
const start = Date.now();
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME);
const timediff = Date.now() - start;
expect(fileSize).toBe(WEBM_SIZE_MT);
expect(timediff < BASELINE_TIME).toBe(true);
}, TIMEOUT);
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 MP4_SIZE = 38372;
let aviData = null;
beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('should transcode to mp4 twice', async () => {
for (let i = 0 ; i < 2; i++) {
const args = ['-i', IN_FILE_NAME, OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME);
expect(fileSize).toBe(MP4_SIZE);
}
}, TIMEOUT);
const fs = require('fs');
const path = require('path');
const { TIMEOUT } = require('./config');
const { runFFmpeg } = require('./utils');
const aviFilePath = path.join(__dirname, 'data', 'video-1s.avi');
const WEBM_SIZE = 41878;
let aviData = null;
beforeAll(async () => {
aviData = Uint8Array.from(fs.readFileSync(aviFilePath));
});
test('transcode avi to webm', async () => {
const Core = await runFFmpeg('video.avi', aviData, ['-i', 'video.avi', '-row-mt', '1', 'video.webm']);
const fileSize = Core.FS.readFile('video.webm').length;
Core.FS.unlink('video.webm');
expect(fileSize).toBe(WEBM_SIZE);
}, TIMEOUT);
test('transcode avi to webm twice', async () => {
for (let i = 0 ; i < 2; i++) {
const Core = await runFFmpeg('video.avi', aviData, ['-i', 'video.avi', '-row-mt', '1', 'video.webm']);
const fileSize = Core.FS.readFile('video.webm').length;
Core.FS.unlink('video.webm');
expect(fileSize).toBe(WEBM_SIZE);
}
}, TIMEOUT);
......@@ -19,8 +19,9 @@ const ffmpeg = (Core, args) => {
);
};
const runFFmpeg = async (filename, data, args) => {
const runFFmpeg = async (ifilename, data, args, ofilename) => {
let resolve = null;
let fileSize = -1;
const Core = await createFFmpegCore({
printErr: () => {},
print: (m) => {
......@@ -29,10 +30,14 @@ const runFFmpeg = async (filename, data, args) => {
}
},
});
Core.FS.writeFile(filename, data);
Core.FS.writeFile(ifilename, data);
ffmpeg(Core, args);
await new Promise((_resolve) => { resolve = _resolve });
return Core;
if (typeof ofilename !== 'undefined') {
fileSize = Core.FS.readFile(ofilename).length;
Core.FS.unlink(ofilename);
}
return { Core, fileSize };
};
module.exports = {
......
const fs = require('fs');
const path = require('path');
const { TIMEOUT } = require('./config');
const { runFFmpeg } = require('./utils');
const IN_FILE_NAME = 'audio-1s.wav';
const OUT_FILE_NAME = 'audio.wv';
const WV_24BIT_SIZE = 23502;
let wavData = null;
beforeAll(() => {
wavData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('convert wav to wv', async () => {
const args = ['-i', IN_FILE_NAME, OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, wavData, args, OUT_FILE_NAME);
expect(fileSize).toBe(WV_24BIT_SIZE);
}, TIMEOUT);
......@@ -2,26 +2,17 @@ const fs = require('fs');
const path = require('path');
const { TIMEOUT } = require('./config');
const { runFFmpeg } = require('./utils');
const aviFilePath = path.join(__dirname, 'data', 'video-1s.avi');
const IN_FILE_NAME = 'video-1s.avi';
const OUT_FILE_NAME = 'video.mp4';
const MP4_SIZE = 38372;
let aviData = null;
beforeAll(async () => {
aviData = Uint8Array.from(fs.readFileSync(aviFilePath));
beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('transcode avi to x264 mp4', async () => {
const Core = await runFFmpeg('video.avi', aviData, ['-i', 'video.avi', 'video.mp4']);
const fileSize = Core.FS.readFile('video.mp4').length;
Core.FS.unlink('video.mp4');
const args = ['-i', IN_FILE_NAME, OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME);
expect(fileSize).toBe(MP4_SIZE);
}, TIMEOUT);
test('transcode avi to x264 mp4 twice', async () => {
for (let i = 0 ; i < 2; i++) {
const Core = await runFFmpeg('video.avi', aviData, ['-i', 'video.avi', 'video.mp4']);
const fileSize = Core.FS.readFile('video.mp4').length;
Core.FS.unlink('video.mp4');
expect(fileSize).toBe(MP4_SIZE);
}
}, TIMEOUT);
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