ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix "height not divisible by 2" ffmpeg error
Chocobozzz318b0bd0c2ff
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.tsindex b5bf2c92c7..f7e6fdddcf 100644--- a/server/helpers/core-utils.ts+++ b/server/helpers/core-utils.ts@@ -243,6 +243,18 @@ function execShell (command: string, options?: ExecOptions) {// ---------------------------------------------------------------------------+function isOdd (num: number) {+ return (num % 2) !== 0+}++function toEven (num: number) {+ if (isOdd) return num + 1++ return num+}++// ---------------------------------------------------------------------------+function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> {return function promisified (): Promise<A> {return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => {@@ -310,5 +322,8 @@ export {execPromise,pipelinePromise,- parseSemVersion+ parseSemVersion,++ isOdd,+ toEven}diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.tsindex e328c49ac8..d20ca5d569 100644--- a/server/helpers/ffmpeg-utils.ts+++ b/server/helpers/ffmpeg-utils.ts@@ -5,11 +5,12 @@ import { dirname, join } from 'path'import { FFMPEG_NICE, VIDEO_LIVE } from '@server/initializers/constants'import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptions, EncoderProfile, VideoResolution } from '../../shared/models/videos'import { CONFIG } from '../initializers/config'-import { execPromise, promisify0 } from './core-utils'+import { execPromise, isOdd, promisify0 } from './core-utils'import { computeFPS, getAudioStream, getVideoFileFPS } from './ffprobe-utils'import { processImage } from './image-utils'import { logger } from './logger'import { FilterSpecification } from 'fluent-ffmpeg'+import { findCommentId } from '@shared/extra-utils'/***@@ -133,7 +134,7 @@ interface BaseTranscodeOptions {availableEncoders: AvailableEncodersprofile: string- resolution: VideoResolution+ resolution: numberisPortraitMode?: boolean@@ -407,8 +408,7 @@ async function buildx264VODCommand (command: ffmpeg.FfmpegCommand, options: Tranasync function buildAudioMergeCommand (command: ffmpeg.FfmpegCommand, options: MergeAudioTranscodeOptions) {command = command.loop(undefined)- // Avoid "height not divisible by 2" error- const scaleFilterValue = 'trunc(iw/2)*2:trunc(ih/2)*2'+ const scaleFilterValue = getScaleCleanerValue()command = await presetVideo({ command, input: options.audioPath, transcodeOptions: options, scaleFilterValue })command.outputOption('-preset:v veryfast')@@ -542,7 +542,7 @@ async function getEncoderBuilderResult (options: {}}- const result = await builder({ input, resolution: resolution, fps, streamNum })+ const result = await builder({ input, resolution, fps, streamNum })return {result,@@ -727,6 +727,11 @@ async function runCommand (options: {})}+// Avoid "height not divisible by 2" error+function getScaleCleanerValue () {+ return 'trunc(iw/2)*2:trunc(ih/2)*2'+}+// ---------------------------------------------------------------------------export {diff --git a/server/lib/transcoding/video-transcoding.ts b/server/lib/transcoding/video-transcoding.tsindex 5df192575f..1ad63baf3a 100644--- a/server/lib/transcoding/video-transcoding.ts+++ b/server/lib/transcoding/video-transcoding.ts@@ -1,6 +1,7 @@import { Job } from 'bull'import { copyFile, ensureDir, move, remove, stat } from 'fs-extra'import { basename, extname as extnameUtil, join } from 'path'+import { toEven } from '@server/helpers/core-utils'import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'import { MStreamingPlaylistFilesVideo, MVideoFile, MVideoFullLight } from '@server/types/models'import { VideoResolution } from '../../../shared/models/videos'@@ -35,6 +36,8 @@ async function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile? 'quick-transcode': 'video'+ const resolution = toEven(inputVideoFile.resolution)+const transcodeOptions: TranscodeOptions = {type: transcodeType,@@ -44,7 +47,7 @@ async function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFileavailableEncoders: VideoTranscodingProfilesManager.Instance.getAvailableEncoders(),profile: CONFIG.TRANSCODING.PROFILE,- resolution: inputVideoFile.resolution,+ resolution,job}@@ -57,7 +60,7 @@ async function optimizeOriginalVideofile (video: MVideoFullLight, inputVideoFile// Important to do this before getVideoFilename() to take in account the new filenameinputVideoFile.extname = newExtname- inputVideoFile.filename = generateVideoFilename(video, false, inputVideoFile.resolution, newExtname)+ inputVideoFile.filename = generateVideoFilename(video, false, resolution, newExtname)const videoOutputPath = getVideoFilePath(video, inputVideoFile)