From cc2abbc320ea66296bf45314a2efb47d16b38374 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 21 Apr 2023 16:31:04 +0200 Subject: Fix next video state after optimize/audio merge --- .../job-builders/transcoding-job-queue-builder.ts | 19 +++++++++++++------ server/lib/transcoding/web-transcoding.ts | 16 ++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) (limited to 'server/lib/transcoding') 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 7c892718b..c09c6b8ce 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 @@ -76,9 +76,10 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder { nextTranscodingSequentialJobPayloads = [ ...nextTranscodingSequentialJobPayloads, ...lowerResolutionJobPayloads ] + const hasChildren = nextTranscodingSequentialJobPayloads.length !== 0 mergeOrOptimizePayload = videoFile.isAudio() - ? this.buildMergeAudioPayload({ videoUUID: video.uuid, isNewVideo }) - : this.buildOptimizePayload({ videoUUID: video.uuid, isNewVideo, quickTranscode }) + ? this.buildMergeAudioPayload({ videoUUID: video.uuid, isNewVideo, hasChildren }) + : this.buildOptimizePayload({ videoUUID: video.uuid, isNewVideo, quickTranscode, hasChildren }) }) } finally { mutexReleaser() @@ -100,7 +101,9 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder { const mergeOrOptimizeJob = await this.buildTranscodingJob({ payload: mergeOrOptimizePayload, user }) - return JobQueue.Instance.createSequentialJobFlow(...[ mergeOrOptimizeJob, transcodingJobBuilderJob ]) + await JobQueue.Instance.createSequentialJobFlow(...[ mergeOrOptimizeJob, transcodingJobBuilderJob ]) + + await VideoJobInfoModel.increaseOrCreate(video.uuid, 'pendingTranscode') } // --------------------------------------------------------------------------- @@ -279,15 +282,17 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder { private buildMergeAudioPayload (options: { videoUUID: string isNewVideo: boolean + hasChildren: boolean }): MergeAudioTranscodingPayload { - const { videoUUID, isNewVideo } = options + const { videoUUID, isNewVideo, hasChildren } = options return { type: 'merge-audio-to-webtorrent', resolution: DEFAULT_AUDIO_RESOLUTION, fps: VIDEO_TRANSCODING_FPS.AUDIO_MERGE, videoUUID, - isNewVideo + isNewVideo, + hasChildren } } @@ -295,13 +300,15 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder { videoUUID: string quickTranscode: boolean isNewVideo: boolean + hasChildren: boolean }): OptimizeTranscodingPayload { - const { videoUUID, quickTranscode, isNewVideo } = options + const { videoUUID, quickTranscode, isNewVideo, hasChildren } = options return { type: 'optimize-to-webtorrent', videoUUID, isNewVideo, + hasChildren, quickTranscode } } diff --git a/server/lib/transcoding/web-transcoding.ts b/server/lib/transcoding/web-transcoding.ts index d43d03b2a..22bd238ae 100644 --- a/server/lib/transcoding/web-transcoding.ts +++ b/server/lib/transcoding/web-transcoding.ts @@ -14,6 +14,7 @@ import { buildFileMetadata } from '../video-file' import { VideoPathManager } from '../video-path-manager' import { buildFFmpegVOD } from './shared' import { computeResolutionsToTranscode } from './transcoding-resolutions' +import { VideoModel } from '@server/models/video/video' // Optimize the original video file and replace it. The resolution is not changed. export async function optimizeOriginalVideofile (options: { @@ -32,6 +33,7 @@ export async function optimizeOriginalVideofile (options: { try { await video.reload() + await inputVideoFile.reload() const fileWithVideoOrPlaylist = inputVideoFile.withVideoOrPlaylist(video) @@ -88,16 +90,15 @@ export async function transcodeNewWebTorrentResolution (options: { fps: number job: Job }) { - const { video, resolution, fps, job } = options + const { video: videoArg, resolution, fps, job } = options const transcodeDirectory = CONFIG.STORAGE.TMP_DIR const newExtname = '.mp4' - const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) + const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(videoArg.uuid) try { - await video.reload() - + const video = await VideoModel.loadFull(videoArg.uuid) const file = video.getMaxQualityFile().withVideoOrPlaylist(video) const result = await VideoPathManager.Instance.makeAvailableVideoFile(file, async videoInputPath => { @@ -141,16 +142,15 @@ export async function mergeAudioVideofile (options: { fps: number job: Job }) { - const { video, resolution, fps, job } = options + const { video: videoArg, resolution, fps, job } = options const transcodeDirectory = CONFIG.STORAGE.TMP_DIR const newExtname = '.mp4' - const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid) + const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(videoArg.uuid) try { - await video.reload() - + const video = await VideoModel.loadFull(videoArg.uuid) const inputVideoFile = video.getMinQualityFile() const fileWithVideoOrPlaylist = inputVideoFile.withVideoOrPlaylist(video) -- cgit v1.2.3