Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix live files locking

Chocobozzz74121a737462
diff --git a/server/core/lib/job-queue/handlers/video-live-ending.ts b/server/core/lib/job-queue/handlers/video-live-ending.ts
index dabb4024c8..e9287f5d9f 100644
--- a/server/core/lib/job-queue/handlers/video-live-ending.ts
+++ b/server/core/lib/job-queue/handlers/video-live-ending.ts
@@ -357,6 +357,7 @@ async function assignReplayFilesToVideo (options: {
await generateHlsPlaylistResolutionFromTS({
video,
inputFileMutexReleaser: null, // Already locked in parent
+ preventInputFileLocking: true,
concatenatedTsFilePath,
resolution,
fps,
diff --git a/server/core/lib/transcoding/hls-transcoding.ts b/server/core/lib/transcoding/hls-transcoding.ts
index 604003c242..7ebb1faf24 100644
--- a/server/core/lib/transcoding/hls-transcoding.ts
+++ b/server/core/lib/transcoding/hls-transcoding.ts
@@ -26,13 +26,14 @@ export async function generateHlsPlaylistResolutionFromTS (options: {
fps: number
isAAC: boolean
inputFileMutexReleaser: MutexInterface.Releaser
+ preventInputFileLocking?: boolean
}) {
return generateHlsPlaylistCommon({
type: 'hls-from-ts' as 'hls-from-ts',
videoInputPath: options.concatenatedTsFilePath,
- ...pick(options, [ 'video', 'resolution', 'fps', 'inputFileMutexReleaser', 'isAAC' ])
+ ...pick(options, [ 'video', 'resolution', 'fps', 'inputFileMutexReleaser', 'preventInputFileLocking', 'isAAC' ])
})
}
@@ -69,8 +70,9 @@ export async function onHLSVideoFileTranscoding (options: {
video: MVideo
videoOutputPath: string
m3u8OutputPath: string
+ preventInputFileLocking?: boolean
}) {
- const { video, videoOutputPath, m3u8OutputPath } = options
+ const { video, videoOutputPath, m3u8OutputPath, preventInputFileLocking } = options
// Create or update the playlist
const { playlist, generated: playlistGenerated } = await retryTransactionWrapper(() => {
@@ -82,7 +84,9 @@ export async function onHLSVideoFileTranscoding (options: {
const newVideoFile = await buildNewFile({ mode: 'hls', path: videoOutputPath })
newVideoFile.videoStreamingPlaylistId = playlist.id
- const mutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
+ const mutexReleaser = preventInputFileLocking === true
+ ? null
+ : await VideoPathManager.Instance.lockFiles(video.uuid)
try {
await video.reload()
@@ -131,7 +135,7 @@ export async function onHLSVideoFileTranscoding (options: {
return { resolutionPlaylistPath, videoFile: savedVideoFile }
} finally {
- mutexReleaser()
+ if (mutexReleaser) mutexReleaser()
}
}
@@ -150,6 +154,7 @@ async function generateHlsPlaylistCommon (options: {
fps: number
inputFileMutexReleaser: MutexInterface.Releaser
+ preventInputFileLocking?: boolean
separatedAudio?: boolean
@@ -167,7 +172,8 @@ async function generateHlsPlaylistCommon (options: {
separatedAudio,
isAAC,
job,
- inputFileMutexReleaser
+ inputFileMutexReleaser,
+ preventInputFileLocking
} = options
const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
@@ -208,11 +214,12 @@ async function generateHlsPlaylistCommon (options: {
await buildFFmpegVOD(job).transcode(transcodeOptions)
// Ensure the mutex is released if the ffmpeg command failed and did not release it
- inputFileMutexReleaser()
+ if (inputFileMutexReleaser) inputFileMutexReleaser()
await onHLSVideoFileTranscoding({
video,
videoOutputPath,
+ preventInputFileLocking,
m3u8OutputPath
})
}