From c729caf6cc34630877a0e5a1bda1719384cd0c8a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 11 Feb 2022 10:51:33 +0100 Subject: Add basic video editor support --- server/lib/video-editor.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 server/lib/video-editor.ts (limited to 'server/lib/video-editor.ts') 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 @@ +import { MVideoFullLight } from "@server/types/models" +import { getVideoStreamDuration } from "@shared/extra-utils" +import { VideoEditorTask } from "@shared/models" + +function buildTaskFileFieldname (indice: number, fieldName = 'file') { + return `tasks[${indice}][options][${fieldName}]` +} + +function getTaskFile (files: Express.Multer.File[], indice: number, fieldName = 'file') { + return files.find(f => f.fieldname === buildTaskFileFieldname(indice, fieldName)) +} + +async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, tasks: VideoEditorTask[], fileFinder: (i: number) => string) { + let additionalDuration = 0 + + for (let i = 0; i < tasks.length; i++) { + const task = tasks[i] + + if (task.name !== 'add-intro' && task.name !== 'add-outro') continue + + const filePath = fileFinder(i) + additionalDuration += await getVideoStreamDuration(filePath) + } + + return (video.getMaxQualityFile().size / video.duration) * additionalDuration +} + +export { + approximateIntroOutroAdditionalSize, + buildTaskFileFieldname, + getTaskFile +} -- cgit v1.2.3