From ad5db1044c8599eaaaa2a578b350777ae996b068 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Nov 2021 14:35:08 +0100 Subject: Add ability to run transcoding jobs --- server/lib/job-queue/handlers/move-to-object-storage.ts | 11 +++++++---- server/lib/job-queue/handlers/video-transcoding.ts | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'server/lib/job-queue') diff --git a/server/lib/job-queue/handlers/move-to-object-storage.ts b/server/lib/job-queue/handlers/move-to-object-storage.ts index 4beca3d75..54a7c566b 100644 --- a/server/lib/job-queue/handlers/move-to-object-storage.ts +++ b/server/lib/job-queue/handlers/move-to-object-storage.ts @@ -56,16 +56,17 @@ async function moveWebTorrentFiles (video: MVideoWithAllFiles) { async function moveHLSFiles (video: MVideoWithAllFiles) { for (const playlist of video.VideoStreamingPlaylists) { + const playlistWithVideo = playlist.withVideo(video) for (const file of playlist.VideoFiles) { if (file.storage !== VideoStorage.FILE_SYSTEM) continue // Resolution playlist const playlistFilename = getHlsResolutionPlaylistFilename(file.filename) - await storeHLSFile(playlist, video, playlistFilename) + await storeHLSFile(playlistWithVideo, playlistFilename) // Resolution fragmented file - const fileUrl = await storeHLSFile(playlist, video, file.filename) + const fileUrl = await storeHLSFile(playlistWithVideo, file.filename) const oldPath = join(getHLSDirectory(video), file.filename) @@ -78,10 +79,12 @@ async function doAfterLastJob (video: MVideoWithAllFiles, isNewVideo: boolean) { for (const playlist of video.VideoStreamingPlaylists) { if (playlist.storage === VideoStorage.OBJECT_STORAGE) continue + const playlistWithVideo = playlist.withVideo(video) + // Master playlist - playlist.playlistUrl = await storeHLSFile(playlist, video, playlist.playlistFilename) + playlist.playlistUrl = await storeHLSFile(playlistWithVideo, playlist.playlistFilename) // Sha256 segments file - playlist.segmentsSha256Url = await storeHLSFile(playlist, video, playlist.segmentsSha256Filename) + playlist.segmentsSha256Url = await storeHLSFile(playlistWithVideo, playlist.segmentsSha256Filename) playlist.storage = VideoStorage.OBJECT_STORAGE diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index 904ef2e3c..2d0798e12 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts @@ -14,7 +14,7 @@ import { VideoTranscodingPayload } from '../../../../shared' import { retryTransactionWrapper } from '../../../helpers/database-utils' -import { computeResolutionsToTranscode } from '../../../helpers/ffprobe-utils' +import { computeLowerResolutionsToTranscode } from '../../../helpers/ffprobe-utils' import { logger, loggerTagsFactory } from '../../../helpers/logger' import { CONFIG } from '../../../initializers/config' import { VideoModel } from '../../../models/video/video' @@ -81,7 +81,7 @@ async function handleHLSJob (job: Job, payload: HLSTranscodingPayload, video: MV const videoOrStreamingPlaylist = videoFileInput.getVideoOrStreamingPlaylist() - await VideoPathManager.Instance.makeAvailableVideoFile(videoOrStreamingPlaylist, videoFileInput, videoInputPath => { + await VideoPathManager.Instance.makeAvailableVideoFile(videoFileInput.withVideoOrPlaylist(videoOrStreamingPlaylist), videoInputPath => { return generateHlsPlaylistResolution({ video, videoInputPath, @@ -135,7 +135,7 @@ async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodi // --------------------------------------------------------------------------- async function onHlsPlaylistGeneration (video: MVideoFullLight, user: MUser, payload: HLSTranscodingPayload) { - if (payload.isMaxQuality && CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) { + if (payload.isMaxQuality && payload.autoDeleteWebTorrentIfNeeded && CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false) { // Remove webtorrent files if not enabled for (const file of video.VideoFiles) { await video.removeWebTorrentFileAndTorrent(file) @@ -232,6 +232,7 @@ async function createHlsJobIfEnabled (user: MUserId, payload: { isPortraitMode: payload.isPortraitMode, copyCodecs: payload.copyCodecs, isMaxQuality: payload.isMaxQuality, + autoDeleteWebTorrentIfNeeded: true, isNewVideo: payload.isNewVideo } @@ -261,7 +262,7 @@ async function createLowerResolutionsJobs (options: { const { video, user, videoFileResolution, isPortraitMode, isNewVideo, type } = options // Create transcoding jobs if there are enabled resolutions - const resolutionsEnabled = computeResolutionsToTranscode(videoFileResolution, 'vod') + const resolutionsEnabled = computeLowerResolutionsToTranscode(videoFileResolution, 'vod') const resolutionCreated: string[] = [] for (const resolution of resolutionsEnabled) { @@ -288,6 +289,7 @@ async function createLowerResolutionsJobs (options: { isPortraitMode, copyCodecs: false, isMaxQuality: false, + autoDeleteWebTorrentIfNeeded: true, isNewVideo } -- cgit v1.2.3