From a687879e94fa5d3ecdd76bec3d94d0e1698ee913 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 May 2023 13:41:48 +0200 Subject: [PATCH] Reload the video after waiting for the files lock --- server/lib/job-queue/handlers/manage-video-torrent.ts | 3 +++ server/lib/job-queue/handlers/move-to-object-storage.ts | 5 +++-- server/lib/job-queue/handlers/video-live-ending.ts | 1 + server/lib/transcoding/hls-transcoding.ts | 1 - .../shared/job-builders/transcoding-job-queue-builder.ts | 3 +++ .../shared/job-builders/transcoding-runner-job-builder.ts | 3 +++ server/tests/peertube-runner/live-transcoding.ts | 6 ++++-- server/tests/peertube-runner/studio-transcoding.ts | 6 ++++-- server/tests/peertube-runner/vod-transcoding.ts | 6 ++++-- shared/server-commands/videos/live.ts | 4 ++-- 10 files changed, 27 insertions(+), 11 deletions(-) diff --git a/server/lib/job-queue/handlers/manage-video-torrent.ts b/server/lib/job-queue/handlers/manage-video-torrent.ts index cef93afda..edf52de0c 100644 --- a/server/lib/job-queue/handlers/manage-video-torrent.ts +++ b/server/lib/job-queue/handlers/manage-video-torrent.ts @@ -35,6 +35,9 @@ async function doCreateAction (payload: ManageVideoTorrentPayload & { action: 'c const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) try { + await video.reload() + await file.reload() + await createTorrentAndSetInfoHash(video, file) // Refresh videoFile because the createTorrentAndSetInfoHash could be long 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 a1530cc57..26752ff37 100644 --- a/server/lib/job-queue/handlers/move-to-object-storage.ts +++ b/server/lib/job-queue/handlers/move-to-object-storage.ts @@ -19,17 +19,18 @@ export async function processMoveToObjectStorage (job: Job) { const payload = job.data as MoveObjectStoragePayload logger.info('Moving video %s in job %s.', payload.videoUUID, job.id) + const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(payload.videoUUID) + const video = await VideoModel.loadWithFiles(payload.videoUUID) // No video, maybe deleted? if (!video) { logger.info('Can\'t process job %d, video does not exist.', job.id, lTagsBase(payload.videoUUID)) + fileMutexReleaser() return undefined } const lTags = lTagsBase(video.uuid, video.url) - const fileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) - try { if (video.VideoFiles) { logger.debug('Moving %d webtorrent files for video %s.', video.VideoFiles.length, video.uuid, lTags) diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts index 1bf43f592..814f313a3 100644 --- a/server/lib/job-queue/handlers/video-live-ending.ts +++ b/server/lib/job-queue/handlers/video-live-ending.ts @@ -218,6 +218,7 @@ async function assignReplayFilesToVideo (options: { for (const concatenatedTsFile of concatenatedTsFiles) { const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) + await video.reload() const concatenatedTsFilePath = join(replayDirectory, concatenatedTsFile) diff --git a/server/lib/transcoding/hls-transcoding.ts b/server/lib/transcoding/hls-transcoding.ts index cffa859c7..2c325d9ee 100644 --- a/server/lib/transcoding/hls-transcoding.ts +++ b/server/lib/transcoding/hls-transcoding.ts @@ -72,7 +72,6 @@ export async function onHLSVideoFileTranscoding (options: { const mutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) try { - // VOD transcoding is a long task, refresh video attributes await video.reload() const videoFilePath = VideoPathManager.Instance.getFSVideoFileOutputPath(playlist, videoFile) diff --git a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts index 29ee2ca61..fa2ac70bf 100644 --- a/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts +++ b/server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts @@ -40,6 +40,9 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder { : await VideoPathManager.Instance.lockFiles(video.uuid) try { + await video.reload() + await videoFile.reload() + await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), async videoFilePath => { const probe = await ffprobePromise(videoFilePath) diff --git a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts index 90b035402..4b8bc2f3d 100644 --- a/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts +++ b/server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts @@ -36,6 +36,9 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder { : await VideoPathManager.Instance.lockFiles(video.uuid) try { + await video.reload() + await videoFile.reload() + await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), async videoFilePath => { const probe = await ffprobePromise(videoFilePath) diff --git a/server/tests/peertube-runner/live-transcoding.ts b/server/tests/peertube-runner/live-transcoding.ts index 31716d545..f0acf25c8 100644 --- a/server/tests/peertube-runner/live-transcoding.ts +++ b/server/tests/peertube-runner/live-transcoding.ts @@ -183,8 +183,10 @@ describe('Test Live transcoding in peertube-runner program', function () { }) after(async function () { - await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] }) - peertubeRunner.kill() + if (peertubeRunner) { + await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] }) + peertubeRunner.kill() + } await cleanupTests(servers) }) diff --git a/server/tests/peertube-runner/studio-transcoding.ts b/server/tests/peertube-runner/studio-transcoding.ts index 204836c4d..e20cc9041 100644 --- a/server/tests/peertube-runner/studio-transcoding.ts +++ b/server/tests/peertube-runner/studio-transcoding.ts @@ -108,8 +108,10 @@ describe('Test studio transcoding in peertube-runner program', function () { }) after(async function () { - await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] }) - peertubeRunner.kill() + if (peertubeRunner) { + await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] }) + peertubeRunner.kill() + } await cleanupTests(servers) }) diff --git a/server/tests/peertube-runner/vod-transcoding.ts b/server/tests/peertube-runner/vod-transcoding.ts index 3a9abba93..3c0918102 100644 --- a/server/tests/peertube-runner/vod-transcoding.ts +++ b/server/tests/peertube-runner/vod-transcoding.ts @@ -334,8 +334,10 @@ describe('Test VOD transcoding in peertube-runner program', function () { }) after(async function () { - await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] }) - peertubeRunner.kill() + if (peertubeRunner) { + await peertubeRunner.unregisterPeerTubeInstance({ server: servers[0] }) + peertubeRunner.kill() + } await cleanupTests(servers) }) diff --git a/shared/server-commands/videos/live.ts b/shared/server-commands/videos/live.ts index 578e6ede7..3b09d3ff8 100644 --- a/shared/server-commands/videos/live.ts +++ b/shared/server-commands/videos/live.ts @@ -21,8 +21,8 @@ function sendRTMPStream (options: { command.outputOption('-c copy') } else { command.outputOption('-c:v libx264') - command.outputOption('-g 50') - command.outputOption('-keyint_min 2') + command.outputOption('-g 120') + command.outputOption('-x264-params "no-scenecut=1"') command.outputOption('-r 60') }