X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fffmpeg%2Fffprobe-utils.ts;h=2c6253d44fc50ca576c7ddccc1f2abbbda70985c;hb=91a4893063402d7beabb3104f9b989b8f88b6038;hp=a9b4fb456e34dac2795412ee00e923d859af1d85;hpb=3d401c1b3d12cec6bdb80b69e1ac30a151448e10;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/ffmpeg/ffprobe-utils.ts b/server/helpers/ffmpeg/ffprobe-utils.ts index a9b4fb456..2c6253d44 100644 --- a/server/helpers/ffmpeg/ffprobe-utils.ts +++ b/server/helpers/ffmpeg/ffprobe-utils.ts @@ -1,15 +1,15 @@ import { FfprobeData } from 'fluent-ffmpeg' import { getMaxBitrate } from '@shared/core-utils' import { + buildFileMetadata, ffprobePromise, getAudioStream, - getVideoStreamDuration, getMaxAudioBitrate, - buildFileMetadata, - getVideoStreamBitrate, - getVideoStreamFPS, getVideoStream, + getVideoStreamBitrate, getVideoStreamDimensionsInfo, + getVideoStreamDuration, + getVideoStreamFPS, hasAudioStream } from '@shared/extra-utils/ffprobe' import { VideoResolution, VideoTranscodingFPS } from '@shared/models' @@ -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}` } @@ -90,15 +91,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() // 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 +118,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 +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 } @@ -224,7 +241,7 @@ export { computeFPS, getClosestFramerateStandard, - computeLowerResolutionsToTranscode, + computeResolutionsToTranscode, canDoQuickTranscode, canDoQuickVideoTranscode,