X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fffprobe-utils.ts;h=adb459ed39042b67e13c0f8b8af8a0e9fb6b1bd4;hb=d223dca0cd50010d1c4455e5eec1736b1c591aed;hp=d03ab91ac93c23bcdcaca0b0e6c080eb8b0e150e;hpb=33ff70baa64c6315856066682595878a27b7ed8c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/ffprobe-utils.ts b/server/helpers/ffprobe-utils.ts index d03ab91ac..adb459ed3 100644 --- a/server/helpers/ffprobe-utils.ts +++ b/server/helpers/ffprobe-utils.ts @@ -5,6 +5,12 @@ import { CONFIG } from '../initializers/config' import { VIDEO_TRANSCODING_FPS } from '../initializers/constants' import { logger } from './logger' +/** + * + * Helpers to run ffprobe and extract data from the JSON output + * + */ + function ffprobePromise (path: string) { return new Promise((res, rej) => { ffmpeg.ffprobe(path, (err, data) => { @@ -158,7 +164,7 @@ async function getVideoFileBitrate (path: string, existingProbe?: ffmpeg.Ffprobe async function getDurationFromVideoFile (path: string, existingProbe?: ffmpeg.FfprobeData) { const metadata = await getMetadataFromFile(path, existingProbe) - return Math.floor(metadata.format.duration) + return Math.round(metadata.format.duration) } async function getVideoStreamFromFile (path: string, existingProbe?: ffmpeg.FfprobeData) { @@ -182,6 +188,7 @@ function computeResolutionsToTranscode (videoFileResolution: number, type: 'vod' VideoResolution.H_720P, VideoResolution.H_240P, VideoResolution.H_1080P, + VideoResolution.H_1440P, VideoResolution.H_4K ] @@ -241,6 +248,26 @@ function getClosestFramerateStandard (fps: number, type: 'HD_STANDARD' | 'STANDA .sort((a, b) => fps % a - fps % b)[0] } +function computeFPS (fpsArg: number, resolution: VideoResolution) { + let fps = fpsArg + + if ( + // On small/medium resolutions, limit FPS + resolution !== undefined && + resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && + fps > VIDEO_TRANSCODING_FPS.AVERAGE + ) { + // Get closest standard framerate by modulo: downsampling has to be done to a divisor of the nominal fps value + fps = getClosestFramerateStandard(fps, 'STANDARD') + } + + // Hard FPS limits + if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = getClosestFramerateStandard(fps, 'HD_STANDARD') + else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN + + return fps +} + // --------------------------------------------------------------------------- export { @@ -253,6 +280,7 @@ export { getVideoStreamFromFile, getDurationFromVideoFile, getAudioStream, + computeFPS, getVideoFileFPS, ffprobePromise, getClosestFramerateStandard,