]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix saved live master playlist bandwidth
authorChocobozzz <me@florianbigard.com>
Fri, 9 Sep 2022 07:21:42 +0000 (09:21 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 9 Sep 2022 07:21:42 +0000 (09:21 +0200)
server/lib/job-queue/handlers/video-live-ending.ts
server/lib/transcoding/transcoding.ts
server/models/video/video.ts

index 79002258cd292153bdf66e369b7f0c4299f24797..8a3ee09a2290210354bedfb8b2895fdadd3ab020 100644 (file)
@@ -1,7 +1,7 @@
 import { Job } from 'bullmq'
 import { readdir, remove } from 'fs-extra'
 import { join } from 'path'
-import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamDuration } from '@server/helpers/ffmpeg'
+import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo } from '@server/helpers/ffmpeg'
 import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
 import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
 import { cleanupPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live'
@@ -203,8 +203,6 @@ async function assignReplayFilesToVideo (options: {
 }) {
   const { video, replayDirectory } = options
 
-  let durationDone = false
-
   const concatenatedTsFiles = await readdir(replayDirectory)
 
   for (const concatenatedTsFile of concatenatedTsFiles) {
@@ -212,22 +210,14 @@ async function assignReplayFilesToVideo (options: {
 
     const probe = await ffprobePromise(concatenatedTsFilePath)
     const { audioStream } = await getAudioStream(concatenatedTsFilePath, probe)
-
     const { resolution } = await getVideoStreamDimensionsInfo(concatenatedTsFilePath, probe)
 
-    const { resolutionPlaylistPath: outputPath } = await generateHlsPlaylistResolutionFromTS({
+    await generateHlsPlaylistResolutionFromTS({
       video,
       concatenatedTsFilePath,
       resolution,
       isAAC: audioStream?.codec_name === 'aac'
     })
-
-    if (!durationDone) {
-      video.duration = await getVideoStreamDuration(outputPath)
-      await video.save()
-
-      durationDone = true
-    }
   }
 
   return video
index 07eee4122d3ad761eb34b841d51fb328156cb5d0..44e26754d52954e06fab0236ea3f98b8c3fe1a36 100644 (file)
@@ -342,6 +342,12 @@ async function generateHlsPlaylistCommon (options: {
   // Move video file
   await move(join(videoTranscodedBasePath, videoFilename), videoFilePath, { overwrite: true })
 
+  // Update video duration if it was not set (in case of a live for example)
+  if (!video.duration) {
+    video.duration = await getVideoStreamDuration(videoFilePath)
+    await video.save()
+  }
+
   const stats = await stat(videoFilePath)
 
   newVideoFile.size = stats.size
index a8ea67c395379a22090f396268bafefc434dbeb2..468117504e5ea328fd2744ff5e64c9b93ef84b3a 100644 (file)
@@ -1899,6 +1899,8 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
   }
 
   getBandwidthBits (this: MVideo, videoFile: MVideoFile) {
+    if (!this.duration) throw new Error(`Cannot get bandwidth bits because video ${this.url} has duration of 0`)
+
     return Math.ceil((videoFile.size * 8) / this.duration)
   }