aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/ffmpeg-utils.ts33
-rw-r--r--server/helpers/image-utils.ts34
2 files changed, 26 insertions, 41 deletions
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<void> {
64function processGIF ( 64function processGIF (
65 path: string, 65 path: string,
66 destination: string, 66 destination: string,
67 newSize: { width: number, height: number }, 67 newSize: { width: number, height: number }
68 keepOriginal = false
69): Promise<void> { 68): Promise<void> {
70 return new Promise<void>(async (res, rej) => { 69 const command = ffmpeg(path)
71 if (path === destination) { 70 .fps(20)
72 throw new Error('FFmpeg needs an input path different that the output path.') 71 .size(`${newSize.width}x${newSize.height}`)
73 } 72 .output(destination)
74
75 logger.debug('Processing gif %s to %s.', path, destination)
76 73
77 try { 74 return runCommand(command)
78 const command = ffmpeg(path)
79 .fps(20)
80 .size(`${newSize.width}x${newSize.height}`)
81 .output(destination)
82
83 command.on('error', (err, stdout, stderr) => {
84 logger.error('Error in ffmpeg gif resizing process.', { stdout, stderr })
85 return rej(err)
86 })
87 .on('end', async () => {
88 if (keepOriginal !== true) await remove(path)
89 res()
90 })
91 .run()
92 } catch (err) {
93 return rej(err)
94 }
95 })
96} 75}
97 76
98async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) { 77async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) {
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts
index fdf06e848..3ebf07305 100644
--- a/server/helpers/image-utils.ts
+++ b/server/helpers/image-utils.ts
@@ -1,5 +1,5 @@
1import { extname } from 'path'
2import { remove, rename } from 'fs-extra' 1import { remove, rename } from 'fs-extra'
2import { extname } from 'path'
3import { convertWebPToJPG, processGIF } from './ffmpeg-utils' 3import { convertWebPToJPG, processGIF } from './ffmpeg-utils'
4import { logger } from './logger' 4import { logger } from './logger'
5 5
@@ -13,17 +13,31 @@ async function processImage (
13) { 13) {
14 const extension = extname(path) 14 const extension = extname(path)
15 15
16 if (path === destination) {
17 throw new Error('Jimp/FFmpeg needs an input path different that the output path.')
18 }
19
20 logger.debug('Processing image %s to %s.', path, destination)
21
16 // Use FFmpeg to process GIF 22 // Use FFmpeg to process GIF
17 if (extension === '.gif') { 23 if (extension === '.gif') {
18 return processGIF(path, destination, newSize, keepOriginal) 24 await processGIF(path, destination, newSize)
25 } else {
26 await jimpProcessor(path, destination, newSize)
19 } 27 }
20 28
21 if (path === destination) { 29 if (keepOriginal !== true) await remove(path)
22 throw new Error('Jimp needs an input path different that the output path.') 30}
23 }
24 31
25 logger.debug('Processing image %s to %s.', path, destination) 32// ---------------------------------------------------------------------------
26 33
34export {
35 processImage
36}
37
38// ---------------------------------------------------------------------------
39
40async function jimpProcessor (path: string, destination: string, newSize: { width: number, height: number }) {
27 let jimpInstance: any 41 let jimpInstance: any
28 42
29 try { 43 try {
@@ -44,12 +58,4 @@ async function processImage (
44 .resize(newSize.width, newSize.height) 58 .resize(newSize.width, newSize.height)
45 .quality(80) 59 .quality(80)
46 .writeAsync(destination) 60 .writeAsync(destination)
47
48 if (keepOriginal !== true) await remove(path)
49}
50
51// ---------------------------------------------------------------------------
52
53export {
54 processImage
55} 61}