]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/models/videos/video-resolution.enum.ts
Refactor how we use icons
[github/Chocobozzz/PeerTube.git] / shared / models / videos / video-resolution.enum.ts
index 4d2644cc0b99cb3edf3c48b8c88c8b89673bd09f..7da5e71004dc1f061ece37e0c53b0daab9fdc081 100644 (file)
@@ -15,7 +15,7 @@ export enum VideoResolution {
  * 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 getBaseBitrate (resolution: VideoResolution) {
+function getBaseBitrate (resolution: VideoResolution) {
   switch (resolution) {
   case VideoResolution.H_240P:
     // quality according to Google Live Encoder: 300 - 700 Kbps
@@ -43,14 +43,19 @@ export function getBaseBitrate (resolution: VideoResolution) {
 
 /**
  * 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:
-  //  720p: 2600 / 1750 = 1.48571428571
-  // 1080p: 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
@@ -58,14 +63,13 @@ export function getTargetBitrate (resolution: VideoResolution, fps: number,
   // 3300 + (x - 30) * (1320/30)
   // Example outputs:
   // 1080p10: 2420 kbps, 1080p30: 3300 kbps, 1080p60: 4620 kbps
-  //  720p10: 1283 kbps,  720p30: 1750 kbps,  720p60: 2450
+  //  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
 }