From f619de0e435f7ac3abad2ec772397486358b56e7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 25 Nov 2020 09:50:12 +0100 Subject: Add tests to gif resizer --- server/helpers/ffmpeg-utils.ts | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'server/helpers/ffmpeg-utils.ts') diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 69defccc4..9755dd67c 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -64,35 +64,14 @@ function convertWebPToJPG (path: string, destination: string): Promise { function processGIF ( path: string, destination: string, - newSize: { width: number, height: number }, - keepOriginal = false + newSize: { width: number, height: number } ): Promise { - return new Promise(async (res, rej) => { - if (path === destination) { - throw new Error('FFmpeg needs an input path different that the output path.') - } - - logger.debug('Processing gif %s to %s.', path, destination) + const command = ffmpeg(path) + .fps(20) + .size(`${newSize.width}x${newSize.height}`) + .output(destination) - try { - const command = ffmpeg(path) - .fps(20) - .size(`${newSize.width}x${newSize.height}`) - .output(destination) - - command.on('error', (err, stdout, stderr) => { - logger.error('Error in ffmpeg gif resizing process.', { stdout, stderr }) - return rej(err) - }) - .on('end', async () => { - if (keepOriginal !== true) await remove(path) - res() - }) - .run() - } catch (err) { - return rej(err) - } - }) + return runCommand(command) } async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) { -- cgit v1.2.3