From 0f11ec8dd32b50897c18588db948e96cf0fc2c70 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 1 Feb 2022 11:16:45 +0100 Subject: Prevent HLS transcoding after webtorrent transcoding --- server/controllers/api/videos/transcoding.ts | 5 +++-- server/lib/job-queue/handlers/video-transcoding.ts | 12 +++++++---- server/lib/video.ts | 1 + .../tests/api/videos/video-create-transcoding.ts | 25 +++++++++++++++++++++- 4 files changed, 36 insertions(+), 7 deletions(-) (limited to 'server') diff --git a/server/controllers/api/videos/transcoding.ts b/server/controllers/api/videos/transcoding.ts index 388689c8a..fba4545c2 100644 --- a/server/controllers/api/videos/transcoding.ts +++ b/server/controllers/api/videos/transcoding.ts @@ -25,7 +25,7 @@ export { async function createTranscoding (req: express.Request, res: express.Response) { const video = res.locals.videoAll - logger.info('Creating %s transcoding job for %s.', req.body.type, video.url, lTags()) + logger.info('Creating %s transcoding job for %s.', req.body.transcodingType, video.url, lTags()) const body: VideoTranscodingCreate = req.body @@ -53,8 +53,9 @@ async function createTranscoding (req: express.Request, res: express.Response) { type: 'new-resolution-to-webtorrent', videoUUID: video.uuid, isNewVideo: false, - resolution: resolution, + resolution, hasAudio: !!audioStream, + createHLSIfNeeded: false, isPortraitMode }) } diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts index 02902b0b8..5540b791d 100644 --- a/server/lib/job-queue/handlers/video-transcoding.ts +++ b/server/lib/job-queue/handlers/video-transcoding.ts @@ -10,7 +10,7 @@ import { pick } from '@shared/core-utils' import { HLSTranscodingPayload, MergeAudioTranscodingPayload, - NewResolutionTranscodingPayload, + NewWebTorrentResolutionTranscodingPayload, OptimizeTranscodingPayload, VideoResolution, VideoTranscodingPayload @@ -110,7 +110,7 @@ async function handleHLSJob (job: Job, payload: HLSTranscodingPayload, video: MV async function handleNewWebTorrentResolutionJob ( job: Job, - payload: NewResolutionTranscodingPayload, + payload: NewWebTorrentResolutionTranscodingPayload, video: MVideoFullLight, user: MUserId ) { @@ -217,9 +217,12 @@ async function onVideoFirstWebTorrentTranscoding ( async function onNewWebTorrentFileResolution ( video: MVideo, user: MUserId, - payload: NewResolutionTranscodingPayload | MergeAudioTranscodingPayload + payload: NewWebTorrentResolutionTranscodingPayload | MergeAudioTranscodingPayload ) { - await createHlsJobIfEnabled(user, { hasAudio: true, copyCodecs: true, isMaxQuality: false, ...payload }) + if (payload.createHLSIfNeeded) { + await createHlsJobIfEnabled(user, { hasAudio: true, copyCodecs: true, isMaxQuality: false, ...payload }) + } + await VideoJobInfoModel.decrease(video.uuid, 'pendingTranscode') await retryTransactionWrapper(moveToNextState, video, payload.isNewVideo) @@ -282,6 +285,7 @@ async function createLowerResolutionsJobs (options: { resolution, isPortraitMode, hasAudio, + createHLSIfNeeded: true, isNewVideo } diff --git a/server/lib/video.ts b/server/lib/video.ts index e5af028ea..2690f953d 100644 --- a/server/lib/video.ts +++ b/server/lib/video.ts @@ -89,6 +89,7 @@ async function addOptimizeOrMergeAudioJob (video: MVideoUUID, videoFile: MVideoF type: 'merge-audio-to-webtorrent', resolution: DEFAULT_AUDIO_RESOLUTION, videoUUID: video.uuid, + createHLSIfNeeded: true, isNewVideo: true } } else { diff --git a/server/tests/api/videos/video-create-transcoding.ts b/server/tests/api/videos/video-create-transcoding.ts index 62a6bab0d..dcdbd9c6e 100644 --- a/server/tests/api/videos/video-create-transcoding.ts +++ b/server/tests/api/videos/video-create-transcoding.ts @@ -25,7 +25,11 @@ async function checkFilesInObjectStorage (video: VideoDetails) { await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) } - for (const file of video.streamingPlaylists[0].files) { + const streamingPlaylistFiles = video.streamingPlaylists.length === 0 + ? [] + : video.streamingPlaylists[0].files + + for (const file of streamingPlaylistFiles) { expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl()) await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) } @@ -127,6 +131,25 @@ function runTests (objectStorage: boolean) { } }) + it('Should only generate WebTorrent', async function () { + this.timeout(60000) + + await servers[0].videos.removeHLSFiles({ videoId: videoUUID }) + await waitJobs(servers) + + await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' }) + await waitJobs(servers) + + for (const server of servers) { + const videoDetails = await server.videos.get({ id: videoUUID }) + + expect(videoDetails.files).to.have.lengthOf(5) + expect(videoDetails.streamingPlaylists).to.have.lengthOf(0) + + if (objectStorage) await checkFilesInObjectStorage(videoDetails) + } + }) + it('Should not have updated published at attributes', async function () { const video = await servers[0].videos.get({ id: videoUUID }) -- cgit v1.2.3