diff options
Diffstat (limited to 'shared/ffmpeg/ffmpeg-images.ts')
-rw-r--r-- | shared/ffmpeg/ffmpeg-images.ts | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/shared/ffmpeg/ffmpeg-images.ts b/shared/ffmpeg/ffmpeg-images.ts new file mode 100644 index 000000000..2db63bd8b --- /dev/null +++ b/shared/ffmpeg/ffmpeg-images.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper' | ||
2 | |||
3 | export class FFmpegImage { | ||
4 | private readonly commandWrapper: FFmpegCommandWrapper | ||
5 | |||
6 | constructor (options: FFmpegCommandWrapperOptions) { | ||
7 | this.commandWrapper = new FFmpegCommandWrapper(options) | ||
8 | } | ||
9 | |||
10 | convertWebPToJPG (options: { | ||
11 | path: string | ||
12 | destination: string | ||
13 | }): Promise<void> { | ||
14 | const { path, destination } = options | ||
15 | |||
16 | this.commandWrapper.buildCommand(path) | ||
17 | .output(destination) | ||
18 | |||
19 | return this.commandWrapper.runCommand({ silent: true }) | ||
20 | } | ||
21 | |||
22 | processGIF (options: { | ||
23 | path: string | ||
24 | destination: string | ||
25 | newSize: { width: number, height: number } | ||
26 | }): Promise<void> { | ||
27 | const { path, destination, newSize } = options | ||
28 | |||
29 | this.commandWrapper.buildCommand(path) | ||
30 | .fps(20) | ||
31 | .size(`${newSize.width}x${newSize.height}`) | ||
32 | .output(destination) | ||
33 | |||
34 | return this.commandWrapper.runCommand() | ||
35 | } | ||
36 | |||
37 | async generateThumbnailFromVideo (options: { | ||
38 | fromPath: string | ||
39 | folder: string | ||
40 | imageName: string | ||
41 | }) { | ||
42 | const { fromPath, folder, imageName } = options | ||
43 | |||
44 | const pendingImageName = 'pending-' + imageName | ||
45 | |||
46 | const thumbnailOptions = { | ||
47 | filename: pendingImageName, | ||
48 | count: 1, | ||
49 | folder | ||
50 | } | ||
51 | |||
52 | return new Promise<string>((res, rej) => { | ||
53 | this.commandWrapper.buildCommand(fromPath) | ||
54 | .on('error', rej) | ||
55 | .on('end', () => res(imageName)) | ||
56 | .thumbnail(thumbnailOptions) | ||
57 | }) | ||
58 | } | ||
59 | } | ||