]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/ffmpeg/ffmpeg-images.ts
Fix unregister default value
[github/Chocobozzz/PeerTube.git] / server / helpers / ffmpeg / ffmpeg-images.ts
1 import ffmpeg from 'fluent-ffmpeg'
2 import { FFMPEG_NICE } from '@server/initializers/constants'
3 import { runCommand } from './ffmpeg-commons'
4
5 function convertWebPToJPG (path: string, destination: string): Promise<void> {
6 const command = ffmpeg(path, { niceness: FFMPEG_NICE.THUMBNAIL })
7 .output(destination)
8
9 return runCommand({ command, silent: true })
10 }
11
12 function processGIF (
13 path: string,
14 destination: string,
15 newSize: { width: number, height: number }
16 ): Promise<void> {
17 const command = ffmpeg(path, { niceness: FFMPEG_NICE.THUMBNAIL })
18 .fps(20)
19 .size(`${newSize.width}x${newSize.height}`)
20 .output(destination)
21
22 return runCommand({ command })
23 }
24
25 async function generateThumbnailFromVideo (fromPath: string, folder: string, imageName: string) {
26 const pendingImageName = 'pending-' + imageName
27
28 const options = {
29 filename: pendingImageName,
30 count: 1,
31 folder
32 }
33
34 return new Promise<string>((res, rej) => {
35 ffmpeg(fromPath, { niceness: FFMPEG_NICE.THUMBNAIL })
36 .on('error', rej)
37 .on('end', () => res(imageName))
38 .thumbnail(options)
39 })
40 }
41
42 export {
43 convertWebPToJPG,
44 processGIF,
45 generateThumbnailFromVideo
46 }