From: Felix Ableitner Date: Tue, 9 Oct 2018 22:46:26 +0000 (-0500) Subject: Scale bitrate linearly with FPS X-Git-Tag: v1.1.0-alpha.2~31 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=7f196c9320ab010fcf659dbf819d83dded5eeb7f;p=github%2FChocobozzz%2FPeerTube.git Scale bitrate linearly with FPS --- diff --git a/shared/models/videos/video-resolution.enum.ts b/shared/models/videos/video-resolution.enum.ts index e40e5b58b..13c0fe9a7 100644 --- a/shared/models/videos/video-resolution.enum.ts +++ b/shared/models/videos/video-resolution.enum.ts @@ -9,13 +9,13 @@ export enum VideoResolution { } /** - * Bitrate targets for different resolutions and frame rates, in bytes per second. + * Bitrate targets for different resolutions, at VideoTranscodingFPS.AVERAGE. + * * Sources for individual quality levels: * Google Live Encoder: https://support.google.com/youtube/answer/2853702?hl=en * YouTube Video Info (tested with random music video): https://www.h3xed.com/blogmedia/youtube-info.php */ -export function getTargetBitrate (resolution: VideoResolution, fps: number, - fpsTranscodingConstants: VideoTranscodingFPS) { +export function getBaseBitrate (resolution: VideoResolution) { switch (resolution) { case VideoResolution.H_240P: // quality according to Google Live Encoder: 300 - 700 Kbps @@ -30,29 +30,36 @@ export function getTargetBitrate (resolution: VideoResolution, fps: number, // Quality according to YouTube Video Info: 879 Kbps return 900 * 1000 case VideoResolution.H_720P: - if (fps === fpsTranscodingConstants.MAX) { - // quality according to Google Live Encoder: 2,250 - 6,000 Kbps - // Quality according to YouTube Video Info: 2634 Kbps - return 2600 * 1000 - } - // quality according to Google Live Encoder: 1,500 - 4,000 Kbps // Quality according to YouTube Video Info: 1752 Kbps return 1750 * 1000 case VideoResolution.H_1080P: // fallthrough default: - if (fps === fpsTranscodingConstants.MAX) { - // quality according to Google Live Encoder: 3000 - 6000 Kbps - // Quality according to YouTube Video Info: 4387 Kbps - return 4400 * 1000 - } - // quality according to Google Live Encoder: 3000 - 6000 Kbps // Quality according to YouTube Video Info: 3277 Kbps return 3300 * 1000 } } +/** + * Calculate the target bitrate based on video resolution and FPS. + */ +export function getTargetBitrate (resolution: VideoResolution, fps: number, + fpsTranscodingConstants: VideoTranscodingFPS) { + const baseBitrate = getBaseBitrate(resolution) + // The maximum bitrate, used when fps === VideoTranscodingFPS.MAX + // Based on numbers from Youtube, 60 fps bitrate divided by 30 fps bitrate: + // 2600 / 1750 = 1.48571428571 + // 4400 / 3300 = 1.33333333333 + const maxBitrate = baseBitrate * 1.4 + const maxBitrateDifference = maxBitrate - baseBitrate + const maxFpsDifference = fpsTranscodingConstants.MAX - fpsTranscodingConstants.AVERAGE + // For 1080p video with default settings, this results in the following formula: + // 3300 + (x - 30) * (1320/30) + // Example outputs: 1080p30: 3300 kbps, 1080p60: 4620 kbps, 720p30: 1750, 720p60: 2450 + return baseBitrate + (fps - fpsTranscodingConstants.AVERAGE) * (maxBitrateDifference / maxFpsDifference) +} + /** * The maximum bitrate we expect to see on a transcoded video in bytes per second. */