]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/core-utils/videos/bitrate.ts
Translated using Weblate (Persian)
[github/Chocobozzz/PeerTube.git] / shared / core-utils / videos / bitrate.ts
index a6712f8a4a8abafb333fbe17ed9d6f694af5c8d9..6be0278267a6f88edbcc59c3ba57679ff3b460f4 100644 (file)
@@ -1,11 +1,24 @@
-import { VideoResolution } from "@shared/models"
+import { VideoResolution } from '@shared/models'
 
 type BitPerPixel = { [ id in VideoResolution ]: number }
 
 // https://bitmovin.com/video-bitrate-streaming-hls-dash/
 
+const minLimitBitPerPixel: BitPerPixel = {
+  [VideoResolution.H_NOVIDEO]: 0,
+  [VideoResolution.H_144P]: 0.02,
+  [VideoResolution.H_240P]: 0.02,
+  [VideoResolution.H_360P]: 0.02,
+  [VideoResolution.H_480P]: 0.02,
+  [VideoResolution.H_720P]: 0.02,
+  [VideoResolution.H_1080P]: 0.02,
+  [VideoResolution.H_1440P]: 0.02,
+  [VideoResolution.H_4K]: 0.02
+}
+
 const averageBitPerPixel: BitPerPixel = {
   [VideoResolution.H_NOVIDEO]: 0,
+  [VideoResolution.H_144P]: 0.19,
   [VideoResolution.H_240P]: 0.17,
   [VideoResolution.H_360P]: 0.15,
   [VideoResolution.H_480P]: 0.12,
@@ -17,6 +30,7 @@ const averageBitPerPixel: BitPerPixel = {
 
 const maxBitPerPixel: BitPerPixel = {
   [VideoResolution.H_NOVIDEO]: 0,
+  [VideoResolution.H_144P]: 0.32,
   [VideoResolution.H_240P]: 0.29,
   [VideoResolution.H_360P]: 0.26,
   [VideoResolution.H_480P]: 0.22,
@@ -26,7 +40,7 @@ const maxBitPerPixel: BitPerPixel = {
   [VideoResolution.H_4K]: 0.14
 }
 
-function getAverageBitrate (options: {
+function getAverageTheoreticalBitrate (options: {
   resolution: VideoResolution
   ratio: number
   fps: number
@@ -37,7 +51,7 @@ function getAverageBitrate (options: {
   return targetBitrate
 }
 
-function getMaxBitrate (options: {
+function getMaxTheoreticalBitrate (options: {
   resolution: VideoResolution
   ratio: number
   fps: number
@@ -48,11 +62,23 @@ function getMaxBitrate (options: {
   return targetBitrate
 }
 
+function getMinTheoreticalBitrate (options: {
+  resolution: VideoResolution
+  ratio: number
+  fps: number
+}) {
+  const minLimitBitrate = calculateBitrate({ ...options, bitPerPixel: minLimitBitPerPixel })
+  if (!minLimitBitrate) return 10 * 1000
+
+  return minLimitBitrate
+}
+
 // ---------------------------------------------------------------------------
 
 export {
-  getAverageBitrate,
-  getMaxBitrate
+  getAverageTheoreticalBitrate,
+  getMaxTheoreticalBitrate,
+  getMinTheoreticalBitrate
 }
 
 // ---------------------------------------------------------------------------
@@ -73,6 +99,7 @@ function calculateBitrate (options: {
     VideoResolution.H_480P,
     VideoResolution.H_360P,
     VideoResolution.H_240P,
+    VideoResolution.H_144P,
     VideoResolution.H_NOVIDEO
   ]