]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/ffmpeg/ffmpeg-images.ts
Translated using Weblate (Esperanto)
[github/Chocobozzz/PeerTube.git] / shared / ffmpeg / ffmpeg-images.ts
CommitLineData
0c9668f7
C
1import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper'
2
3export 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}