aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-09-09 09:21:42 +0200
committerChocobozzz <me@florianbigard.com>2022-09-09 09:21:42 +0200
commite4fc3697acb27c4192cbbb63eb94272a6cf7ce32 (patch)
tree96daedbbbc030920bae25816dd15a16a8c85fb8f
parent405c83f9af377a663a4c8e9ad025fd5c10496922 (diff)
downloadPeerTube-e4fc3697acb27c4192cbbb63eb94272a6cf7ce32.tar.gz
PeerTube-e4fc3697acb27c4192cbbb63eb94272a6cf7ce32.tar.zst
PeerTube-e4fc3697acb27c4192cbbb63eb94272a6cf7ce32.zip
Fix saved live master playlist bandwidth
-rw-r--r--server/lib/job-queue/handlers/video-live-ending.ts14
-rw-r--r--server/lib/transcoding/transcoding.ts6
-rw-r--r--server/models/video/video.ts2
3 files changed, 10 insertions, 12 deletions
diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts
index 79002258c..8a3ee09a2 100644
--- a/server/lib/job-queue/handlers/video-live-ending.ts
+++ b/server/lib/job-queue/handlers/video-live-ending.ts
@@ -1,7 +1,7 @@
1import { Job } from 'bullmq' 1import { Job } from 'bullmq'
2import { readdir, remove } from 'fs-extra' 2import { readdir, remove } from 'fs-extra'
3import { join } from 'path' 3import { join } from 'path'
4import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamDuration } from '@server/helpers/ffmpeg' 4import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo } from '@server/helpers/ffmpeg'
5import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' 5import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
6import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' 6import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
7import { cleanupPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live' 7import { cleanupPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live'
@@ -203,8 +203,6 @@ async function assignReplayFilesToVideo (options: {
203}) { 203}) {
204 const { video, replayDirectory } = options 204 const { video, replayDirectory } = options
205 205
206 let durationDone = false
207
208 const concatenatedTsFiles = await readdir(replayDirectory) 206 const concatenatedTsFiles = await readdir(replayDirectory)
209 207
210 for (const concatenatedTsFile of concatenatedTsFiles) { 208 for (const concatenatedTsFile of concatenatedTsFiles) {
@@ -212,22 +210,14 @@ async function assignReplayFilesToVideo (options: {
212 210
213 const probe = await ffprobePromise(concatenatedTsFilePath) 211 const probe = await ffprobePromise(concatenatedTsFilePath)
214 const { audioStream } = await getAudioStream(concatenatedTsFilePath, probe) 212 const { audioStream } = await getAudioStream(concatenatedTsFilePath, probe)
215
216 const { resolution } = await getVideoStreamDimensionsInfo(concatenatedTsFilePath, probe) 213 const { resolution } = await getVideoStreamDimensionsInfo(concatenatedTsFilePath, probe)
217 214
218 const { resolutionPlaylistPath: outputPath } = await generateHlsPlaylistResolutionFromTS({ 215 await generateHlsPlaylistResolutionFromTS({
219 video, 216 video,
220 concatenatedTsFilePath, 217 concatenatedTsFilePath,
221 resolution, 218 resolution,
222 isAAC: audioStream?.codec_name === 'aac' 219 isAAC: audioStream?.codec_name === 'aac'
223 }) 220 })
224
225 if (!durationDone) {
226 video.duration = await getVideoStreamDuration(outputPath)
227 await video.save()
228
229 durationDone = true
230 }
231 } 221 }
232 222
233 return video 223 return video
diff --git a/server/lib/transcoding/transcoding.ts b/server/lib/transcoding/transcoding.ts
index 07eee4122..44e26754d 100644
--- a/server/lib/transcoding/transcoding.ts
+++ b/server/lib/transcoding/transcoding.ts
@@ -342,6 +342,12 @@ async function generateHlsPlaylistCommon (options: {
342 // Move video file 342 // Move video file
343 await move(join(videoTranscodedBasePath, videoFilename), videoFilePath, { overwrite: true }) 343 await move(join(videoTranscodedBasePath, videoFilename), videoFilePath, { overwrite: true })
344 344
345 // Update video duration if it was not set (in case of a live for example)
346 if (!video.duration) {
347 video.duration = await getVideoStreamDuration(videoFilePath)
348 await video.save()
349 }
350
345 const stats = await stat(videoFilePath) 351 const stats = await stat(videoFilePath)
346 352
347 newVideoFile.size = stats.size 353 newVideoFile.size = stats.size
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index a8ea67c39..468117504 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1899,6 +1899,8 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1899 } 1899 }
1900 1900
1901 getBandwidthBits (this: MVideo, videoFile: MVideoFile) { 1901 getBandwidthBits (this: MVideo, videoFile: MVideoFile) {
1902 if (!this.duration) throw new Error(`Cannot get bandwidth bits because video ${this.url} has duration of 0`)
1903
1902 return Math.ceil((videoFile.size * 8) / this.duration) 1904 return Math.ceil((videoFile.size * 8) / this.duration)
1903 } 1905 }
1904 1906