Fix "height not divisible by 2" ffmpeg error
This commit is contained in:
parent
5982ffc4b5
commit
318b0bd0c2
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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: AvailableEncoders
|
||||
profile: string
|
||||
|
||||
resolution: VideoResolution
|
||||
resolution: number
|
||||
|
||||
isPortraitMode?: boolean
|
||||
|
||||
|
@ -407,8 +408,7 @@ async function buildx264VODCommand (command: ffmpeg.FfmpegCommand, options: Tran
|
|||
async 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 {
|
||||
|
|
|
@ -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, inputVideoFile
|
|||
availableEncoders: 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 filename
|
||||
inputVideoFile.extname = newExtname
|
||||
inputVideoFile.filename = generateVideoFilename(video, false, inputVideoFile.resolution, newExtname)
|
||||
inputVideoFile.filename = generateVideoFilename(video, false, resolution, newExtname)
|
||||
|
||||
const videoOutputPath = getVideoFilePath(video, inputVideoFile)
|
||||
|
||||
|
|
Loading…
Reference in New Issue