diff options
Diffstat (limited to 'server/lib/transcoding')
-rw-r--r-- | server/lib/transcoding/video-transcoding-profiles.ts | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/server/lib/transcoding/video-transcoding-profiles.ts b/server/lib/transcoding/video-transcoding-profiles.ts index 2309f38d4..bca6dfccd 100644 --- a/server/lib/transcoding/video-transcoding-profiles.ts +++ b/server/lib/transcoding/video-transcoding-profiles.ts | |||
@@ -1,23 +1,24 @@ | |||
1 | import { logger } from '@server/helpers/logger' | 1 | import { logger } from '@server/helpers/logger' |
2 | import { AvailableEncoders, EncoderOptionsBuilder, getTargetBitrate, VideoResolution } from '../../../shared/models/videos' | 2 | import { getAverageBitrate } from '@shared/core-utils' |
3 | import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptionsBuilderParams } from '../../../shared/models/videos' | ||
3 | import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils' | 4 | import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils' |
4 | import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBitrate } from '../../helpers/ffprobe-utils' | 5 | import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBitrate } from '../../helpers/ffprobe-utils' |
5 | import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' | ||
6 | 6 | ||
7 | /** | 7 | /** |
8 | * | 8 | * |
9 | * Available encoders and profiles for the transcoding jobs | 9 | * Available encoders and profiles for the transcoding jobs |
10 | * These functions are used by ffmpeg-utils that will get the encoders and options depending on the chosen profile | 10 | * These functions are used by ffmpeg-utils that will get the encoders and options depending on the chosen profile |
11 | * | 11 | * |
12 | * Resources: | ||
13 | * * https://slhck.info/video/2017/03/01/rate-control.html | ||
14 | * * https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate | ||
12 | */ | 15 | */ |
13 | 16 | ||
14 | // Resources: | 17 | const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async (options: EncoderOptionsBuilderParams) => { |
15 | // * https://slhck.info/video/2017/03/01/rate-control.html | 18 | const { fps, inputRatio, inputBitrate } = options |
16 | // * https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate | 19 | if (!fps) return { outputOptions: [ ] } |
17 | 20 | ||
18 | const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async ({ inputBitrate, resolution, fps }) => { | 21 | const targetBitrate = capBitrate(inputBitrate, getAverageBitrate({ ...options, fps, ratio: inputRatio })) |
19 | const targetBitrate = buildTargetBitrate({ inputBitrate, resolution, fps }) | ||
20 | if (!targetBitrate) return { outputOptions: [ ] } | ||
21 | 22 | ||
22 | return { | 23 | return { |
23 | outputOptions: [ | 24 | outputOptions: [ |
@@ -29,8 +30,10 @@ const defaultX264VODOptionsBuilder: EncoderOptionsBuilder = async ({ inputBitrat | |||
29 | } | 30 | } |
30 | } | 31 | } |
31 | 32 | ||
32 | const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = async ({ resolution, fps, inputBitrate, streamNum }) => { | 33 | const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = async (options: EncoderOptionsBuilderParams) => { |
33 | const targetBitrate = buildTargetBitrate({ inputBitrate, resolution, fps }) | 34 | const { streamNum, fps, inputBitrate, inputRatio } = options |
35 | |||
36 | const targetBitrate = capBitrate(inputBitrate, getAverageBitrate({ ...options, fps, ratio: inputRatio })) | ||
34 | 37 | ||
35 | return { | 38 | return { |
36 | outputOptions: [ | 39 | outputOptions: [ |
@@ -231,14 +234,7 @@ export { | |||
231 | 234 | ||
232 | // --------------------------------------------------------------------------- | 235 | // --------------------------------------------------------------------------- |
233 | 236 | ||
234 | function buildTargetBitrate (options: { | 237 | function capBitrate (inputBitrate: number, targetBitrate: number) { |
235 | inputBitrate: number | ||
236 | resolution: VideoResolution | ||
237 | fps: number | ||
238 | }) { | ||
239 | const { inputBitrate, resolution, fps } = options | ||
240 | |||
241 | const targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS) | ||
242 | if (!inputBitrate) return targetBitrate | 238 | if (!inputBitrate) return targetBitrate |
243 | 239 | ||
244 | return Math.min(targetBitrate, inputBitrate) | 240 | return Math.min(targetBitrate, inputBitrate) |