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 @@ 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 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: { // 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 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>> { } 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) }