X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fffmpeg-utils.ts;h=78f9ba07cc2592f66e308f1aa8e673508cf02869;hb=06bcfbd9f715055f2f00bb66149b1dba926d007a;hp=1eea05d1edaaaeeaecc8cce6b8dfaf052c38bd20;hpb=52201311e1973a12960466232d4dec861e8258ee;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index 1eea05d1e..78f9ba07c 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts @@ -70,7 +70,7 @@ async function getAudioStreamCodec (path: string) { if (!audioStream) return '' const audioCodec = audioStream.codec_name - if (audioCodec.codec_name === 'aac') return 'mp4a.40.2' + if (audioCodec === 'aac') return 'mp4a.40.2' logger.warn('Cannot get audio codec of %s.', path, { audioStream }) @@ -286,13 +286,16 @@ export { async function buildx264Command (command: ffmpeg.FfmpegCommand, options: TranscodeOptions) { let fps = await getVideoFileFPS(options.inputPath) - // On small/medium resolutions, limit FPS if ( + // On small/medium resolutions, limit FPS options.resolution !== undefined && options.resolution < VIDEO_TRANSCODING_FPS.KEEP_ORIGIN_FPS_RESOLUTION_MIN && - fps > VIDEO_TRANSCODING_FPS.AVERAGE + fps > VIDEO_TRANSCODING_FPS.AVERAGE || + // If the video is doesn't match had standard + !VIDEO_TRANSCODING_FPS.HD_STANDARD.map(value => fps % value).includes(0) ) { - 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 = VIDEO_TRANSCODING_FPS.STANDARD.sort((a, b) => fps % a - fps % b)[0] } command = await presetH264(command, options.inputPath, options.resolution, fps) @@ -305,7 +308,7 @@ async function buildx264Command (command: ffmpeg.FfmpegCommand, options: Transco if (fps) { // Hard FPS limits - if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = VIDEO_TRANSCODING_FPS.MAX + if (fps > VIDEO_TRANSCODING_FPS.MAX) fps = VIDEO_TRANSCODING_FPS.HD_STANDARD.sort((a, b) => fps % a - fps % b)[0] else if (fps < VIDEO_TRANSCODING_FPS.MIN) fps = VIDEO_TRANSCODING_FPS.MIN command = command.withFPS(fps)