mirror of https://github.com/Chocobozzz/PeerTube
Fix saved live master playlist bandwidth
parent
405c83f9af
commit
e4fc3697ac
|
@ -1,7 +1,7 @@
|
||||||
import { Job } from 'bullmq'
|
import { Job } from 'bullmq'
|
||||||
import { readdir, remove } from 'fs-extra'
|
import { readdir, remove } from 'fs-extra'
|
||||||
import { join } from 'path'
|
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 { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
|
||||||
import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
|
import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
|
||||||
import { cleanupPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live'
|
import { cleanupPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live'
|
||||||
|
@ -203,8 +203,6 @@ async function assignReplayFilesToVideo (options: {
|
||||||
}) {
|
}) {
|
||||||
const { video, replayDirectory } = options
|
const { video, replayDirectory } = options
|
||||||
|
|
||||||
let durationDone = false
|
|
||||||
|
|
||||||
const concatenatedTsFiles = await readdir(replayDirectory)
|
const concatenatedTsFiles = await readdir(replayDirectory)
|
||||||
|
|
||||||
for (const concatenatedTsFile of concatenatedTsFiles) {
|
for (const concatenatedTsFile of concatenatedTsFiles) {
|
||||||
|
@ -212,22 +210,14 @@ async function assignReplayFilesToVideo (options: {
|
||||||
|
|
||||||
const probe = await ffprobePromise(concatenatedTsFilePath)
|
const probe = await ffprobePromise(concatenatedTsFilePath)
|
||||||
const { audioStream } = await getAudioStream(concatenatedTsFilePath, probe)
|
const { audioStream } = await getAudioStream(concatenatedTsFilePath, probe)
|
||||||
|
|
||||||
const { resolution } = await getVideoStreamDimensionsInfo(concatenatedTsFilePath, probe)
|
const { resolution } = await getVideoStreamDimensionsInfo(concatenatedTsFilePath, probe)
|
||||||
|
|
||||||
const { resolutionPlaylistPath: outputPath } = await generateHlsPlaylistResolutionFromTS({
|
await generateHlsPlaylistResolutionFromTS({
|
||||||
video,
|
video,
|
||||||
concatenatedTsFilePath,
|
concatenatedTsFilePath,
|
||||||
resolution,
|
resolution,
|
||||||
isAAC: audioStream?.codec_name === 'aac'
|
isAAC: audioStream?.codec_name === 'aac'
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!durationDone) {
|
|
||||||
video.duration = await getVideoStreamDuration(outputPath)
|
|
||||||
await video.save()
|
|
||||||
|
|
||||||
durationDone = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return video
|
return video
|
||||||
|
|
|
@ -342,6 +342,12 @@ async function generateHlsPlaylistCommon (options: {
|
||||||
// Move video file
|
// Move video file
|
||||||
await move(join(videoTranscodedBasePath, videoFilename), videoFilePath, { overwrite: true })
|
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)
|
const stats = await stat(videoFilePath)
|
||||||
|
|
||||||
newVideoFile.size = stats.size
|
newVideoFile.size = stats.size
|
||||||
|
|
|
@ -1899,6 +1899,8 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
getBandwidthBits (this: MVideo, videoFile: MVideoFile) {
|
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)
|
return Math.ceil((videoFile.size * 8) / this.duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue