PeerTube/server/lib/video-studio.ts

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-03-22 10:58:49 -05:00
import { MVideoFullLight } from '@server/types/models'
import { getVideoStreamDuration } from '@shared/extra-utils'
import { VideoStudioTask } from '@shared/models'
2022-02-11 03:51:33 -06:00
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))
}
2022-03-22 10:58:49 -05:00
async function approximateIntroOutroAdditionalSize (video: MVideoFullLight, tasks: VideoStudioTask[], fileFinder: (i: number) => string) {
2022-02-11 03:51:33 -06:00
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
}