From 29c7319c8a42d5c4831d08a80f4d111d3a72f52c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 30 May 2023 09:35:21 +0200 Subject: Fix transcoding error When transcoding.always_transcode_original_resolution is false --- .../job-builders/transcoding-job-queue-builder.ts | 4 ++-- server/lib/transcoding/transcoding-resolutions.ts | 21 ++++++++++++++++ server/lib/transcoding/web-transcoding.ts | 28 ++-------------------- 3 files changed, 25 insertions(+), 28 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 fa2ac70bf..4f802e2a6 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 @@ -18,7 +18,7 @@ import { } from '@shared/models' import { getTranscodingJobPriority } from '../../transcoding-priority' import { canDoQuickTranscode } from '../../transcoding-quick-transcode' -import { computeResolutionsToTranscode } from '../../transcoding-resolutions' +import { buildOriginalFileResolution, computeResolutionsToTranscode } from '../../transcoding-resolutions' import { AbstractJobBuilder } from './abstract-job-builder' export class TranscodingJobQueueBuilder extends AbstractJobBuilder { @@ -55,7 +55,7 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder { const maxResolution = await isAudioFile(videoFilePath, probe) ? DEFAULT_AUDIO_RESOLUTION - : resolution + : buildOriginalFileResolution(resolution) if (CONFIG.TRANSCODING.HLS.ENABLED === true) { nextTranscodingSequentialJobPayloads.push([ diff --git a/server/lib/transcoding/transcoding-resolutions.ts b/server/lib/transcoding/transcoding-resolutions.ts index 91f4d18d8..9a6bf5722 100644 --- a/server/lib/transcoding/transcoding-resolutions.ts +++ b/server/lib/transcoding/transcoding-resolutions.ts @@ -2,6 +2,27 @@ import { CONFIG } from '@server/initializers/config' import { toEven } from '@shared/core-utils' import { VideoResolution } from '@shared/models' +export function buildOriginalFileResolution (inputResolution: number) { + if (CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION === true) { + return toEven(inputResolution) + } + + const resolutions = computeResolutionsToTranscode({ + input: inputResolution, + type: 'vod', + includeInput: false, + strictLower: false, + // We don't really care about the audio resolution in this context + hasAudio: true + }) + + if (resolutions.length === 0) { + return toEven(inputResolution) + } + + return Math.max(...resolutions) +} + export function computeResolutionsToTranscode (options: { input: number type: 'vod' | 'live' diff --git a/server/lib/transcoding/web-transcoding.ts b/server/lib/transcoding/web-transcoding.ts index 22bd238ae..7cc8f20bc 100644 --- a/server/lib/transcoding/web-transcoding.ts +++ b/server/lib/transcoding/web-transcoding.ts @@ -3,8 +3,8 @@ import { copyFile, move, remove, stat } from 'fs-extra' import { basename, join } from 'path' import { computeOutputFPS } from '@server/helpers/ffmpeg' import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' +import { VideoModel } from '@server/models/video/video' import { MVideoFile, MVideoFullLight } from '@server/types/models' -import { toEven } from '@shared/core-utils' import { ffprobePromise, getVideoStreamDuration, getVideoStreamFPS, TranscodeVODOptionsType } from '@shared/ffmpeg' import { VideoResolution, VideoStorage } from '@shared/models' import { CONFIG } from '../../initializers/config' @@ -13,8 +13,7 @@ import { generateWebTorrentVideoFilename } from '../paths' 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' +import { buildOriginalFileResolution } from './transcoding-resolutions' // Optimize the original video file and replace it. The resolution is not changed. export async function optimizeOriginalVideofile (options: { @@ -248,26 +247,3 @@ export async function onWebTorrentVideoFileTranscoding (options: { mutexReleaser() } } - -// --------------------------------------------------------------------------- - -function buildOriginalFileResolution (inputResolution: number) { - if (CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION === true) { - return toEven(inputResolution) - } - - const resolutions = computeResolutionsToTranscode({ - input: inputResolution, - type: 'vod', - includeInput: false, - strictLower: false, - // We don't really care about the audio resolution in this context - hasAudio: true - }) - - if (resolutions.length === 0) { - return toEven(inputResolution) - } - - return Math.max(...resolutions) -} -- cgit v1.2.3