diff options
Diffstat (limited to 'server/helpers/ffmpeg-utils.ts')
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 18 |
1 files changed, 11 insertions, 7 deletions
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 @@ | |||
1 | import * as ffmpeg from 'fluent-ffmpeg' | 1 | import * as ffmpeg from 'fluent-ffmpeg' |
2 | import { VideoResolution } from '../../shared/models/videos' | 2 | import { VideoResolution } from '../../shared/models/videos' |
3 | import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers' | 3 | import { CONFIG, MAX_VIDEO_TRANSCODING_FPS } from '../initializers' |
4 | import { processImage } from './image-utils' | ||
5 | import { join } from 'path' | ||
4 | 6 | ||
5 | async function getVideoFileHeight (path: string) { | 7 | async function getVideoFileHeight (path: string) { |
6 | const videoStream = await getVideoFileStream(path) | 8 | const videoStream = await getVideoFileStream(path) |
@@ -34,23 +36,25 @@ function getDurationFromVideoFile (path: string) { | |||
34 | }) | 36 | }) |
35 | } | 37 | } |
36 | 38 | ||
37 | function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: string) { | 39 | async function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: { width: number, height: number }) { |
40 | const pendingImageName = 'pending-' + imageName | ||
41 | |||
38 | const options = { | 42 | const options = { |
39 | filename: imageName, | 43 | filename: pendingImageName, |
40 | count: 1, | 44 | count: 1, |
41 | folder | 45 | folder |
42 | } | 46 | } |
43 | 47 | ||
44 | if (size !== undefined) { | 48 | await new Promise<string>((res, rej) => { |
45 | options['size'] = size | ||
46 | } | ||
47 | |||
48 | return new Promise<string>((res, rej) => { | ||
49 | ffmpeg(fromPath) | 49 | ffmpeg(fromPath) |
50 | .on('error', rej) | 50 | .on('error', rej) |
51 | .on('end', () => res(imageName)) | 51 | .on('end', () => res(imageName)) |
52 | .thumbnail(options) | 52 | .thumbnail(options) |
53 | }) | 53 | }) |
54 | |||
55 | const pendingImagePath = join(folder, pendingImageName) | ||
56 | const destination = join(folder, imageName) | ||
57 | await processImage({ path: pendingImagePath }, destination, size) | ||
54 | } | 58 | } |
55 | 59 | ||
56 | type TranscodeOptions = { | 60 | type TranscodeOptions = { |