import { computeResolutionsToTranscode } from '../../../helpers/ffprobe-utils'
import { logger } from '../../../helpers/logger'
import { CONFIG } from '../../../initializers/config'
-import { sequelizeTypescript } from '../../../initializers/database'
import { VideoModel } from '../../../models/video/video'
import { federateVideoIfNeeded } from '../../activitypub/videos'
import { Notifier } from '../../notifier'
type HandlerFunction = (job: Bull.Job, payload: VideoTranscodingPayload, video: MVideoFullLight, user: MUser) => Promise<any>
-const handlers: { [ id: string ]: HandlerFunction } = {
- // Deprecated, introduced in 3.1
- 'hls': handleHLSJob,
+const handlers: { [ id in VideoTranscodingPayload['type'] ]: HandlerFunction } = {
'new-resolution-to-hls': handleHLSJob,
-
- // Deprecated, introduced in 3.1
- 'new-resolution': handleNewWebTorrentResolutionJob,
'new-resolution-to-webtorrent': handleNewWebTorrentResolutionJob,
-
- // Deprecated, introduced in 3.1
- 'merge-audio': handleWebTorrentMergeAudioJob,
'merge-audio-to-webtorrent': handleWebTorrentMergeAudioJob,
-
- // Deprecated, introduced in 3.1
- 'optimize': handleWebTorrentOptimizeJob,
'optimize-to-webtorrent': handleWebTorrentOptimizeJob
}
if (payload.isMaxQuality && CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) {
// Remove webtorrent files if not enabled
for (const file of video.VideoFiles) {
- await video.removeFile(file)
- await file.removeTorrent()
+ await video.removeFileAndTorrent(file)
await file.destroy()
}
// 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
-
- let videoPublished = false
-
- // Generate HLS version of the original 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',
- isMaxQuality: true
- })
- const hasHls = await createHlsJobIfEnabled(user, originalFileHLSPayload)
-
- const hasNewResolutions = await createLowerResolutionsJobs(videoDatabase, user, videoFileResolution, isPortraitMode, 'webtorrent')
-
- if (!hasHls && !hasNewResolutions) {
- // No transcoding to do, it's now published
- videoPublished = await videoDatabase.publishIfNeededAndSave(t)
- }
+ // Maybe the video changed in database, refresh it
+ const videoDatabase = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoArg.uuid)
+ // Video does not exist anymore
+ if (!videoDatabase) return undefined
- await federateVideoIfNeeded(videoDatabase, payload.isNewVideo, t)
+ let videoPublished = false
- return { videoDatabase, videoPublished }
+ // Generate HLS version of the original 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',
+ isMaxQuality: true
})
+ const hasHls = await createHlsJobIfEnabled(user, originalFileHLSPayload)
+
+ const hasNewResolutions = await createLowerResolutionsJobs(videoDatabase, user, videoFileResolution, isPortraitMode, 'webtorrent')
+
+ if (!hasHls && !hasNewResolutions) {
+ // No transcoding to do, it's now published
+ videoPublished = await videoDatabase.publishIfNeededAndSave(undefined)
+ }
+
+ await federateVideoIfNeeded(videoDatabase, payload.isNewVideo)
if (payload.isNewVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoDatabase)
if (videoPublished) Notifier.Instance.notifyOnVideoPublishedAfterTranscoding(videoDatabase)