Commit 67036c79 authored by Jerome Wu's avatar Jerome Wu

Add freetype2 and git tests

parent 0fdf4573
const fs = require('fs');
const path = require('path');
const { TIMEOUT } = require('./config');
const { runFFmpeg, b64ToUint8Array } = require('./utils');
const ARIAL_TTF = require('./data/arial.ttf.js');
const IN_FILE_NAME = 'video-1s.avi';
const OUT_FILE_NAME = 'video.mp4';
const FILE_SIZE = 37243;
let aviData = null;
beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('transcode avi to x264 mp4 with drawtext', async () => {
const args = ['-i', IN_FILE_NAME, '-vf', 'drawtext=fontfile=/arial.ttf:text=\'Artist\':fontcolor=white:fontsize=24:x=(w-text_w)/2:y=(h-text_h)/2', OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME, [{ name: 'arial.ttf', data: b64ToUint8Array(ARIAL_TTF) }]);
expect(fileSize).toBe(FILE_SIZE);
}, 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.gif';
const FILE_SIZE = 181674;
let aviData = null;
beforeAll(() => {
aviData = Uint8Array.from(fs.readFileSync(path.join(__dirname, 'data', IN_FILE_NAME)));
});
test('transcode avi to gif', async () => {
const args = ['-i', IN_FILE_NAME, '-f', 'gif', OUT_FILE_NAME];
const { fileSize } = await runFFmpeg(IN_FILE_NAME, aviData, args, OUT_FILE_NAME);
expect(fileSize).toBe(FILE_SIZE);
}, TIMEOUT);
...@@ -19,7 +19,7 @@ const ffmpeg = (Core, args) => { ...@@ -19,7 +19,7 @@ const ffmpeg = (Core, args) => {
); );
}; };
const runFFmpeg = async (ifilename, data, args, ofilename) => { const runFFmpeg = async (ifilename, data, args, ofilename, extraFiles = []) => {
let resolve = null; let resolve = null;
let file = null; let file = null;
let fileSize = -1; let fileSize = -1;
...@@ -31,6 +31,9 @@ const runFFmpeg = async (ifilename, data, args, ofilename) => { ...@@ -31,6 +31,9 @@ const runFFmpeg = async (ifilename, data, args, ofilename) => {
} }
}, },
}); });
extraFiles.forEach(({ name, data: d }) => {
Core.FS.writeFile(name, d);
});
Core.FS.writeFile(ifilename, data); Core.FS.writeFile(ifilename, data);
ffmpeg(Core, args); ffmpeg(Core, args);
await new Promise((_resolve) => { resolve = _resolve }); await new Promise((_resolve) => { resolve = _resolve });
...@@ -42,7 +45,10 @@ const runFFmpeg = async (ifilename, data, args, ofilename) => { ...@@ -42,7 +45,10 @@ const runFFmpeg = async (ifilename, data, args, ofilename) => {
return { Core, file, fileSize }; return { Core, file, fileSize };
}; };
const b64ToUint8Array = (str) => (Buffer.from(str, 'base64'));
module.exports = { module.exports = {
runFFmpeg, runFFmpeg,
b64ToUint8Array,
ffmpeg, ffmpeg,
}; };
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