ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix HLS playlist generation with 0 duration length
Chocobozzz9cd06903f4e8
diff --git a/server/lib/hls.ts b/server/lib/hls.tsindex fc1d7e1b0c..19044d7c2a 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: MStreaminvideo.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: MStreamingPlaylistconst 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.tsindex 06aec13084..3a0d95b625 100644--- a/server/models/video/video.ts+++ b/server/models/video/video.ts@@ -2016,7 +2016,7 @@ 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`)+ if (!this.duration) return videoFile.sizereturn Math.ceil((videoFile.size * 8) / this.duration)}