aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/ffmpeg/ffmpeg-images.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-31 14:34:36 +0200
committerChocobozzz <me@florianbigard.com>2023-08-11 15:02:33 +0200
commit3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch)
treee4510b39bdac9c318fdb4b47018d08f15368b8f0 /shared/ffmpeg/ffmpeg-images.ts
parent04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff)
downloadPeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst
PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge conflicts, but it's a major step forward: * Server can be faster at startup because imports() are async and we can easily lazy import big modules * Angular doesn't seem to support ES import (with .js extension), so we had to correctly organize peertube into a monorepo: * Use yarn workspace feature * Use typescript reference projects for dependencies * Shared projects have been moved into "packages", each one is now a node module (with a dedicated package.json/tsconfig.json) * server/tools have been moved into apps/ and is now a dedicated app bundled and published on NPM so users don't have to build peertube cli tools manually * server/tests have been moved into packages/ so we don't compile them every time we want to run the server * Use isolatedModule option: * Had to move from const enum to const (https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) * Had to explictely specify "type" imports when used in decorators * Prefer tsx (that uses esbuild under the hood) instead of ts-node to load typescript files (tests with mocha or scripts): * To reduce test complexity as esbuild doesn't support decorator metadata, we only test server files that do not import server models * We still build tests files into js files for a faster CI * Remove unmaintained peertube CLI import script * Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'shared/ffmpeg/ffmpeg-images.ts')
-rw-r--r--shared/ffmpeg/ffmpeg-images.ts92
1 files changed, 0 insertions, 92 deletions
diff --git a/shared/ffmpeg/ffmpeg-images.ts b/shared/ffmpeg/ffmpeg-images.ts
deleted file mode 100644
index 618fac7d1..000000000
--- a/shared/ffmpeg/ffmpeg-images.ts
+++ /dev/null
@@ -1,92 +0,0 @@
1import { FFmpegCommandWrapper, FFmpegCommandWrapperOptions } from './ffmpeg-command-wrapper'
2import { getVideoStreamDuration } from './ffprobe'
3
4export class FFmpegImage {
5 private readonly commandWrapper: FFmpegCommandWrapper
6
7 constructor (options: FFmpegCommandWrapperOptions) {
8 this.commandWrapper = new FFmpegCommandWrapper(options)
9 }
10
11 convertWebPToJPG (options: {
12 path: string
13 destination: string
14 }): Promise<void> {
15 const { path, destination } = options
16
17 this.commandWrapper.buildCommand(path)
18 .output(destination)
19
20 return this.commandWrapper.runCommand({ silent: true })
21 }
22
23 processGIF (options: {
24 path: string
25 destination: string
26 newSize: { width: number, height: number }
27 }): Promise<void> {
28 const { path, destination, newSize } = options
29
30 this.commandWrapper.buildCommand(path)
31 .fps(20)
32 .size(`${newSize.width}x${newSize.height}`)
33 .output(destination)
34
35 return this.commandWrapper.runCommand()
36 }
37
38 async generateThumbnailFromVideo (options: {
39 fromPath: string
40 output: string
41 }) {
42 const { fromPath, output } = options
43
44 let duration = await getVideoStreamDuration(fromPath)
45 if (isNaN(duration)) duration = 0
46
47 this.commandWrapper.buildCommand(fromPath)
48 .seekInput(duration / 2)
49 .videoFilter('thumbnail=500')
50 .outputOption('-frames:v 1')
51 .output(output)
52
53 return this.commandWrapper.runCommand()
54 }
55
56 async generateStoryboardFromVideo (options: {
57 path: string
58 destination: string
59
60 sprites: {
61 size: {
62 width: number
63 height: number
64 }
65
66 count: {
67 width: number
68 height: number
69 }
70
71 duration: number
72 }
73 }) {
74 const { path, destination, sprites } = options
75
76 const command = this.commandWrapper.buildCommand(path)
77
78 const filter = [
79 `setpts=N/round(FRAME_RATE)/TB`,
80 `select='not(mod(t,${options.sprites.duration}))'`,
81 `scale=${sprites.size.width}:${sprites.size.height}`,
82 `tile=layout=${sprites.count.width}x${sprites.count.height}`
83 ].join(',')
84
85 command.outputOption('-filter_complex', filter)
86 command.outputOption('-frames:v', '1')
87 command.outputOption('-q:v', '2')
88 command.output(destination)
89
90 return this.commandWrapper.runCommand()
91 }
92}