X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fmodels%2Fvideos%2Fvideo-resolution.enum.ts;h=06e0779617f908386d839c6c8b9e7ed2246fc651;hb=7cd1b12c19d0589d1d692ed0571ca0800f028aea;hp=13c0fe9a74d3dfe821c0349bc8258d8a147761e6;hpb=7f196c9320ab010fcf659dbf819d83dded5eeb7f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/models/videos/video-resolution.enum.ts b/shared/models/videos/video-resolution.enum.ts index 13c0fe9a7..06e077961 100644 --- a/shared/models/videos/video-resolution.enum.ts +++ b/shared/models/videos/video-resolution.enum.ts @@ -1,11 +1,13 @@ import { VideoTranscodingFPS } from './video-transcoding-fps.model' export enum VideoResolution { + H_NOVIDEO = 0, H_240P = 240, H_360P = 360, H_480P = 480, H_720P = 720, - H_1080P = 1080 + H_1080P = 1080, + H_4K = 2160 } /** @@ -13,57 +15,75 @@ export enum VideoResolution { * * 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 + * YouTube Video Info: youtube-dl --list-formats, with sample videos */ -export function getBaseBitrate (resolution: VideoResolution) { +function getBaseBitrate (resolution: VideoResolution) { switch (resolution) { - case VideoResolution.H_240P: - // quality according to Google Live Encoder: 300 - 700 Kbps - // Quality according to YouTube Video Info: 186 Kbps - return 250 * 1000 - case VideoResolution.H_360P: - // quality according to Google Live Encoder: 400 - 1,000 Kbps - // Quality according to YouTube Video Info: 480 Kbps - return 500 * 1000 - case VideoResolution.H_480P: - // quality according to Google Live Encoder: 500 - 2,000 Kbps - // Quality according to YouTube Video Info: 879 Kbps - return 900 * 1000 - case VideoResolution.H_720P: - // 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: - // quality according to Google Live Encoder: 3000 - 6000 Kbps - // Quality according to YouTube Video Info: 3277 Kbps - return 3300 * 1000 + case VideoResolution.H_NOVIDEO: + // audio-only + return 64 * 1000 + + case VideoResolution.H_240P: + // quality according to Google Live Encoder: 300 - 700 Kbps + // Quality according to YouTube Video Info: 285 Kbps + return 320 * 1000 + + case VideoResolution.H_360P: + // quality according to Google Live Encoder: 400 - 1,000 Kbps + // Quality according to YouTube Video Info: 700 Kbps + return 780 * 1000 + + case VideoResolution.H_480P: + // quality according to Google Live Encoder: 500 - 2,000 Kbps + // Quality according to YouTube Video Info: 1300 Kbps + return 1500 * 1000 + + case VideoResolution.H_720P: + // quality according to Google Live Encoder: 1,500 - 4,000 Kbps + // Quality according to YouTube Video Info: 2680 Kbps + return 2800 * 1000 + + case VideoResolution.H_1080P: + // quality according to Google Live Encoder: 3000 - 6000 Kbps + // Quality according to YouTube Video Info: 5081 Kbps + return 5200 * 1000 + + case VideoResolution.H_4K: // fallthrough + default: + // quality according to Google Live Encoder: 13000 - 34000 Kbps + return 22000 * 1000 } } /** * Calculate the target bitrate based on video resolution and FPS. + * + * The calculation is based on two values: + * Bitrate at VideoTranscodingFPS.AVERAGE is always the same as + * getBaseBitrate(). Bitrate at VideoTranscodingFPS.MAX is always + * getBaseBitrate() * 1.4. All other values are calculated linearly + * between these two points. */ -export function getTargetBitrate (resolution: VideoResolution, fps: number, - fpsTranscodingConstants: VideoTranscodingFPS) { +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 + // 720p: 2600 / 1750 = 1.49 + // 1080p: 4400 / 3300 = 1.33 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 + // Example outputs: + // 1080p10: 2420 kbps, 1080p30: 3300 kbps, 1080p60: 4620 kbps + // 720p10: 1283 kbps, 720p30: 1750 kbps, 720p60: 2450 kbps return baseBitrate + (fps - fpsTranscodingConstants.AVERAGE) * (maxBitrateDifference / maxFpsDifference) } /** * The maximum bitrate we expect to see on a transcoded video in bytes per second. */ -export function getMaxBitrate (resolution: VideoResolution, fps: number, - fpsTranscodingConstants: VideoTranscodingFPS) { +export function getMaxBitrate (resolution: VideoResolution, fps: number, fpsTranscodingConstants: VideoTranscodingFPS) { return getTargetBitrate(resolution, fps, fpsTranscodingConstants) * 2 }