]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/ffmpeg/ffprobe-utils.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / helpers / ffmpeg / ffprobe-utils.ts
index 7bcd27665829756d5b8b4706ff09c97573b20445..2c6253d44fc50ca576c7ddccc1f2abbbda70985c 100644 (file)
@@ -56,16 +56,17 @@ async function getVideoStreamCodec (path: string) {
   }
 
   if (videoCodec === 'av01') {
-    const level = videoStream.level
+    let level = videoStream.level.toString()
+    if (level.length === 1) level = `0${level}`
 
     // Guess the tier indicator and bit depth
     return `${videoCodec}.${baseProfile}.${level}M.08`
   }
 
-  // Default, h264 codec
   let level = videoStream.level.toString(16)
   if (level.length === 1) level = `0${level}`
 
+  // Default, h264 codec
   return `${videoCodec}.${baseProfile}${level}`
 }
 
@@ -91,11 +92,12 @@ async function getAudioStreamCodec (path: string, existingProbe?: FfprobeData) {
 // ---------------------------------------------------------------------------
 
 function computeResolutionsToTranscode (options: {
-  inputResolution: number
+  input: number
   type: 'vod' | 'live'
-  includeInputResolution: boolean
+  includeInput: boolean
+  strictLower: boolean
 }) {
-  const { inputResolution, type, includeInputResolution } = options
+  const { input, type, includeInput, strictLower } = options
 
   const configResolutions = type === 'vod'
     ? CONFIG.TRANSCODING.RESOLUTIONS
@@ -117,13 +119,18 @@ function computeResolutionsToTranscode (options: {
   ]
 
   for (const resolution of availableResolutions) {
-    if (configResolutions[resolution + 'p'] === true && inputResolution > resolution) {
-      resolutionsEnabled.add(resolution)
-    }
+    // Resolution not enabled
+    if (configResolutions[resolution + 'p'] !== true) continue
+    // Too big resolution for input file
+    if (input < resolution) continue
+    // We only want lower resolutions than input file
+    if (strictLower && input === resolution) continue
+
+    resolutionsEnabled.add(resolution)
   }
 
-  if (includeInputResolution) {
-    resolutionsEnabled.add(inputResolution)
+  if (includeInput) {
+    resolutionsEnabled.add(input)
   }
 
   return Array.from(resolutionsEnabled)
@@ -157,7 +164,7 @@ async function canDoQuickAudioTranscode (path: string, probe?: FfprobeData): Pro
 
   const channelLayout = parsedAudio.audioStream['channel_layout']
   // Causes playback issues with Chrome
-  if (!channelLayout || channelLayout === 'unknown') return false
+  if (!channelLayout || channelLayout === 'unknown' || channelLayout === 'quad') return false
 
   return true
 }