diff --git a/scripts/create-transcoding-job.ts b/scripts/create-transcoding-job.ts index 95e1e66cf..c4b376431 100755 --- a/scripts/create-transcoding-job.ts +++ b/scripts/create-transcoding-job.ts @@ -77,6 +77,8 @@ async function run () { type: 'new-resolution-to-webtorrent', videoUUID: video.uuid, + createHLSIfNeeded: true, + // FIXME: check the file has audio hasAudio: true, 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 }) diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index 8a69d11fa..1519d1c3e 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts @@ -113,11 +113,12 @@ export interface HLSTranscodingPayload extends BaseTranscodingPayload { isMaxQuality: boolean } -export interface NewResolutionTranscodingPayload extends BaseTranscodingPayload { +export interface NewWebTorrentResolutionTranscodingPayload extends BaseTranscodingPayload { type: 'new-resolution-to-webtorrent' resolution: VideoResolution hasAudio: boolean + createHLSIfNeeded: boolean isPortraitMode?: boolean } @@ -125,6 +126,7 @@ export interface NewResolutionTranscodingPayload extends BaseTranscodingPayload export interface MergeAudioTranscodingPayload extends BaseTranscodingPayload { type: 'merge-audio-to-webtorrent' resolution: VideoResolution + createHLSIfNeeded: true } export interface OptimizeTranscodingPayload extends BaseTranscodingPayload { @@ -133,7 +135,7 @@ export interface OptimizeTranscodingPayload extends BaseTranscodingPayload { export type VideoTranscodingPayload = HLSTranscodingPayload - | NewResolutionTranscodingPayload + | NewWebTorrentResolutionTranscodingPayload | OptimizeTranscodingPayload | MergeAudioTranscodingPayload