diff options
author | Chocobozzz <me@florianbigard.com> | 2022-02-11 10:51:33 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-02-28 10:42:19 +0100 |
commit | c729caf6cc34630877a0e5a1bda1719384cd0c8a (patch) | |
tree | 1d2e13722e518c73d2c9e6f0969615e29d51cf8c /server/lib/video-editor.ts | |
parent | a24bf4dc659cebb65d887862bf21d7a35e9ec791 (diff) | |
download | PeerTube-c729caf6cc34630877a0e5a1bda1719384cd0c8a.tar.gz PeerTube-c729caf6cc34630877a0e5a1bda1719384cd0c8a.tar.zst PeerTube-c729caf6cc34630877a0e5a1bda1719384cd0c8a.zip |
Add basic video editor support
Diffstat (limited to 'server/lib/video-editor.ts')
-rw-r--r-- | server/lib/video-editor.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/server/lib/video-editor.ts b/server/lib/video-editor.ts new file mode 100644 index 000000000..99b0bd949 --- /dev/null +++ b/server/lib/video-editor.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import { MVideoFullLight } from "@server/types/models" | ||
2 | import { getVideoStreamDuration } from "@shared/extra-utils" | ||
3 | import { VideoEditorTask } from "@shared/models" | ||
4 | |||
5 | function buildTaskFileFieldname (indice: number, fieldName = 'file') { | ||
6 | return `tasks[${indice}][options][${fieldName}]` | ||
7 | } | ||
8 | |||
9 | function getTaskFile (files: Express.Multer.File[], indice: number, fieldName = 'file') { | ||
10 | return files.find(f => f.fieldname === buildTaskFileFieldname(indice, fieldName)) | ||
11 | } | ||
12 | |||
13 | async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, tasks: VideoEditorTask[], fileFinder: (i: number) => string) { | ||
14 | let additionalDuration = 0 | ||
15 | |||
16 | for (let i = 0; i < tasks.length; i++) { | ||
17 | const task = tasks[i] | ||
18 | |||
19 | if (task.name !== 'add-intro' && task.name !== 'add-outro') continue | ||
20 | |||
21 | const filePath = fileFinder(i) | ||
22 | additionalDuration += await getVideoStreamDuration(filePath) | ||
23 | } | ||
24 | |||
25 | return (video.getMaxQualityFile().size / video.duration) * additionalDuration | ||
26 | } | ||
27 | |||
28 | export { | ||
29 | approximateIntroOutroAdditionalSize, | ||
30 | buildTaskFileFieldname, | ||
31 | getTaskFile | ||
32 | } | ||