X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fhls.ts;h=43043315be6ed42dc752d029ca87ebb30ba67de2;hb=57e4e1c1a95c3a81a967f54ecc2a510d8b0e129c;hp=220b7733b56d3b2dc15c5c613527edd0f3b38d68;hpb=06aad80165d09a8863ab8103149a8ff518b10641;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/hls.ts b/server/lib/hls.ts index 220b7733b..43043315b 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts @@ -2,8 +2,9 @@ import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, import { flatten, uniq } from 'lodash' import { basename, dirname, join } from 'path' import { MStreamingPlaylistFilesVideo, MVideo, MVideoUUID } from '@server/types/models' -import { sha256 } from '@shared/core-utils/crypto' -import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamSize } from '../helpers/ffprobe-utils' +import { sha256 } from '@shared/extra-utils' +import { VideoStorage } from '@shared/models' +import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamDimensionsInfo } from '../helpers/ffmpeg' import { logger } from '../helpers/logger' import { doRequest, doRequestAndSaveToFile } from '../helpers/requests' import { generateRandomString } from '../helpers/utils' @@ -12,6 +13,7 @@ import { P2P_MEDIA_LOADER_PEER_VERSION, REQUEST_TIMEOUTS } from '../initializers import { sequelizeTypescript } from '../initializers/database' import { VideoFileModel } from '../models/video/video-file' import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' +import { storeHLSFile } from './object-storage' import { getHlsResolutionPlaylistFilename } from './paths' import { VideoPathManager } from './video-path-manager' @@ -38,10 +40,10 @@ async function updateMasterHLSPlaylist (video: MVideo, playlist: MStreamingPlayl const playlistFilename = getHlsResolutionPlaylistFilename(file.filename) await VideoPathManager.Instance.makeAvailableVideoFile(file.withVideoOrPlaylist(playlist), async videoFilePath => { - const size = await getVideoStreamSize(videoFilePath) + const size = await getVideoStreamDimensionsInfo(videoFilePath) const bandwidth = 'BANDWIDTH=' + video.getBandwidthBits(file) - const resolution = `RESOLUTION=${size.width}x${size.height}` + const resolution = `RESOLUTION=${size?.width || 0}x${size?.height || 0}` let line = `#EXT-X-STREAM-INF:${bandwidth},${resolution}` if (file.fps) line += ',FRAME-RATE=' + file.fps @@ -58,8 +60,12 @@ async function updateMasterHLSPlaylist (video: MVideo, playlist: MStreamingPlayl }) } - await VideoPathManager.Instance.makeAvailablePlaylistFile(playlist, playlist.playlistFilename, masterPlaylistPath => { - return writeFile(masterPlaylistPath, masterPlaylists.join('\n') + '\n') + await VideoPathManager.Instance.makeAvailablePlaylistFile(playlist, playlist.playlistFilename, async masterPlaylistPath => { + await writeFile(masterPlaylistPath, masterPlaylists.join('\n') + '\n') + + if (playlist.storage === VideoStorage.OBJECT_STORAGE) { + await storeHLSFile(playlist, playlist.playlistFilename, masterPlaylistPath) + } }) } @@ -94,6 +100,11 @@ async function updateSha256VODSegments (video: MVideoUUID, playlist: MStreamingP const outputPath = VideoPathManager.Instance.getFSHLSOutputPath(video, playlist.segmentsSha256Filename) await outputJSON(outputPath, json) + + if (playlist.storage === VideoStorage.OBJECT_STORAGE) { + await storeHLSFile(playlist, playlist.segmentsSha256Filename) + await remove(outputPath) + } } async function buildSha256Segment (segmentPath: string) {