aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/transcoding/video-transcoding-profiles.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/transcoding/video-transcoding-profiles.ts')
-rw-r--r--server/lib/transcoding/video-transcoding-profiles.ts27
1 files changed, 21 insertions, 6 deletions
diff --git a/server/lib/transcoding/video-transcoding-profiles.ts b/server/lib/transcoding/video-transcoding-profiles.ts
index 92971210c..34a364415 100644
--- a/server/lib/transcoding/video-transcoding-profiles.ts
+++ b/server/lib/transcoding/video-transcoding-profiles.ts
@@ -1,6 +1,7 @@
1
1import { logger } from '@server/helpers/logger' 2import { logger } from '@server/helpers/logger'
2import { getAverageBitrate } from '@shared/core-utils' 3import { getAverageBitrate, getMinLimitBitrate } from '@shared/core-utils'
3import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptionsBuilderParams } from '../../../shared/models/videos' 4import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptionsBuilderParams, VideoResolution } from '../../../shared/models/videos'
4import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils' 5import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils'
5import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBitrate } from '../../helpers/ffprobe-utils' 6import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBitrate } from '../../helpers/ffprobe-utils'
6 7
@@ -15,10 +16,10 @@ import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBi
15 */ 16 */
16 17
17const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => { 18const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => {
18 const { fps, inputRatio, inputBitrate } = options 19 const { fps, inputRatio, inputBitrate, resolution } = options
19 if (!fps) return { outputOptions: [ ] } 20 if (!fps) return { outputOptions: [ ] }
20 21
21 const targetBitrate = capBitrate(inputBitrate, getAverageBitrate({ ...options, fps, ratio: inputRatio })) 22 const targetBitrate = getTargetBitrate({ inputBitrate, ratio: inputRatio, fps, resolution })
22 23
23 return { 24 return {
24 outputOptions: [ 25 outputOptions: [
@@ -31,9 +32,9 @@ const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOpt
31} 32}
32 33
33const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => { 34const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => {
34 const { streamNum, fps, inputBitrate, inputRatio } = options 35 const { streamNum, fps, inputBitrate, inputRatio, resolution } = options
35 36
36 const targetBitrate = capBitrate(inputBitrate, getAverageBitrate({ ...options, fps, ratio: inputRatio })) 37 const targetBitrate = getTargetBitrate({ inputBitrate, ratio: inputRatio, fps, resolution })
37 38
38 return { 39 return {
39 outputOptions: [ 40 outputOptions: [
@@ -234,6 +235,20 @@ export {
234 235
235// --------------------------------------------------------------------------- 236// ---------------------------------------------------------------------------
236 237
238function getTargetBitrate (options: {
239 inputBitrate: number
240 resolution: VideoResolution
241 ratio: number
242 fps: number
243}) {
244 const { inputBitrate, resolution, ratio, fps } = options
245
246 const capped = capBitrate(inputBitrate, getAverageBitrate({ resolution, fps, ratio }))
247 const limit = getMinLimitBitrate({ resolution, fps, ratio })
248
249 return Math.max(limit, capped)
250}
251
237function capBitrate (inputBitrate: number, targetBitrate: number) { 252function capBitrate (inputBitrate: number, targetBitrate: number) {
238 if (!inputBitrate) return targetBitrate 253 if (!inputBitrate) return targetBitrate
239 254