]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Prevent HLS transcoding after webtorrent transcoding
authorChocobozzz <me@florianbigard.com>
Tue, 1 Feb 2022 10:16:45 +0000 (11:16 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 1 Feb 2022 10:27:38 +0000 (11:27 +0100)
scripts/create-transcoding-job.ts
server/controllers/api/videos/transcoding.ts
server/lib/job-queue/handlers/video-transcoding.ts
server/lib/video.ts
server/tests/api/videos/video-create-transcoding.ts
shared/models/server/job.model.ts

index 95e1e66cfdf2307da2a8ef56527b5dc484b19268..c4b376431fff0cc6fecb66c446fd118af0013ea7 100755 (executable)
@@ -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,
 
index 388689c8afa0a113696bf5d03b02f36454067c7b..fba4545c2a6b849069c8b57c0d23622e5b556fe2 100644 (file)
@@ -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
       })
     }
index 02902b0b8b9faabd23b706bf6319cedb47fde9f3..5540b791de8efded1d8f193d81d158afb019d3b2 100644 (file)
@@ -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
       }
 
index e5af028ea93fff653f2fc26a65fba017f1667fc2..2690f953d9a54a6886dbbf88febeb959e1e64048 100644 (file)
@@ -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 {
index 62a6bab0d6c288c03c2a56b2dde3523878796dde..dcdbd9c6ed74caa8ce519c9f28b1e75836a53158 100644 (file)
@@ -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 })
 
index 8a69d11fa86148786872f7c83199a56e6ffe8536..1519d1c3e4bab01f3fdfa5124604bde145208140 100644 (file)
@@ -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