From b7f946892bcd63d5e01e50df3a40c56d3cb7577b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 2 Jun 2023 15:52:55 +0200 Subject: Simpler thumbnail generation --- shared/ffmpeg/ffmpeg-images.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'shared/ffmpeg') diff --git a/shared/ffmpeg/ffmpeg-images.ts b/shared/ffmpeg/ffmpeg-images.ts index 27305382c..618fac7d1 100644 --- a/shared/ffmpeg/ffmpeg-images.ts +++ b/shared/ffmpeg/ffmpeg-images.ts @@ -1,4 +1,5 @@ import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper' +import { getVideoStreamDuration } from './ffprobe' export class FFmpegImage { private readonly commandWrapper: FFmpegCommandWrapper @@ -36,25 +37,20 @@ export class FFmpegImage { async generateThumbnailFromVideo (options: { fromPath: string - folder: string - imageName: string + output: string }) { - const { fromPath, folder, imageName } = options + const { fromPath, output } = options - const pendingImageName = 'pending-' + imageName + let duration = await getVideoStreamDuration(fromPath) + if (isNaN(duration)) duration = 0 - const thumbnailOptions = { - filename: pendingImageName, - count: 1, - folder - } + this.commandWrapper.buildCommand(fromPath) + .seekInput(duration / 2) + .videoFilter('thumbnail=500') + .outputOption('-frames:v 1') + .output(output) - return new Promise((res, rej) => { - this.commandWrapper.buildCommand(fromPath) - .on('error', rej) - .on('end', () => res(imageName)) - .thumbnail(thumbnailOptions) - }) + return this.commandWrapper.runCommand() } async generateStoryboardFromVideo (options: { -- cgit v1.2.3