From d218e7de9400938ae6ac593d9ae5842e23abd4f0 Mon Sep 17 00:00:00 2001
From: Chocobozzz <me@florianbigard.com>
Date: Fri, 20 Nov 2020 15:06:56 +0100
Subject: Do not transcode to an higher bitrate

Thanks bkil https://github.com/bkil
---
 server/helpers/ffmpeg-utils.ts | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'server/helpers')

diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index 1d610eff2..c8d6969ff 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -674,7 +674,12 @@ async function presetH264 (command: ffmpeg.FfmpegCommand, input: string, resolut
     // Constrained Encoding (VBV)
     // https://slhck.info/video/2017/03/01/rate-control.html
     // https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate
-    const targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS)
+    let targetBitrate = getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS)
+
+    // Don't transcode to an higher bitrate than the original file
+    const fileBitrate = await getVideoFileBitrate(input)
+    targetBitrate = Math.min(targetBitrate, fileBitrate)
+
     localCommand = localCommand.outputOptions([ `-maxrate ${targetBitrate}`, `-bufsize ${targetBitrate * 2}` ])
 
     // Keyframe interval of 2 seconds for faster seeking and resolution switching.
-- 
cgit v1.2.3