aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/job-queue/handlers/video-studio-edition.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/job-queue/handlers/video-studio-edition.ts')
-rw-r--r--server/lib/job-queue/handlers/video-studio-edition.ts68
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 @@
1import { Job } from 'bullmq' 1import { Job } from 'bullmq'
2import { move, remove } from 'fs-extra' 2import { move, remove } from 'fs-extra'
3import { join } from 'path' 3import { join } from 'path'
4import { addIntroOutro, addWatermark, cutVideo } from '@server/helpers/ffmpeg' 4import { getFFmpegCommandWrapperOptions } from '@server/helpers/ffmpeg'
5import { createTorrentAndSetInfoHashFromPath } from '@server/helpers/webtorrent' 5import { createTorrentAndSetInfoHashFromPath } from '@server/helpers/webtorrent'
6import { CONFIG } from '@server/initializers/config' 6import { CONFIG } from '@server/initializers/config'
7import { VIDEO_FILTERS } from '@server/initializers/constants'
7import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' 8import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
8import { generateWebTorrentVideoFilename } from '@server/lib/paths' 9import { generateWebTorrentVideoFilename } from '@server/lib/paths'
10import { createOptimizeOrMergeAudioJobs } from '@server/lib/transcoding/create-transcoding-job'
9import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles' 11import { VideoTranscodingProfilesManager } from '@server/lib/transcoding/default-transcoding-profiles'
10import { isAbleToUploadVideo } from '@server/lib/user' 12import { isAbleToUploadVideo } from '@server/lib/user'
11import { buildOptimizeOrMergeAudioJob } from '@server/lib/video' 13import { buildFileMetadata, removeHLSPlaylist, removeWebTorrentFile } from '@server/lib/video-file'
12import { removeHLSPlaylist, removeWebTorrentFile } from '@server/lib/video-file'
13import { VideoPathManager } from '@server/lib/video-path-manager' 14import { VideoPathManager } from '@server/lib/video-path-manager'
14import { approximateIntroOutroAdditionalSize } from '@server/lib/video-studio' 15import { approximateIntroOutroAdditionalSize } from '@server/lib/video-studio'
15import { UserModel } from '@server/models/user/user' 16import { UserModel } from '@server/models/user/user'
@@ -17,15 +18,8 @@ import { VideoModel } from '@server/models/video/video'
17import { VideoFileModel } from '@server/models/video/video-file' 18import { VideoFileModel } from '@server/models/video/video-file'
18import { MVideo, MVideoFile, MVideoFullLight, MVideoId, MVideoWithAllFiles } from '@server/types/models' 19import { MVideo, MVideoFile, MVideoFullLight, MVideoId, MVideoWithAllFiles } from '@server/types/models'
19import { getLowercaseExtension, pick } from '@shared/core-utils' 20import { getLowercaseExtension, pick } from '@shared/core-utils'
20import { 21import { buildUUID, getFileSize } from '@shared/extra-utils'
21 buildFileMetadata, 22import { 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'
29import { 23import {
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'
38import { logger, loggerTagsFactory } from '../../../helpers/logger' 32import { logger, loggerTagsFactory } from '../../../helpers/logger'
39import { JobQueue } from '../job-queue'
40 33
41const lTagsBase = loggerTagsFactory('video-edition') 34const 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
133async function processTask (options: TaskProcessorOptions) { 124async 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
144function processAddIntroOutro (options: TaskProcessorOptions<VideoStudioTaskIntroPayload | VideoStudioTaskOutroPayload>) { 135function 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
160function processCut (options: TaskProcessorOptions<VideoStudioTaskCutPayload>) { 150function 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
174function processAddWatermark (options: TaskProcessorOptions<VideoStudioTaskWatermarkPayload>) { 163function 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
187async function buildNewFile (video: MVideoId, path: string) { 183async 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
223function buildFFmpegEdition () {
224 return new FFmpegEdition(getFFmpegCommandWrapperOptions('vod', VideoTranscodingProfilesManager.Instance.getAvailableEncoders()))
225}