- for (const resolution of resolutionsEnabled) {
- const dataInput = {
- videoUUID: videoDatabase.uuid,
- resolution,
- isNewVideo
+ // Outside the transaction (IO on disk)
+ const { videoFileResolution } = await video.getOriginalFileResolution()
+
+ return sequelizeTypescript.transaction(async t => {
+ // Maybe the video changed in database, refresh it
+ const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(video.uuid, t)
+ // Video does not exist anymore
+ if (!videoDatabase) return undefined
+
+ // Create transcoding jobs if there are enabled resolutions
+ const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution)
+ logger.info(
+ 'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, videoFileResolution,
+ { resolutions: resolutionsEnabled }
+ )
+
+ if (resolutionsEnabled.length !== 0) {
+ const tasks: Bluebird<any>[] = []
+
+ for (const resolution of resolutionsEnabled) {
+ const dataInput = {
+ videoUUID: videoDatabase.uuid,
+ resolution
+ }
+
+ const p = JobQueue.Instance.createJob({ type: 'video-file', payload: dataInput })
+ tasks.push(p)