Fix saved live master playlist bandwidth
This commit is contained in:
parent
405c83f9af
commit
e4fc3697ac
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue