aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/transcoding
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-06 13:35:25 +0200
committerChocobozzz <me@florianbigard.com>2021-08-06 14:13:26 +0200
commit679c12e69c9f3a2d003ee3abe8b8da49f25b2bd3 (patch)
tree03abf589275db05e5b1fa1c89f57049cd807324a /server/lib/transcoding
parentc826f34a45757b324a20f71665b44ed10e6953b5 (diff)
downloadPeerTube-679c12e69c9f3a2d003ee3abe8b8da49f25b2bd3.tar.gz
PeerTube-679c12e69c9f3a2d003ee3abe8b8da49f25b2bd3.tar.zst
PeerTube-679c12e69c9f3a2d003ee3abe8b8da49f25b2bd3.zip
Improve target bitrate calculation
Diffstat (limited to 'server/lib/transcoding')
-rw-r--r--server/lib/transcoding/video-transcoding-profiles.ts32
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 @@
1import { logger } from '@server/helpers/logger' 1import { logger } from '@server/helpers/logger'
2import { AvailableEncoders, EncoderOptionsBuilder, getTargetBitrate, VideoResolution } from '../../../shared/models/videos' 2import { getAverageBitrate } from '@shared/core-utils'
3import { AvailableEncoders, EncoderOptionsBuilder, EncoderOptionsBuilderParams } from '../../../shared/models/videos'
3import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils' 4import { buildStreamSuffix, resetSupportedEncoders } from '../../helpers/ffmpeg-utils'
4import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBitrate } from '../../helpers/ffprobe-utils' 5import { canDoQuickAudioTranscode, ffprobePromise, getAudioStream, getMaxAudioBitrate } from '../../helpers/ffprobe-utils'
5import { 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: 17const 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
18const 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
32const defaultX264LiveOptionsBuilder: EncoderOptionsBuilder = async ({ resolution, fps, inputBitrate, streamNum }) => { 33const 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
234function buildTargetBitrate (options: { 237function 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)