aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-08 11:28:51 +0200
committerChocobozzz <me@florianbigard.com>2021-06-08 11:28:51 +0200
commit318b0bd0c2ff575f35d51d97327f77abfecd6b86 (patch)
tree095a464dc053c06bc7a9c1e6a50a18ac9a7e4dce /server/helpers
parent5982ffc4b5c926ea51f5bb3ca48f0f2f8f5bd621 (diff)
downloadPeerTube-318b0bd0c2ff575f35d51d97327f77abfecd6b86.tar.gz
PeerTube-318b0bd0c2ff575f35d51d97327f77abfecd6b86.tar.zst
PeerTube-318b0bd0c2ff575f35d51d97327f77abfecd6b86.zip
Fix "height not divisible by 2" ffmpeg error
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/core-utils.ts17
-rw-r--r--server/helpers/ffmpeg-utils.ts15
2 files changed, 26 insertions, 6 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index b5bf2c92c..f7e6fdddc 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -243,6 +243,18 @@ function execShell (command: string, options?: ExecOptions) {
243 243
244// --------------------------------------------------------------------------- 244// ---------------------------------------------------------------------------
245 245
246function isOdd (num: number) {
247 return (num % 2) !== 0
248}
249
250function toEven (num: number) {
251 if (isOdd) return num + 1
252
253 return num
254}
255
256// ---------------------------------------------------------------------------
257
246function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> { 258function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> {
247 return function promisified (): Promise<A> { 259 return function promisified (): Promise<A> {
248 return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => { 260 return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => {
@@ -310,5 +322,8 @@ export {
310 execPromise, 322 execPromise,
311 pipelinePromise, 323 pipelinePromise,
312 324
313 parseSemVersion 325 parseSemVersion,
326
327 isOdd,
328 toEven
314} 329}
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index e328c49ac..d20ca5d56 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -5,11 +5,12 @@ import { dirname, join } from 'path'
5import { FFMPEG_NICE, VIDEO_LIVE } from '@server/initializers/constants' 5import { FFMPEG_NICE, VIDEO_LIVE } from '@server/initializers/constants'
6import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptions, EncoderProfile, VideoResolution } from '../../shared/models/videos' 6import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptions, EncoderProfile, VideoResolution } from '../../shared/models/videos'
7import { CONFIG } from '../initializers/config' 7import { CONFIG } from '../initializers/config'
8import { execPromise, promisify0 } from './core-utils' 8import { execPromise, isOdd, promisify0 } from './core-utils'
9import { computeFPS, getAudioStream, getVideoFileFPS } from './ffprobe-utils' 9import { computeFPS, getAudioStream, getVideoFileFPS } from './ffprobe-utils'
10import { processImage } from './image-utils' 10import { processImage } from './image-utils'
11import { logger } from './logger' 11import { logger } from './logger'
12import { FilterSpecification } from 'fluent-ffmpeg' 12import { FilterSpecification } from 'fluent-ffmpeg'
13import { findCommentId } from '@shared/extra-utils'
13 14
14/** 15/**
15 * 16 *
@@ -133,7 +134,7 @@ interface BaseTranscodeOptions {
133 availableEncoders: AvailableEncoders 134 availableEncoders: AvailableEncoders
134 profile: string 135 profile: string
135 136
136 resolution: VideoResolution 137 resolution: number
137 138
138 isPortraitMode?: boolean 139 isPortraitMode?: boolean
139 140
@@ -407,8 +408,7 @@ async function buildx264VODCommand (command: ffmpeg.FfmpegCommand, options: Tran
407async function buildAudioMergeCommand (command: ffmpeg.FfmpegCommand, options: MergeAudioTranscodeOptions) { 408async function buildAudioMergeCommand (command: ffmpeg.FfmpegCommand, options: MergeAudioTranscodeOptions) {
408 command = command.loop(undefined) 409 command = command.loop(undefined)
409 410
410 // Avoid "height not divisible by 2" error 411 const scaleFilterValue = getScaleCleanerValue()
411 const scaleFilterValue = 'trunc(iw/2)*2:trunc(ih/2)*2'
412 command = await presetVideo({ command, input: options.audioPath, transcodeOptions: options, scaleFilterValue }) 412 command = await presetVideo({ command, input: options.audioPath, transcodeOptions: options, scaleFilterValue })
413 413
414 command.outputOption('-preset:v veryfast') 414 command.outputOption('-preset:v veryfast')
@@ -542,7 +542,7 @@ async function getEncoderBuilderResult (options: {
542 } 542 }
543 } 543 }
544 544
545 const result = await builder({ input, resolution: resolution, fps, streamNum }) 545 const result = await builder({ input, resolution, fps, streamNum })
546 546
547 return { 547 return {
548 result, 548 result,
@@ -727,6 +727,11 @@ async function runCommand (options: {
727 }) 727 })
728} 728}
729 729
730// Avoid "height not divisible by 2" error
731function getScaleCleanerValue () {
732 return 'trunc(iw/2)*2:trunc(ih/2)*2'
733}
734
730// --------------------------------------------------------------------------- 735// ---------------------------------------------------------------------------
731 736
732export { 737export {