diff options
-rw-r--r-- | server/helpers/image-utils.ts | 2 | ||||
-rw-r--r-- | shared/ffmpeg/ffmpeg-images.ts | 26 |
2 files changed, 12 insertions, 16 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index f86f7216d..7b77e694a 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts | |||
@@ -51,7 +51,7 @@ async function generateImageFromVideoFile (options: { | |||
51 | const pendingImagePath = join(folder, pendingImageName) | 51 | const pendingImagePath = join(folder, pendingImageName) |
52 | 52 | ||
53 | try { | 53 | try { |
54 | await generateThumbnailFromVideo({ fromPath, folder, imageName }) | 54 | await generateThumbnailFromVideo({ fromPath, output: pendingImagePath }) |
55 | 55 | ||
56 | const destination = join(folder, imageName) | 56 | const destination = join(folder, imageName) |
57 | await processImage({ path: pendingImagePath, destination, newSize: size }) | 57 | await processImage({ path: pendingImagePath, destination, newSize: size }) |
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 @@ | |||
1 | import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper' | 1 | import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper' |
2 | import { getVideoStreamDuration } from './ffprobe' | ||
2 | 3 | ||
3 | export class FFmpegImage { | 4 | export class FFmpegImage { |
4 | private readonly commandWrapper: FFmpegCommandWrapper | 5 | private readonly commandWrapper: FFmpegCommandWrapper |
@@ -36,25 +37,20 @@ export class FFmpegImage { | |||
36 | 37 | ||
37 | async generateThumbnailFromVideo (options: { | 38 | async generateThumbnailFromVideo (options: { |
38 | fromPath: string | 39 | fromPath: string |
39 | folder: string | 40 | output: string |
40 | imageName: string | ||
41 | }) { | 41 | }) { |
42 | const { fromPath, folder, imageName } = options | 42 | const { fromPath, output } = options |
43 | 43 | ||
44 | const pendingImageName = 'pending-' + imageName | 44 | let duration = await getVideoStreamDuration(fromPath) |
45 | if (isNaN(duration)) duration = 0 | ||
45 | 46 | ||
46 | const thumbnailOptions = { | 47 | this.commandWrapper.buildCommand(fromPath) |
47 | filename: pendingImageName, | 48 | .seekInput(duration / 2) |
48 | count: 1, | 49 | .videoFilter('thumbnail=500') |
49 | folder | 50 | .outputOption('-frames:v 1') |
50 | } | 51 | .output(output) |
51 | 52 | ||
52 | return new Promise<string>((res, rej) => { | 53 | return this.commandWrapper.runCommand() |
53 | this.commandWrapper.buildCommand(fromPath) | ||
54 | .on('error', rej) | ||
55 | .on('end', () => res(imageName)) | ||
56 | .thumbnail(thumbnailOptions) | ||
57 | }) | ||
58 | } | 54 | } |
59 | 55 | ||
60 | async generateStoryboardFromVideo (options: { | 56 | async generateStoryboardFromVideo (options: { |