diff options
author | Chocobozzz <me@florianbigard.com> | 2023-06-02 15:52:55 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-06-29 10:16:57 +0200 |
commit | b7f946892bcd63d5e01e50df3a40c56d3cb7577b (patch) | |
tree | 5a8dac769cbd043ec448036596b74ae0db408d28 /shared/ffmpeg | |
parent | 318aa9c42250c38c845f007a83ee84a0884436c1 (diff) | |
download | PeerTube-b7f946892bcd63d5e01e50df3a40c56d3cb7577b.tar.gz PeerTube-b7f946892bcd63d5e01e50df3a40c56d3cb7577b.tar.zst PeerTube-b7f946892bcd63d5e01e50df3a40c56d3cb7577b.zip |
Simpler thumbnail generation
Diffstat (limited to 'shared/ffmpeg')
-rw-r--r-- | shared/ffmpeg/ffmpeg-images.ts | 26 |
1 files changed, 11 insertions, 15 deletions
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: { |