X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fjob-queue%2Fhandlers%2Fvideo-studio-edition.ts;h=fbb55a388631f3cb8041049f442f08154ebfb791;hb=3a0c2a77b1a6626699514ddaf8135f4397175443;hp=434d0ffe821d1e9430c7020b102ac6488dca12e4;hpb=4fae2b1f300c1f027629569817262f60873a663a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/job-queue/handlers/video-studio-edition.ts b/server/lib/job-queue/handlers/video-studio-edition.ts index 434d0ffe8..fbb55a388 100644 --- a/server/lib/job-queue/handlers/video-studio-edition.ts +++ b/server/lib/job-queue/handlers/video-studio-edition.ts @@ -1,14 +1,16 @@ -import { Job } from 'bull' +import { Job } from 'bullmq' import { move, remove } from 'fs-extra' import { join } from 'path' -import { addIntroOutro, addWatermark, cutVideo } from '@server/helpers/ffmpeg' +import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg' import { createTorrentAndSetInfoHashFromPath } from '@server/helpers/webtorrent' import { CONFIG } from '@server/initializers/config' +import { VIDEO_FILTERS } from '@server/initializers/constants' import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' import { generateWebTorrentVideoFilename } from '@server/lib/paths' +import { createOptimizeOrMergeAudioJobs } from '@server/lib/transcoding/create-transcoding-job' import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles' import { isAbleToUploadVideo } from '@server/lib/user' -import { addOptimizeOrMergeAudioJob } from '@server/lib/video' +import { buildFileMetadata, removeHLSPlaylist, removeWebTorrentFile } from '@server/lib/video-file' import { VideoPathManager } from '@server/lib/video-path-manager' import { approximateIntroOutroAdditionalSize } from '@server/lib/video-studio' import { UserModel } from '@server/models/user/user' @@ -16,23 +18,16 @@ import { VideoModel } from '@server/models/video/video' import { VideoFileModel } from '@server/models/video/video-file' import { MVideo, MVideoFile, MVideoFullLight, MVideoId, MVideoWithAllFiles } from '@server/types/models' import { getLowercaseExtension, pick } from '@shared/core-utils' -import { - buildFileMetadata, - buildUUID, - ffprobePromise, - getFileSize, - getVideoStreamDimensionsInfo, - getVideoStreamDuration, - getVideoStreamFPS -} from '@shared/extra-utils' +import { buildUUID, getFileSize } from '@shared/extra-utils' +import { FFmpegEdition, ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamDuration, getVideoStreamFPS } from '@shared/ffmpeg' import { VideoStudioEditionPayload, - VideoStudioTaskPayload, + VideoStudioTask, VideoStudioTaskCutPayload, VideoStudioTaskIntroPayload, VideoStudioTaskOutroPayload, - VideoStudioTaskWatermarkPayload, - VideoStudioTask + VideoStudioTaskPayload, + VideoStudioTaskWatermarkPayload } from '@shared/models' import { logger, loggerTagsFactory } from '../../../helpers/logger' @@ -42,7 +37,7 @@ async function processVideoStudioEdition (job: Job) { const payload = job.data as VideoStudioEditionPayload const lTags = lTagsBase(payload.videoUUID) - logger.info('Process video studio edition of %s in job %d.', payload.videoUUID, job.id, lTags) + logger.info('Process video studio edition of %s in job %s.', payload.videoUUID, job.id, lTags) const video = await VideoModel.loadFull(payload.videoUUID) @@ -89,7 +84,6 @@ async function processVideoStudioEdition (job: Job) { await move(editionResultPath, outputPath) await createTorrentAndSetInfoHashFromPath(video, newFile, outputPath) - await removeAllFiles(video, newFile) await newFile.save() @@ -100,7 +94,8 @@ async function processVideoStudioEdition (job: Job) { await federateVideoIfNeeded(video, false, undefined) const user = await UserModel.loadByVideoId(video.id) - await addOptimizeOrMergeAudioJob({ video, videoFile: newFile, user, isNewVideo: false }) + + await createOptimizeOrMergeAudioJobs({ video, videoFile: newFile, isNewVideo: false, user, videoFileAlreadyLocked: false }) } // --------------------------------------------------------------------------- @@ -127,9 +122,9 @@ const taskProcessors: { [id in VideoStudioTask['name']]: (options: TaskProcessor } async function processTask (options: TaskProcessorOptions) { - const { video, task } = options + const { video, task, lTags } = options - logger.info('Processing %s task for video %s.', task.name, video.uuid, { task, ...options.lTags }) + logger.info('Processing %s task for video %s.', task.name, video.uuid, { task, ...lTags }) const processor = taskProcessors[options.task.name] if (!process) throw new Error('Unknown task ' + task.name) @@ -138,25 +133,26 @@ async function processTask (options: TaskProcessorOptions) { } function processAddIntroOutro (options: TaskProcessorOptions) { - const { task } = options + const { task, lTags } = options + + logger.debug('Will add intro/outro to the video.', { options, ...lTags }) - return addIntroOutro({ + return buildFFmpegEdition().addIntroOutro({ ...pick(options, [ 'inputPath', 'outputPath' ]), introOutroPath: task.options.file, type: task.name === 'add-intro' ? 'intro' - : 'outro', - - availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(), - profile: CONFIG.TRANSCODING.PROFILE + : 'outro' }) } function processCut (options: TaskProcessorOptions) { - const { task } = options + const { task, lTags } = options + + logger.debug('Will cut the video.', { options, ...lTags }) - return cutVideo({ + return buildFFmpegEdition().cutVideo({ ...pick(options, [ 'inputPath', 'outputPath' ]), start: task.options.start, @@ -165,18 +161,25 @@ function processCut (options: TaskProcessorOptions) { } function processAddWatermark (options: TaskProcessorOptions) { - const { task } = options + const { task, lTags } = options - return addWatermark({ + logger.debug('Will add watermark to the video.', { options, ...lTags }) + + return buildFFmpegEdition().addWatermark({ ...pick(options, [ 'inputPath', 'outputPath' ]), watermarkPath: task.options.file, - availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(), - profile: CONFIG.TRANSCODING.PROFILE + videoFilters: { + watermarkSizeRatio: VIDEO_FILTERS.WATERMARK.SIZE_RATIO, + horitonzalMarginRatio: VIDEO_FILTERS.WATERMARK.HORIZONTAL_MARGIN_RATIO, + verticalMarginRatio: VIDEO_FILTERS.WATERMARK.VERTICAL_MARGIN_RATIO + } }) } +// --------------------------------------------------------------------------- + async function buildNewFile (video: MVideoId, path: string) { const videoFile = new VideoFileModel({ extname: getLowercaseExtension(path), @@ -197,18 +200,12 @@ async function buildNewFile (video: MVideoId, path: string) { } async function removeAllFiles (video: MVideoWithAllFiles, webTorrentFileException: MVideoFile) { - const hls = video.getHLSPlaylist() - - if (hls) { - await video.removeStreamingPlaylistFiles(hls) - await hls.destroy() - } + await removeHLSPlaylist(video) for (const file of video.VideoFiles) { if (file.id === webTorrentFileException.id) continue - await video.removeWebTorrentFileAndTorrent(file) - await file.destroy() + await removeWebTorrentFile(video, file.id) } } @@ -222,3 +219,7 @@ async function checkUserQuotaOrThrow (video: MVideoFullLight, payload: VideoStud throw new Error('Quota exceeded for this user to edit the video') } } + +function buildFFmpegEdition () { + return new FFmpegEdition(getFFmpegCommandWrapperOptions('vod', VideoTranscodingProfilesManager.Instance.getAvailableEncoders())) +}