From 9cd06903f4e83b67bde8bd558374c75127a86c39 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 29 Jun 2023 14:20:03 +0200 Subject: [PATCH] Fix HLS playlist generation with 0 duration length --- server/lib/hls.ts | 8 ++++++-- server/models/video/video.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/server/lib/hls.ts b/server/lib/hls.ts index fc1d7e1b0..19044d7c2 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts @@ -8,7 +8,7 @@ import { sha256 } from '@shared/extra-utils' import { getVideoStreamDimensionsInfo } from '@shared/ffmpeg' import { VideoStorage } from '@shared/models' import { getAudioStreamCodec, getVideoStreamCodec } from '../helpers/ffmpeg' -import { logger } from '../helpers/logger' +import { logger, loggerTagsFactory } from '../helpers/logger' import { doRequest, doRequestAndSaveToFile } from '../helpers/requests' import { generateRandomString } from '../helpers/utils' import { CONFIG } from '../initializers/config' @@ -20,6 +20,8 @@ import { storeHLSFileFromFilename } from './object-storage' import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getHlsResolutionPlaylistFilename } from './paths' import { VideoPathManager } from './video-path-manager' +const lTags = loggerTagsFactory('hls') + async function updateStreamingPlaylistsInfohashesIfNeeded () { const playlistsToUpdate = await VideoStreamingPlaylistModel.listByIncorrectPeerVersion() @@ -48,7 +50,7 @@ async function updatePlaylistAfterFileChange (video: MVideo, playlist: MStreamin video.setHLSPlaylist(playlistWithFiles) } catch (err) { - logger.info('Cannot update playlist after file change. Maybe due to concurrent transcoding', { err }) + logger.warn('Cannot update playlist after file change. Maybe due to concurrent transcoding', { err }) } } @@ -95,6 +97,8 @@ function updateMasterHLSPlaylist (video: MVideo, playlistArg: MStreamingPlaylist const masterPlaylistPath = VideoPathManager.Instance.getFSHLSOutputPath(video, playlist.playlistFilename) await writeFile(masterPlaylistPath, masterPlaylists.join('\n') + '\n') + logger.info('Updating %s master playlist file of video %s', masterPlaylistPath, video.uuid, lTags(video.uuid)) + if (playlist.storage === VideoStorage.OBJECT_STORAGE) { playlist.playlistUrl = await storeHLSFileFromFilename(playlist, playlist.playlistFilename) await remove(masterPlaylistPath) diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 06aec1308..3a0d95b62 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -2016,7 +2016,7 @@ 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`) + if (!this.duration) return videoFile.size return Math.ceil((videoFile.size * 8) / this.duration) }