diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 14:55:10 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch) | |
tree | 226d3dd1565b0bb56588897af3b8530e6216e96b /shared/ffmpeg/ffmpeg-images.ts | |
parent | 6bcb854cdea8688a32240bc5719c7d139806e00b (diff) | |
download | PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.gz PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.zst PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.zip |
Implement remote runner jobs in server
Move ffmpeg functions to @shared
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 | } | ||