mirror of https://github.com/Chocobozzz/PeerTube
Fix HLS playlist generation with 0 duration length
parent
a287136427
commit
9cd06903f4
|
@ -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)
|
||||
|
|
|
@ -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.size
|
||||
|
||||
return Math.ceil((videoFile.size * 8) / this.duration)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue