From cfd57d2ca0bb058087f7dc90fcc3e8442b0288e1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 4 Oct 2022 10:03:17 +0200 Subject: Live supports object storage * Sync live files (segments, master playlist, resolution playlist, segment sha file) into object storage * Automatically delete them when the live ends * Segment sha file is now a file on disk, and not stored in memory anymore --- .../job-queue/handlers/move-to-object-storage.ts | 10 +++++----- server/lib/job-queue/handlers/video-live-ending.ts | 23 +++++++++++----------- 2 files changed, 16 insertions(+), 17 deletions(-) (limited to 'server/lib/job-queue') diff --git a/server/lib/job-queue/handlers/move-to-object-storage.ts b/server/lib/job-queue/handlers/move-to-object-storage.ts index 25bdebeea..28c3d325d 100644 --- a/server/lib/job-queue/handlers/move-to-object-storage.ts +++ b/server/lib/job-queue/handlers/move-to-object-storage.ts @@ -5,7 +5,7 @@ import { logger, loggerTagsFactory } from '@server/helpers/logger' import { updateTorrentMetadata } from '@server/helpers/webtorrent' import { CONFIG } from '@server/initializers/config' import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants' -import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage' +import { storeHLSFileFromFilename, storeWebTorrentFile } from '@server/lib/object-storage' import { getHLSDirectory, getHlsResolutionPlaylistFilename } from '@server/lib/paths' import { moveToFailedMoveToObjectStorageState, moveToNextState } from '@server/lib/video-state' import { VideoModel } from '@server/models/video/video' @@ -88,10 +88,10 @@ async function moveHLSFiles (video: MVideoWithAllFiles) { // Resolution playlist const playlistFilename = getHlsResolutionPlaylistFilename(file.filename) - await storeHLSFile(playlistWithVideo, playlistFilename) + await storeHLSFileFromFilename(playlistWithVideo, playlistFilename) // Resolution fragmented file - const fileUrl = await storeHLSFile(playlistWithVideo, file.filename) + const fileUrl = await storeHLSFileFromFilename(playlistWithVideo, file.filename) const oldPath = join(getHLSDirectory(video), file.filename) @@ -113,9 +113,9 @@ async function doAfterLastJob (options: { const playlistWithVideo = playlist.withVideo(video) // Master playlist - playlist.playlistUrl = await storeHLSFile(playlistWithVideo, playlist.playlistFilename) + playlist.playlistUrl = await storeHLSFileFromFilename(playlistWithVideo, playlist.playlistFilename) // Sha256 segments file - playlist.segmentsSha256Url = await storeHLSFile(playlistWithVideo, playlist.segmentsSha256Filename) + playlist.segmentsSha256Url = await storeHLSFileFromFilename(playlistWithVideo, playlist.segmentsSha256Filename) playlist.storage = VideoStorage.OBJECT_STORAGE diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts index 8a3ee09a2..abfaf1cd7 100644 --- a/server/lib/job-queue/handlers/video-live-ending.ts +++ b/server/lib/job-queue/handlers/video-live-ending.ts @@ -4,7 +4,7 @@ import { join } from 'path' 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' +import { cleanupAndDestroyPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live' import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '@server/lib/paths' import { generateVideoMiniature } from '@server/lib/thumbnail' import { generateHlsPlaylistResolutionFromTS } from '@server/lib/transcoding/transcoding' @@ -141,23 +141,22 @@ async function replaceLiveByReplay (options: { }) { const { video, liveSession, live, permanentLive, replayDirectory } = options - await cleanupTMPLiveFiles(video) + const videoWithFiles = await VideoModel.loadFull(video.id) + const hlsPlaylist = videoWithFiles.getHLSPlaylist() + + await cleanupTMPLiveFiles(videoWithFiles, hlsPlaylist) await live.destroy() - video.isLive = false - video.waitTranscoding = true - video.state = VideoState.TO_TRANSCODE + videoWithFiles.isLive = false + videoWithFiles.waitTranscoding = true + videoWithFiles.state = VideoState.TO_TRANSCODE - await video.save() + await videoWithFiles.save() - liveSession.replayVideoId = video.id + liveSession.replayVideoId = videoWithFiles.id await liveSession.save() - // Remove old HLS playlist video files - const videoWithFiles = await VideoModel.loadFull(video.id) - - const hlsPlaylist = videoWithFiles.getHLSPlaylist() await VideoFileModel.removeHLSFilesOfVideoId(hlsPlaylist.id) // Reset playlist @@ -234,7 +233,7 @@ async function cleanupLiveAndFederate (options: { if (streamingPlaylist) { if (permanentLive) { - await cleanupPermanentLive(video, streamingPlaylist) + await cleanupAndDestroyPermanentLive(video, streamingPlaylist) } else { await cleanupUnsavedNormalLive(video, streamingPlaylist) } -- cgit v1.2.3