1 import { VideoTranscodingFPS } from './video-transcoding-fps.model'
3 export enum VideoResolution {
12 * Bitrate targets for different resolutions, at VideoTranscodingFPS.AVERAGE.
14 * Sources for individual quality levels:
15 * Google Live Encoder: https://support.google.com/youtube/answer/2853702?hl=en
16 * YouTube Video Info (tested with random music video): https://www.h3xed.com/blogmedia/youtube-info.php
18 export function getBaseBitrate (resolution: VideoResolution) {
20 case VideoResolution.H_240P:
21 // quality according to Google Live Encoder: 300 - 700 Kbps
22 // Quality according to YouTube Video Info: 186 Kbps
24 case VideoResolution.H_360P:
25 // quality according to Google Live Encoder: 400 - 1,000 Kbps
26 // Quality according to YouTube Video Info: 480 Kbps
28 case VideoResolution.H_480P:
29 // quality according to Google Live Encoder: 500 - 2,000 Kbps
30 // Quality according to YouTube Video Info: 879 Kbps
32 case VideoResolution.H_720P:
33 // quality according to Google Live Encoder: 1,500 - 4,000 Kbps
34 // Quality according to YouTube Video Info: 1752 Kbps
36 case VideoResolution.H_1080P: // fallthrough
38 // quality according to Google Live Encoder: 3000 - 6000 Kbps
39 // Quality according to YouTube Video Info: 3277 Kbps
45 * Calculate the target bitrate based on video resolution and FPS.
47 export function getTargetBitrate (resolution: VideoResolution, fps: number,
48 fpsTranscodingConstants: VideoTranscodingFPS) {
49 const baseBitrate = getBaseBitrate(resolution)
50 // The maximum bitrate, used when fps === VideoTranscodingFPS.MAX
51 // Based on numbers from Youtube, 60 fps bitrate divided by 30 fps bitrate:
52 // 720p: 2600 / 1750 = 1.48571428571
53 // 1080p: 4400 / 3300 = 1.33333333333
54 const maxBitrate = baseBitrate * 1.4
55 const maxBitrateDifference = maxBitrate - baseBitrate
56 const maxFpsDifference = fpsTranscodingConstants.MAX - fpsTranscodingConstants.AVERAGE
57 // For 1080p video with default settings, this results in the following formula:
58 // 3300 + (x - 30) * (1320/30)
60 // 1080p10: 2420 kbps, 1080p30: 3300 kbps, 1080p60: 4620 kbps
61 // 720p10: 1283 kbps, 720p30: 1750 kbps, 720p60: 2450
62 return baseBitrate + (fps - fpsTranscodingConstants.AVERAGE) * (maxBitrateDifference / maxFpsDifference)
66 * The maximum bitrate we expect to see on a transcoded video in bytes per second.
68 export function getMaxBitrate (resolution: VideoResolution, fps: number,
69 fpsTranscodingConstants: VideoTranscodingFPS) {
70 return getTargetBitrate(resolution, fps, fpsTranscodingConstants) * 2