X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fffmpeg%2Fffprobe-utils.ts;h=9746c2046e815a84f8909a63cac982e40f24555a;hb=6c38f40d966eb25e53ac38174153cb1fef0475f5;hp=07bcf01f45a0f08c6644ec8d04e2613a2a5752e4;hpb=7b51ede977c299a74728171d8c124bcc4cbba6ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/ffmpeg/ffprobe-utils.ts b/server/helpers/ffmpeg/ffprobe-utils.ts index 07bcf01f4..9746c2046 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' @@ -79,6 +79,7 @@ async function getAudioStreamCodec (path: string, existingProbe?: FfprobeData) { if (audioCodecName === 'opus') return 'opus' if (audioCodecName === 'vorbis') return 'vorbis' if (audioCodecName === 'aac') return 'mp4a.40.2' + if (audioCodecName === 'mp3') return 'mp4a.40.34' logger.warn('Cannot get audio codec of %s.', path, { audioStream }) @@ -89,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() // Put in the order we want to proceed jobs - const resolutions: VideoResolution[] = [ + const availableResolutions: VideoResolution[] = [ VideoResolution.H_NOVIDEO, VideoResolution.H_480P, VideoResolution.H_360P, @@ -109,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) } // --------------------------------------------------------------------------- @@ -146,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 } @@ -223,7 +240,7 @@ export { computeFPS, getClosestFramerateStandard, - computeLowerResolutionsToTranscode, + computeResolutionsToTranscode, canDoQuickTranscode, canDoQuickVideoTranscode,