aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/ffmpeg-utils.ts
diff options
context:
space:
mode:
authorKimsible <1877318+kimsible@users.noreply.github.com>2020-11-25 09:26:31 +0100
committerGitHub <noreply@github.com>2020-11-25 09:26:31 +0100
commit123f61933611f326ea5a5e8c2ea253ee8720e4f0 (patch)
tree49ff0e98eaffc389f33fb57bd1b42735fe78bce8 /server/helpers/ffmpeg-utils.ts
parentc07fac202dba3fed69aace74157589c21d732be6 (diff)
downloadPeerTube-123f61933611f326ea5a5e8c2ea253ee8720e4f0.tar.gz
PeerTube-123f61933611f326ea5a5e8c2ea253ee8720e4f0.tar.zst
PeerTube-123f61933611f326ea5a5e8c2ea253ee8720e4f0.zip
Add pixel size to tooltip and gif support with FFmpeg for avatar upload (#3329)
* Add avatar pixel size upload in tooltip * Add gif support for avatar * Add ffmpeg GIF process Co-authored-by: kimsible <kimsible@users.noreply.github.com>
Diffstat (limited to 'server/helpers/ffmpeg-utils.ts')
-rw-r--r--server/helpers/ffmpeg-utils.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index c8d6969ff..66b9d2e44 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -355,6 +355,40 @@ function convertWebPToJPG (path: string, destination: string): Promise<void> {
355 }) 355 })
356} 356}
357 357
358function processGIF (
359 path: string,
360 destination: string,
361 newSize: { width: number, height: number },
362 keepOriginal = false
363): Promise<void> {
364 return new Promise<void>(async (res, rej) => {
365 if (path === destination) {
366 throw new Error('FFmpeg needs an input path different that the output path.')
367 }
368
369 logger.debug('Processing gif %s to %s.', path, destination)
370
371 try {
372 const command = ffmpeg(path)
373 .fps(20)
374 .size(`${newSize.width}x${newSize.height}`)
375 .output(destination)
376
377 command.on('error', (err, stdout, stderr) => {
378 logger.error('Error in ffmpeg gif resizing process.', { stdout, stderr })
379 return rej(err)
380 })
381 .on('end', async () => {
382 if (keepOriginal !== true) await remove(path)
383 res()
384 })
385 .run()
386 } catch (err) {
387 return rej(err)
388 }
389 })
390}
391
358function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: number[], fps, deleteSegments: boolean) { 392function runLiveTranscoding (rtmpUrl: string, outPath: string, resolutions: number[], fps, deleteSegments: boolean) {
359 const command = getFFmpeg(rtmpUrl) 393 const command = getFFmpeg(rtmpUrl)
360 command.inputOption('-fflags nobuffer') 394 command.inputOption('-fflags nobuffer')
@@ -474,6 +508,7 @@ export {
474 getAudioStreamCodec, 508 getAudioStreamCodec,
475 runLiveMuxing, 509 runLiveMuxing,
476 convertWebPToJPG, 510 convertWebPToJPG,
511 processGIF,
477 getVideoStreamSize, 512 getVideoStreamSize,
478 getVideoFileResolution, 513 getVideoFileResolution,
479 getMetadataFromFile, 514 getMetadataFromFile,