diff options
author | Chocobozzz <me@florianbigard.com> | 2021-11-10 11:04:00 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-11-10 11:04:00 +0100 |
commit | 67eeec8b955339120ff5d3c8286fdf0715e6270c (patch) | |
tree | ec28e8c218ed4e80f5f1f86f59fe2acb360950a9 /server/lib/transcoding | |
parent | 93904032506dd222404d9be60fd2e41763554665 (diff) | |
download | PeerTube-67eeec8b955339120ff5d3c8286fdf0715e6270c.tar.gz PeerTube-67eeec8b955339120ff5d3c8286fdf0715e6270c.tar.zst PeerTube-67eeec8b955339120ff5d3c8286fdf0715e6270c.zip |
Add minimum bitrate limit
Diffstat (limited to 'server/lib/transcoding')
-rw-r--r-- | server/lib/transcoding/video-transcoding-profiles.ts | 27 |
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 | |||
1 | import { logger } from '@server/helpers/logger' | 2 | import { logger } from '@server/helpers/logger' |
2 | import { getAverageBitrate } from '@shared/core-utils' | 3 | import { getAverageBitrate, getMinLimitBitrate } from '@shared/core-utils' |
3 | import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptionsBuilderParams } from '../../../shared/models/videos' | 4 | import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptionsBuilderParams, VideoResolution } from '../../../shared/models/videos' |
4 | import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils' | 5 | import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils' |
5 | import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBitrate } from '../../helpers/ffprobe-utils' | 6 | import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBitrate } from '../../helpers/ffprobe-utils' |
6 | 7 | ||
@@ -15,10 +16,10 @@ import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBi | |||
15 | */ | 16 | */ |
16 | 17 | ||
17 | const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => { | 18 | const 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 | ||
33 | const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = (options: EncoderOptionsBuilderParams) => { | 34 | const 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 | ||
238 | function 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 | |||
237 | function capBitrate (inputBitrate: number, targetBitrate: number) { | 252 | function capBitrate (inputBitrate: number, targetBitrate: number) { |
238 | if (!inputBitrate) return targetBitrate | 253 | if (!inputBitrate) return targetBitrate |
239 | 254 | ||