]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/ffmpeg/ffprobe-utils.ts
Prevent weird error on sync failure
[github/Chocobozzz/PeerTube.git] / server / helpers / ffmpeg / ffprobe-utils.ts
index 9529162eb9de6f850a1857569de9e87078fb160b..9746c2046e815a84f8909a63cac982e40f24555a 100644 (file)
@@ -90,15 +90,22 @@ async function getAudioStreamCodec (path: string, existingProbe?: FfprobeData) {
 // Resolutions
 // ---------------------------------------------------------------------------
 
-function computeLowerResolutionsToTranscode (videoFileResolution: number, type: 'vod' | 'live') {
+function computeResolutionsToTranscode (options: {
+  input: number
+  type: 'vod' | 'live'
+  includeInput: boolean
+  strictLower: boolean
+}) {
+  const { input, type, includeInput, strictLower } = options
+
   const configResolutions = type === 'vod'
     ? CONFIG.TRANSCODING.RESOLUTIONS
     : CONFIG.LIVE.TRANSCODING.RESOLUTIONS
 
-  const resolutionsEnabled: number[] = []
+  const resolutionsEnabled = new Set<number>()
 
   // Put in the order we want to proceed jobs
-  const resolutions: VideoResolution[] = [
+  const availableResolutions: VideoResolution[] = [
     VideoResolution.H_NOVIDEO,
     VideoResolution.H_480P,
     VideoResolution.H_360P,
@@ -110,13 +117,22 @@ function computeLowerResolutionsToTranscode (videoFileResolution: number, type:
     VideoResolution.H_4K
   ]
 
-  for (const resolution of resolutions) {
-    if (configResolutions[resolution + 'p'] === true && videoFileResolution > resolution) {
-      resolutionsEnabled.push(resolution)
-    }
+  for (const resolution of availableResolutions) {
+    // 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 (includeInput) {
+    resolutionsEnabled.add(input)
   }
 
-  return resolutionsEnabled
+  return Array.from(resolutionsEnabled)
 }
 
 // ---------------------------------------------------------------------------
@@ -147,7 +163,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
 }
@@ -224,7 +240,7 @@ export {
   computeFPS,
   getClosestFramerateStandard,
 
-  computeLowerResolutionsToTranscode,
+  computeResolutionsToTranscode,
 
   canDoQuickTranscode,
   canDoQuickVideoTranscode,