- if (videoArg === undefined) return undefined
-
- // Outside the transaction (IO on disk)
- const { videoFileResolution, isPortraitMode } = await videoArg.getMaxQualityResolution()
-
- const { videoDatabase, videoPublished } = await sequelizeTypescript.transaction(async t => {
- // Maybe the video changed in database, refresh it
- const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid, t)
- // Video does not exist anymore
- if (!videoDatabase) return undefined
-
- // Create transcoding jobs if there are enabled resolutions
- const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution, 'vod')
- logger.info(
- 'Resolutions computed for video %s and origin file resolution of %d.', videoDatabase.uuid, videoFileResolution,
- { resolutions: resolutionsEnabled }
- )
-
- let videoPublished = false
-
- // Generate HLS version of the max quality file
- const originalFileHLSPayload = Object.assign({}, payload, {
- isPortraitMode,
- resolution: videoDatabase.getMaxQualityFile().resolution,
- // If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues
- copyCodecs: transcodeType !== 'quick-transcode'
- })
- createHlsJobIfEnabled(originalFileHLSPayload)
-
- if (resolutionsEnabled.length !== 0) {
- for (const resolution of resolutionsEnabled) {
- let dataInput: VideoTranscodingPayload
-
- if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED) {
- dataInput = {
- type: 'new-resolution' as 'new-resolution',
- videoUUID: videoDatabase.uuid,
- resolution,
- isPortraitMode
- }
- } else if (CONFIG.TRANSCODING.HLS.ENABLED) {
- dataInput = {
- type: 'hls',
- videoUUID: videoDatabase.uuid,
- resolution,
- isPortraitMode,
- copyCodecs: false
- }
- }
-
- JobQueue.Instance.createJob({ type: 'video-transcoding', payload: dataInput })
- }
+ const { resolution, isPortraitMode, audioStream } = await videoArg.probeMaxQualityFile()
+
+ // Maybe the video changed in database, refresh it
+ const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid)
+ // Video does not exist anymore
+ if (!videoDatabase) return undefined
+
+ // Generate HLS version of the original file
+ const originalFileHLSPayload = {
+ ...payload,
+
+ isPortraitMode,
+ hasAudio: !!audioStream,
+ resolution: videoDatabase.getMaxQualityFile().resolution,
+ // If we quick transcoded original file, force transcoding for HLS to avoid some weird playback issues
+ copyCodecs: transcodeType !== 'quick-transcode',
+ isMaxQuality: true
+ }
+ const hasHls = await createHlsJobIfEnabled(user, originalFileHLSPayload)
+ const hasNewResolutions = await createLowerResolutionsJobs({
+ video: videoDatabase,
+ user,
+ videoFileResolution: resolution,
+ hasAudio: !!audioStream,
+ isPortraitMode,
+ type: 'webtorrent',
+ isNewVideo: payload.isNewVideo ?? true
+ })