ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix next video state after optimize/audio merge
Chocobozzzcc2abbc320ea
diff --git a/server/lib/job-queue/handlers/transcoding-job-builder.ts b/server/lib/job-queue/handlers/transcoding-job-builder.tsindex 8b4a877d7d..cb45337dfe 100644--- a/server/lib/job-queue/handlers/transcoding-job-builder.ts+++ b/server/lib/job-queue/handlers/transcoding-job-builder.ts@@ -36,7 +36,7 @@ async function processTranscodingJobBuilder (job: Job) {for (const sequentialJobs of (payload.sequentialJobs || [])) {await JobQueue.Instance.createSequentialJobFlow(...sequentialJobs)- await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode', sequentialJobs.length)+ await VideoJobInfoModel.increaseOrCreate(payload.videoUUID, 'pendingTranscode', sequentialJobs.filter(s => !!s).length)}}diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.tsindex 17b717275f..39f078bf06 100644--- a/server/lib/job-queue/handlers/video-transcoding.ts+++ b/server/lib/job-queue/handlers/video-transcoding.ts@@ -81,7 +81,7 @@ async function handleWebTorrentMergeAudioJob (job: Job, payload: MergeAudioTranslogger.info('Merge audio transcoding job for %s ended.', video.uuid, lTags(video.uuid))- await onTranscodingEnded({ isNewVideo: payload.isNewVideo, moveVideoToNextState: true, video })+ await onTranscodingEnded({ isNewVideo: payload.isNewVideo, moveVideoToNextState: !payload.hasChildren, video })}async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodingPayload, video: MVideoFullLight, user: MUserId) {@@ -91,9 +91,11 @@ async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodilogger.info('Optimize transcoding job for %s ended.', video.uuid, lTags(video.uuid))- await onTranscodingEnded({ isNewVideo: payload.isNewVideo, moveVideoToNextState: true, video })+ await onTranscodingEnded({ isNewVideo: payload.isNewVideo, moveVideoToNextState: !payload.hasChildren, video })}+// ---------------------------------------------------------------------------+async function handleNewWebTorrentResolutionJob (job: Job, payload: NewWebTorrentResolutionTranscodingPayload, video: MVideoFullLight) {logger.info('Handling WebTorrent transcoding job for %s.', video.uuid, lTags(video.uuid))@@ -104,19 +106,22 @@ async function handleNewWebTorrentResolutionJob (job: Job, payload: NewWebTorrenawait onTranscodingEnded({ isNewVideo: payload.isNewVideo, moveVideoToNextState: true, video })}-async function handleHLSJob (job: Job, payload: HLSTranscodingPayload, video: MVideoFullLight) {- logger.info('Handling HLS transcoding job for %s.', video.uuid, lTags(video.uuid))-- const videoFileInput = payload.copyCodecs- ? video.getWebTorrentFile(payload.resolution)- : video.getMaxQualityFile()+// ---------------------------------------------------------------------------- const videoOrStreamingPlaylist = videoFileInput.getVideoOrStreamingPlaylist()+async function handleHLSJob (job: Job, payload: HLSTranscodingPayload, videoArg: MVideoFullLight) {+ logger.info('Handling HLS transcoding job for %s.', videoArg.uuid, lTags(videoArg.uuid))- const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)+ const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(videoArg.uuid)+ let video: MVideoFullLighttry {- await videoFileInput.getVideo().reload()+ video = await VideoModel.loadFull(videoArg.uuid)++ const videoFileInput = payload.copyCodecs+ ? video.getWebTorrentFile(payload.resolution)+ : video.getMaxQualityFile()++ const videoOrStreamingPlaylist = videoFileInput.getVideoOrStreamingPlaylist()await VideoPathManager.Instance.makeAvailableVideoFile(videoFileInput.withVideoOrPlaylist(videoOrStreamingPlaylist), videoInputPath => {return generateHlsPlaylistResolution({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.tsindex 7c892718b9..c09c6b8ce9 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 !== 0mergeOrOptimizePayload = 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: stringisNewVideo: boolean+ hasChildren: boolean}): MergeAudioTranscodingPayload {- const { videoUUID, isNewVideo } = options+ const { videoUUID, isNewVideo, hasChildren } = optionsreturn {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: stringquickTranscode: booleanisNewVideo: boolean+ hasChildren: boolean}): OptimizeTranscodingPayload {- const { videoUUID, quickTranscode, isNewVideo } = options+ const { videoUUID, quickTranscode, isNewVideo, hasChildren } = optionsreturn {type: 'optimize-to-webtorrent',videoUUID,isNewVideo,+ hasChildren,quickTranscode}}diff --git a/server/lib/transcoding/web-transcoding.ts b/server/lib/transcoding/web-transcoding.tsindex d43d03b2a1..22bd238aea 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: numberjob: Job}) {- const { video, resolution, fps, job } = options+ const { video: videoArg, resolution, fps, job } = optionsconst transcodeDirectory = CONFIG.STORAGE.TMP_DIRconst 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: numberjob: Job}) {- const { video, resolution, fps, job } = options+ const { video: videoArg, resolution, fps, job } = optionsconst transcodeDirectory = CONFIG.STORAGE.TMP_DIRconst 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)diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.tsindex 16187d133b..3fd5bf7f92 100644--- a/shared/models/server/job.model.ts+++ b/shared/models/server/job.model.ts@@ -158,14 +158,19 @@ export interface NewWebTorrentResolutionTranscodingPayload extends BaseTranscodiexport interface MergeAudioTranscodingPayload extends BaseTranscodingPayload {type: 'merge-audio-to-webtorrent'+resolution: VideoResolutionfps: number++ hasChildren: boolean}export interface OptimizeTranscodingPayload extends BaseTranscodingPayload {type: 'optimize-to-webtorrent'quickTranscode: boolean++ hasChildren: boolean}export type VideoTranscodingPayload =