From 266707202c2ffcb8a1b7649ec29106dd444f4a77 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 27 Feb 2018 11:29:24 +0100 Subject: Keep ratio for thumbnails --- server/helpers/ffmpeg-utils.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'server/helpers') diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index ad6f2f867..57911bc73 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -1,6 +1,8 @@ import * as ffmpeg from 'fluent-ffmpeg' import { VideoResolution } from '../../shared/models/videos' import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers' +import { processImage } from './image-utils' +import { join } from 'path' async function getVideoFileHeight (path: string) { const videoStream = await getVideoFileStream(path) @@ -34,23 +36,25 @@ function getDurationFromVideoFile (path: string) { }) } -function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: string) { +async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) { + const pendingImageName = 'pending-' + imageName + const options = { - filename: imageName, + filename: pendingImageName, count: 1, folder } - if (size !== undefined) { - options['size'] = size - } - - return new Promise((res, rej) => { + await new Promise((res, rej) => { ffmpeg(fromPath) .on('error', rej) .on('end', () => res(imageName)) .thumbnail(options) }) + + const pendingImagePath = join(folder, pendingImageName) + const destination = join(folder, imageName) + await processImage({ path: pendingImagePath }, destination, size) } type TranscodeOptions = { -- cgit v1.2.3