diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-22 10:33:33 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-02-22 10:35:37 +0100 |
commit | 70243d7a3575402dee00669da5c0d00a4b27dba4 (patch) | |
tree | 483c7e27e6043655f01247e8e6c99b0951b4e08e /server/lib/job-queue/handlers/video-transcoding.ts | |
parent | 15bedeebd7671bf5177879899404d48942b2d090 (diff) | |
download | PeerTube-70243d7a3575402dee00669da5c0d00a4b27dba4.tar.gz PeerTube-70243d7a3575402dee00669da5c0d00a4b27dba4.tar.zst PeerTube-70243d7a3575402dee00669da5c0d00a4b27dba4.zip |
Correctly wait transcoding before federating
Diffstat (limited to 'server/lib/job-queue/handlers/video-transcoding.ts')
-rw-r--r-- | server/lib/job-queue/handlers/video-transcoding.ts | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index 8573d4d12..4ee2b2df2 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts | |||
@@ -3,6 +3,7 @@ import { TranscodeOptionsType } from '@server/helpers/ffmpeg-utils' | |||
3 | import { JOB_PRIORITY } from '@server/initializers/constants' | 3 | import { JOB_PRIORITY } from '@server/initializers/constants' |
4 | import { getJobTranscodingPriorityMalus, publishAndFederateIfNeeded } from '@server/lib/video' | 4 | import { getJobTranscodingPriorityMalus, publishAndFederateIfNeeded } from '@server/lib/video' |
5 | import { getVideoFilePath } from '@server/lib/video-paths' | 5 | import { getVideoFilePath } from '@server/lib/video-paths' |
6 | import { UserModel } from '@server/models/account/user' | ||
6 | import { MUser, MUserId, MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/types/models' | 7 | import { MUser, MUserId, MVideoFullLight, MVideoUUID, MVideoWithFile } from '@server/types/models' |
7 | import { | 8 | import { |
8 | HLSTranscodingPayload, | 9 | HLSTranscodingPayload, |
@@ -26,7 +27,6 @@ import { | |||
26 | transcodeNewWebTorrentResolution | 27 | transcodeNewWebTorrentResolution |
27 | } from '../../video-transcoding' | 28 | } from '../../video-transcoding' |
28 | import { JobQueue } from '../job-queue' | 29 | import { JobQueue } from '../job-queue' |
29 | import { UserModel } from '@server/models/account/user' | ||
30 | 30 | ||
31 | type HandlerFunction = (job: Bull.Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<any> | 31 | type HandlerFunction = (job: Bull.Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<any> |
32 | 32 | ||
@@ -168,11 +168,11 @@ async function onVideoFileOptimizer ( | |||
168 | copyCodecs: transcodeType !== 'quick-transcode', | 168 | copyCodecs: transcodeType !== 'quick-transcode', |
169 | isMaxQuality: true | 169 | isMaxQuality: true |
170 | }) | 170 | }) |
171 | await createHlsJobIfEnabled(user, originalFileHLSPayload) | 171 | const hasHls = await createHlsJobIfEnabled(user, originalFileHLSPayload) |
172 | 172 | ||
173 | const hasNewResolutions = await createLowerResolutionsJobs(videoDatabase, user, videoFileResolution, isPortraitMode, 'webtorrent') | 173 | const hasNewResolutions = await createLowerResolutionsJobs(videoDatabase, user, videoFileResolution, isPortraitMode, 'webtorrent') |
174 | 174 | ||
175 | if (!hasNewResolutions) { | 175 | if (!hasHls && !hasNewResolutions) { |
176 | // No transcoding to do, it's now published | 176 | // No transcoding to do, it's now published |
177 | videoPublished = await videoDatabase.publishIfNeededAndSave(t) | 177 | videoPublished = await videoDatabase.publishIfNeededAndSave(t) |
178 | } | 178 | } |
@@ -212,7 +212,7 @@ async function createHlsJobIfEnabled (user: MUserId, payload: { | |||
212 | copyCodecs: boolean | 212 | copyCodecs: boolean |
213 | isMaxQuality: boolean | 213 | isMaxQuality: boolean |
214 | }) { | 214 | }) { |
215 | if (!payload || CONFIG.TRANSCODING.HLS.ENABLED !== true) return | 215 | if (!payload || CONFIG.TRANSCODING.HLS.ENABLED !== true) return false |
216 | 216 | ||
217 | const jobOptions = { | 217 | const jobOptions = { |
218 | priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user) | 218 | priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user) |
@@ -227,7 +227,9 @@ async function createHlsJobIfEnabled (user: MUserId, payload: { | |||
227 | isMaxQuality: payload.isMaxQuality | 227 | isMaxQuality: payload.isMaxQuality |
228 | } | 228 | } |
229 | 229 | ||
230 | return JobQueue.Instance.createJobWithPromise({ type: 'video-transcoding', payload: hlsTranscodingPayload }, jobOptions) | 230 | JobQueue.Instance.createJob({ type: 'video-transcoding', payload: hlsTranscodingPayload }, jobOptions) |
231 | |||
232 | return true | ||
231 | } | 233 | } |
232 | 234 | ||
233 | async function createLowerResolutionsJobs ( | 235 | async function createLowerResolutionsJobs ( |
@@ -239,16 +241,7 @@ async function createLowerResolutionsJobs ( | |||
239 | ) { | 241 | ) { |
240 | // Create transcoding jobs if there are enabled resolutions | 242 | // Create transcoding jobs if there are enabled resolutions |
241 | const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution, 'vod') | 243 | const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution, 'vod') |
242 | logger.info( | 244 | const resolutionCreated: number[] = [] |
243 | 'Resolutions computed for video %s and origin file resolution of %d.', video.uuid, videoFileResolution, | ||
244 | { resolutions: resolutionsEnabled } | ||
245 | ) | ||
246 | |||
247 | if (resolutionsEnabled.length === 0) { | ||
248 | logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid) | ||
249 | |||
250 | return false | ||
251 | } | ||
252 | 245 | ||
253 | for (const resolution of resolutionsEnabled) { | 246 | for (const resolution of resolutionsEnabled) { |
254 | let dataInput: VideoTranscodingPayload | 247 | let dataInput: VideoTranscodingPayload |
@@ -274,6 +267,10 @@ async function createLowerResolutionsJobs ( | |||
274 | } | 267 | } |
275 | } | 268 | } |
276 | 269 | ||
270 | if (!dataInput) continue | ||
271 | |||
272 | resolutionCreated.push(resolution) | ||
273 | |||
277 | const jobOptions = { | 274 | const jobOptions = { |
278 | priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user) | 275 | priority: JOB_PRIORITY.TRANSCODING.NEW_RESOLUTION + await getJobTranscodingPriorityMalus(user) |
279 | } | 276 | } |
@@ -281,7 +278,16 @@ async function createLowerResolutionsJobs ( | |||
281 | JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }, jobOptions) | 278 | JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput }, jobOptions) |
282 | } | 279 | } |
283 | 280 | ||
284 | logger.info('Transcoding jobs created for uuid %s.', video.uuid, { resolutionsEnabled }) | 281 | if (resolutionCreated.length === 0) { |
282 | logger.info('No transcoding jobs created for video %s (no resolutions).', video.uuid) | ||
283 | |||
284 | return false | ||
285 | } | ||
286 | |||
287 | logger.info( | ||
288 | 'New resolutions %s transcoding jobs created for video %s and origin file resolution of %d.', type, video.uuid, videoFileResolution, | ||
289 | { resolutionCreated } | ||
290 | ) | ||
285 | 291 | ||
286 | return true | 292 | return true |
287 | } | 293 | } |