Fix next video state after optimize/audio merge
This commit is contained in:
parent
1772b383de
commit
cc2abbc320
|
@ -36,7 +36,7 @@ async function processTranscodingJobBuilder (job: Job) {
|
||||||
for (const sequentialJobs of (payload.sequentialJobs || [])) {
|
for (const sequentialJobs of (payload.sequentialJobs || [])) {
|
||||||
await JobQueue.Instance.createSequentialJobFlow(...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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ async function handleWebTorrentMergeAudioJob (job: Job, payload: MergeAudioTrans
|
||||||
|
|
||||||
logger.info('Merge audio transcoding job for %s ended.', video.uuid, lTags(video.uuid))
|
logger.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) {
|
async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodingPayload, video: MVideoFullLight, user: MUserId) {
|
||||||
|
@ -91,9 +91,11 @@ async function handleWebTorrentOptimizeJob (job: Job, payload: OptimizeTranscodi
|
||||||
|
|
||||||
logger.info('Optimize transcoding job for %s ended.', video.uuid, lTags(video.uuid))
|
logger.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) {
|
async function handleNewWebTorrentResolutionJob (job: Job, payload: NewWebTorrentResolutionTranscodingPayload, video: MVideoFullLight) {
|
||||||
logger.info('Handling WebTorrent transcoding job for %s.', video.uuid, lTags(video.uuid))
|
logger.info('Handling WebTorrent transcoding job for %s.', video.uuid, lTags(video.uuid))
|
||||||
|
|
||||||
|
@ -104,19 +106,22 @@ async function handleNewWebTorrentResolutionJob (job: Job, payload: NewWebTorren
|
||||||
await onTranscodingEnded({ isNewVideo: payload.isNewVideo, moveVideoToNextState: true, video })
|
await 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
|
async function handleHLSJob (job: Job, payload: HLSTranscodingPayload, videoArg: MVideoFullLight) {
|
||||||
? video.getWebTorrentFile(payload.resolution)
|
logger.info('Handling HLS transcoding job for %s.', videoArg.uuid, lTags(videoArg.uuid))
|
||||||
: video.getMaxQualityFile()
|
|
||||||
|
|
||||||
const videoOrStreamingPlaylist = videoFileInput.getVideoOrStreamingPlaylist()
|
const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(videoArg.uuid)
|
||||||
|
let video: MVideoFullLight
|
||||||
const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
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 => {
|
await VideoPathManager.Instance.makeAvailableVideoFile(videoFileInput.withVideoOrPlaylist(videoOrStreamingPlaylist), videoInputPath => {
|
||||||
return generateHlsPlaylistResolution({
|
return generateHlsPlaylistResolution({
|
||||||
|
|
|
@ -76,9 +76,10 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder {
|
||||||
|
|
||||||
nextTranscodingSequentialJobPayloads = [ ...nextTranscodingSequentialJobPayloads, ...lowerResolutionJobPayloads ]
|
nextTranscodingSequentialJobPayloads = [ ...nextTranscodingSequentialJobPayloads, ...lowerResolutionJobPayloads ]
|
||||||
|
|
||||||
|
const hasChildren = nextTranscodingSequentialJobPayloads.length !== 0
|
||||||
mergeOrOptimizePayload = videoFile.isAudio()
|
mergeOrOptimizePayload = videoFile.isAudio()
|
||||||
? this.buildMergeAudioPayload({ videoUUID: video.uuid, isNewVideo })
|
? this.buildMergeAudioPayload({ videoUUID: video.uuid, isNewVideo, hasChildren })
|
||||||
: this.buildOptimizePayload({ videoUUID: video.uuid, isNewVideo, quickTranscode })
|
: this.buildOptimizePayload({ videoUUID: video.uuid, isNewVideo, quickTranscode, hasChildren })
|
||||||
})
|
})
|
||||||
} finally {
|
} finally {
|
||||||
mutexReleaser()
|
mutexReleaser()
|
||||||
|
@ -100,7 +101,9 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder {
|
||||||
|
|
||||||
const mergeOrOptimizeJob = await this.buildTranscodingJob({ payload: mergeOrOptimizePayload, user })
|
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: {
|
private buildMergeAudioPayload (options: {
|
||||||
videoUUID: string
|
videoUUID: string
|
||||||
isNewVideo: boolean
|
isNewVideo: boolean
|
||||||
|
hasChildren: boolean
|
||||||
}): MergeAudioTranscodingPayload {
|
}): MergeAudioTranscodingPayload {
|
||||||
const { videoUUID, isNewVideo } = options
|
const { videoUUID, isNewVideo, hasChildren } = options
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'merge-audio-to-webtorrent',
|
type: 'merge-audio-to-webtorrent',
|
||||||
resolution: DEFAULT_AUDIO_RESOLUTION,
|
resolution: DEFAULT_AUDIO_RESOLUTION,
|
||||||
fps: VIDEO_TRANSCODING_FPS.AUDIO_MERGE,
|
fps: VIDEO_TRANSCODING_FPS.AUDIO_MERGE,
|
||||||
videoUUID,
|
videoUUID,
|
||||||
isNewVideo
|
isNewVideo,
|
||||||
|
hasChildren
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,13 +300,15 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder {
|
||||||
videoUUID: string
|
videoUUID: string
|
||||||
quickTranscode: boolean
|
quickTranscode: boolean
|
||||||
isNewVideo: boolean
|
isNewVideo: boolean
|
||||||
|
hasChildren: boolean
|
||||||
}): OptimizeTranscodingPayload {
|
}): OptimizeTranscodingPayload {
|
||||||
const { videoUUID, quickTranscode, isNewVideo } = options
|
const { videoUUID, quickTranscode, isNewVideo, hasChildren } = options
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'optimize-to-webtorrent',
|
type: 'optimize-to-webtorrent',
|
||||||
videoUUID,
|
videoUUID,
|
||||||
isNewVideo,
|
isNewVideo,
|
||||||
|
hasChildren,
|
||||||
quickTranscode
|
quickTranscode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { buildFileMetadata } from '../video-file'
|
||||||
import { VideoPathManager } from '../video-path-manager'
|
import { VideoPathManager } from '../video-path-manager'
|
||||||
import { buildFFmpegVOD } from './shared'
|
import { buildFFmpegVOD } from './shared'
|
||||||
import { computeResolutionsToTranscode } from './transcoding-resolutions'
|
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.
|
// Optimize the original video file and replace it. The resolution is not changed.
|
||||||
export async function optimizeOriginalVideofile (options: {
|
export async function optimizeOriginalVideofile (options: {
|
||||||
|
@ -32,6 +33,7 @@ export async function optimizeOriginalVideofile (options: {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await video.reload()
|
await video.reload()
|
||||||
|
await inputVideoFile.reload()
|
||||||
|
|
||||||
const fileWithVideoOrPlaylist = inputVideoFile.withVideoOrPlaylist(video)
|
const fileWithVideoOrPlaylist = inputVideoFile.withVideoOrPlaylist(video)
|
||||||
|
|
||||||
|
@ -88,16 +90,15 @@ export async function transcodeNewWebTorrentResolution (options: {
|
||||||
fps: number
|
fps: number
|
||||||
job: Job
|
job: Job
|
||||||
}) {
|
}) {
|
||||||
const { video, resolution, fps, job } = options
|
const { video: videoArg, resolution, fps, job } = options
|
||||||
|
|
||||||
const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
|
const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
|
||||||
const newExtname = '.mp4'
|
const newExtname = '.mp4'
|
||||||
|
|
||||||
const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
|
const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(videoArg.uuid)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await video.reload()
|
const video = await VideoModel.loadFull(videoArg.uuid)
|
||||||
|
|
||||||
const file = video.getMaxQualityFile().withVideoOrPlaylist(video)
|
const file = video.getMaxQualityFile().withVideoOrPlaylist(video)
|
||||||
|
|
||||||
const result = await VideoPathManager.Instance.makeAvailableVideoFile(file, async videoInputPath => {
|
const result = await VideoPathManager.Instance.makeAvailableVideoFile(file, async videoInputPath => {
|
||||||
|
@ -141,16 +142,15 @@ export async function mergeAudioVideofile (options: {
|
||||||
fps: number
|
fps: number
|
||||||
job: Job
|
job: Job
|
||||||
}) {
|
}) {
|
||||||
const { video, resolution, fps, job } = options
|
const { video: videoArg, resolution, fps, job } = options
|
||||||
|
|
||||||
const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
|
const transcodeDirectory = CONFIG.STORAGE.TMP_DIR
|
||||||
const newExtname = '.mp4'
|
const newExtname = '.mp4'
|
||||||
|
|
||||||
const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
|
const inputFileMutexReleaser = await VideoPathManager.Instance.lockFiles(videoArg.uuid)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await video.reload()
|
const video = await VideoModel.loadFull(videoArg.uuid)
|
||||||
|
|
||||||
const inputVideoFile = video.getMinQualityFile()
|
const inputVideoFile = video.getMinQualityFile()
|
||||||
|
|
||||||
const fileWithVideoOrPlaylist = inputVideoFile.withVideoOrPlaylist(video)
|
const fileWithVideoOrPlaylist = inputVideoFile.withVideoOrPlaylist(video)
|
||||||
|
|
|
@ -158,14 +158,19 @@ export interface NewWebTorrentResolutionTranscodingPayload extends BaseTranscodi
|
||||||
|
|
||||||
export interface MergeAudioTranscodingPayload extends BaseTranscodingPayload {
|
export interface MergeAudioTranscodingPayload extends BaseTranscodingPayload {
|
||||||
type: 'merge-audio-to-webtorrent'
|
type: 'merge-audio-to-webtorrent'
|
||||||
|
|
||||||
resolution: VideoResolution
|
resolution: VideoResolution
|
||||||
fps: number
|
fps: number
|
||||||
|
|
||||||
|
hasChildren: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OptimizeTranscodingPayload extends BaseTranscodingPayload {
|
export interface OptimizeTranscodingPayload extends BaseTranscodingPayload {
|
||||||
type: 'optimize-to-webtorrent'
|
type: 'optimize-to-webtorrent'
|
||||||
|
|
||||||
quickTranscode: boolean
|
quickTranscode: boolean
|
||||||
|
|
||||||
|
hasChildren: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type VideoTranscodingPayload =
|
export type VideoTranscodingPayload =
|
||||||
|
|
Loading…
Reference in New Issue
Block a user