diff options
Diffstat (limited to 'server/lib/job-queue/handlers/video-studio-edition.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-studio-edition.ts | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/server/lib/job-queue/handlers/video-studio-edition.ts b/server/lib/job-queue/handlers/video-studio-edition.ts index 3e208d83d..991d11ef1 100644 --- a/server/lib/job-queue/handlers/video-studio-edition.ts +++ b/server/lib/job-queue/handlers/video-studio-edition.ts | |||
@@ -1,15 +1,16 @@ | |||
1 | import { Job } from 'bullmq' | 1 | import { Job } from 'bullmq' |
2 | import { move, remove } from 'fs-extra' | 2 | import { move, remove } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { addIntroOutro, addWatermark, cutVideo } from '@server/helpers/ffmpeg' | 4 | import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg' |
5 | import { createTorrentAndSetInfoHashFromPath } from '@server/helpers/webtorrent' | 5 | import { createTorrentAndSetInfoHashFromPath } from '@server/helpers/webtorrent' |
6 | import { CONFIG } from '@server/initializers/config' | 6 | import { CONFIG } from '@server/initializers/config' |
7 | import { VIDEO_FILTERS } from '@server/initializers/constants' | ||
7 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' | 8 | import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' |
8 | import { generateWebTorrentVideoFilename } from '@server/lib/paths' | 9 | import { generateWebTorrentVideoFilename } from '@server/lib/paths' |
10 | import { createOptimizeOrMergeAudioJobs } from '@server/lib/transcoding/create-transcoding-job' | ||
9 | import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles' | 11 | import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles' |
10 | import { isAbleToUploadVideo } from '@server/lib/user' | 12 | import { isAbleToUploadVideo } from '@server/lib/user' |
11 | import { buildOptimizeOrMergeAudioJob } from '@server/lib/video' | 13 | import { buildFileMetadata, removeHLSPlaylist, removeWebTorrentFile } from '@server/lib/video-file' |
12 | import { removeHLSPlaylist, removeWebTorrentFile } from '@server/lib/video-file' | ||
13 | import { VideoPathManager } from '@server/lib/video-path-manager' | 14 | import { VideoPathManager } from '@server/lib/video-path-manager' |
14 | import { approximateIntroOutroAdditionalSize } from '@server/lib/video-studio' | 15 | import { approximateIntroOutroAdditionalSize } from '@server/lib/video-studio' |
15 | import { UserModel } from '@server/models/user/user' | 16 | import { UserModel } from '@server/models/user/user' |
@@ -17,15 +18,8 @@ import { VideoModel } from '@server/models/video/video' | |||
17 | import { VideoFileModel } from '@server/models/video/video-file' | 18 | import { VideoFileModel } from '@server/models/video/video-file' |
18 | import { MVideo, MVideoFile, MVideoFullLight, MVideoId, MVideoWithAllFiles } from '@server/types/models' | 19 | import { MVideo, MVideoFile, MVideoFullLight, MVideoId, MVideoWithAllFiles } from '@server/types/models' |
19 | import { getLowercaseExtension, pick } from '@shared/core-utils' | 20 | import { getLowercaseExtension, pick } from '@shared/core-utils' |
20 | import { | 21 | import { buildUUID, getFileSize } from '@shared/extra-utils' |
21 | buildFileMetadata, | 22 | import { FFmpegEdition, ffprobePromise, getVideoStreamDimensionsInfo, getVideoStreamDuration, getVideoStreamFPS } from '@shared/ffmpeg' |
22 | buildUUID, | ||
23 | ffprobePromise, | ||
24 | getFileSize, | ||
25 | getVideoStreamDimensionsInfo, | ||
26 | getVideoStreamDuration, | ||
27 | getVideoStreamFPS | ||
28 | } from '@shared/extra-utils' | ||
29 | import { | 23 | import { |
30 | VideoStudioEditionPayload, | 24 | VideoStudioEditionPayload, |
31 | VideoStudioTask, | 25 | VideoStudioTask, |
@@ -36,7 +30,6 @@ import { | |||
36 | VideoStudioTaskWatermarkPayload | 30 | VideoStudioTaskWatermarkPayload |
37 | } from '@shared/models' | 31 | } from '@shared/models' |
38 | import { logger, loggerTagsFactory } from '../../../helpers/logger' | 32 | import { logger, loggerTagsFactory } from '../../../helpers/logger' |
39 | import { JobQueue } from '../job-queue' | ||
40 | 33 | ||
41 | const lTagsBase = loggerTagsFactory('video-edition') | 34 | const lTagsBase = loggerTagsFactory('video-edition') |
42 | 35 | ||
@@ -102,9 +95,7 @@ async function processVideoStudioEdition (job: Job) { | |||
102 | 95 | ||
103 | const user = await UserModel.loadByVideoId(video.id) | 96 | const user = await UserModel.loadByVideoId(video.id) |
104 | 97 | ||
105 | await JobQueue.Instance.createJob( | 98 | await createOptimizeOrMergeAudioJobs({ video, videoFile: newFile, isNewVideo: false, user }) |
106 | await buildOptimizeOrMergeAudioJob({ video, videoFile: newFile, user, isNewVideo: false }) | ||
107 | ) | ||
108 | } | 99 | } |
109 | 100 | ||
110 | // --------------------------------------------------------------------------- | 101 | // --------------------------------------------------------------------------- |
@@ -131,9 +122,9 @@ const taskProcessors: { [id in VideoStudioTask['name']]: (options: TaskProcessor | |||
131 | } | 122 | } |
132 | 123 | ||
133 | async function processTask (options: TaskProcessorOptions) { | 124 | async function processTask (options: TaskProcessorOptions) { |
134 | const { video, task } = options | 125 | const { video, task, lTags } = options |
135 | 126 | ||
136 | logger.info('Processing %s task for video %s.', task.name, video.uuid, { task, ...options.lTags }) | 127 | logger.info('Processing %s task for video %s.', task.name, video.uuid, { task, ...lTags }) |
137 | 128 | ||
138 | const processor = taskProcessors[options.task.name] | 129 | const processor = taskProcessors[options.task.name] |
139 | if (!process) throw new Error('Unknown task ' + task.name) | 130 | if (!process) throw new Error('Unknown task ' + task.name) |
@@ -142,48 +133,53 @@ async function processTask (options: TaskProcessorOptions) { | |||
142 | } | 133 | } |
143 | 134 | ||
144 | function processAddIntroOutro (options: TaskProcessorOptions<VideoStudioTaskIntroPayload | VideoStudioTaskOutroPayload>) { | 135 | function processAddIntroOutro (options: TaskProcessorOptions<VideoStudioTaskIntroPayload | VideoStudioTaskOutroPayload>) { |
145 | const { task } = options | 136 | const { task, lTags } = options |
137 | |||
138 | logger.debug('Will add intro/outro to the video.', { options, ...lTags }) | ||
146 | 139 | ||
147 | return addIntroOutro({ | 140 | return buildFFmpegEdition().addIntroOutro({ |
148 | ...pick(options, [ 'inputPath', 'outputPath' ]), | 141 | ...pick(options, [ 'inputPath', 'outputPath' ]), |
149 | 142 | ||
150 | introOutroPath: task.options.file, | 143 | introOutroPath: task.options.file, |
151 | type: task.name === 'add-intro' | 144 | type: task.name === 'add-intro' |
152 | ? 'intro' | 145 | ? 'intro' |
153 | : 'outro', | 146 | : 'outro' |
154 | |||
155 | availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(), | ||
156 | profile: CONFIG.TRANSCODING.PROFILE | ||
157 | }) | 147 | }) |
158 | } | 148 | } |
159 | 149 | ||
160 | function processCut (options: TaskProcessorOptions<VideoStudioTaskCutPayload>) { | 150 | function processCut (options: TaskProcessorOptions<VideoStudioTaskCutPayload>) { |
161 | const { task } = options | 151 | const { task, lTags } = options |
162 | 152 | ||
163 | return cutVideo({ | 153 | logger.debug('Will cut the video.', { options, ...lTags }) |
154 | |||
155 | return buildFFmpegEdition().cutVideo({ | ||
164 | ...pick(options, [ 'inputPath', 'outputPath' ]), | 156 | ...pick(options, [ 'inputPath', 'outputPath' ]), |
165 | 157 | ||
166 | start: task.options.start, | 158 | start: task.options.start, |
167 | end: task.options.end, | 159 | end: task.options.end |
168 | |||
169 | availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(), | ||
170 | profile: CONFIG.TRANSCODING.PROFILE | ||
171 | }) | 160 | }) |
172 | } | 161 | } |
173 | 162 | ||
174 | function processAddWatermark (options: TaskProcessorOptions<VideoStudioTaskWatermarkPayload>) { | 163 | function processAddWatermark (options: TaskProcessorOptions<VideoStudioTaskWatermarkPayload>) { |
175 | const { task } = options | 164 | const { task, lTags } = options |
165 | |||
166 | logger.debug('Will add watermark to the video.', { options, ...lTags }) | ||
176 | 167 | ||
177 | return addWatermark({ | 168 | return buildFFmpegEdition().addWatermark({ |
178 | ...pick(options, [ 'inputPath', 'outputPath' ]), | 169 | ...pick(options, [ 'inputPath', 'outputPath' ]), |
179 | 170 | ||
180 | watermarkPath: task.options.file, | 171 | watermarkPath: task.options.file, |
181 | 172 | ||
182 | availableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(), | 173 | videoFilters: { |
183 | profile: CONFIG.TRANSCODING.PROFILE | 174 | watermarkSizeRatio: VIDEO_FILTERS.WATERMARK.SIZE_RATIO, |
175 | horitonzalMarginRatio: VIDEO_FILTERS.WATERMARK.HORIZONTAL_MARGIN_RATIO, | ||
176 | verticalMarginRatio: VIDEO_FILTERS.WATERMARK.VERTICAL_MARGIN_RATIO | ||
177 | } | ||
184 | }) | 178 | }) |
185 | } | 179 | } |
186 | 180 | ||
181 | // --------------------------------------------------------------------------- | ||
182 | |||
187 | async function buildNewFile (video: MVideoId, path: string) { | 183 | async function buildNewFile (video: MVideoId, path: string) { |
188 | const videoFile = new VideoFileModel({ | 184 | const videoFile = new VideoFileModel({ |
189 | extname: getLowercaseExtension(path), | 185 | extname: getLowercaseExtension(path), |
@@ -223,3 +219,7 @@ async function checkUserQuotaOrThrow (video: MVideoFullLight, payload: VideoStud | |||
223 | throw new Error('Quota exceeded for this user to edit the video') | 219 | throw new Error('Quota exceeded for this user to edit the video') |
224 | } | 220 | } |
225 | } | 221 | } |
222 | |||
223 | function buildFFmpegEdition () { | ||
224 | return new FFmpegEdition(getFFmpegCommandWrapperOptions('vod', VideoTranscodingProfilesManager.Instance.getAvailableEncoders())) | ||
225 | } | ||