From 735947ee045dbedd7c5195457ddd88782ca553b3 Mon Sep 17 00:00:00 2001 From: HaveAGitGat <43864057+HaveAGitGat@users.noreply.github.com> Date: Tue, 8 Aug 2023 07:18:24 +0100 Subject: [PATCH] Set gpu device --- .../Tdarr_Plugin_00td_action_transcode.js | 18 +++++++++++++----- .../Tdarr_Plugin_00td_action_transcode.js | 4 ++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Community/Tdarr_Plugin_00td_action_transcode.js b/Community/Tdarr_Plugin_00td_action_transcode.js index b07f90a..77b5230 100644 --- a/Community/Tdarr_Plugin_00td_action_transcode.js +++ b/Community/Tdarr_Plugin_00td_action_transcode.js @@ -217,7 +217,7 @@ const getBestNvencDevice = async ({ }) => { const { execSync } = require('child_process'); let gpu_num = -1; - let gpu_util = 100000; + let lowest_gpu_util = 100000; let result_util = 0; let gpu_count = -1; let gpu_names = ''; @@ -237,6 +237,7 @@ const getBestNvencDevice = async ({ response.infoLog += 'Error in reading nvidia-smi output! \n'; // response.infoLog += error.message; } + if (gpu_count > 0) { for (let gpui = 0; gpui < gpu_count; gpui++) { // Check if GPU # is in GPUs to exclude @@ -248,9 +249,10 @@ const getBestNvencDevice = async ({ result_util = parseInt(execSync(cmd_gpu), 10); if (!Number.isNaN(result_util)) { // != "No devices were found") { response.infoLog += `GPU ${gpui} : Utilization ${result_util}%\n`; - if (result_util < gpu_util) { + + if (result_util < lowest_gpu_util) { gpu_num = gpui; - gpu_util = result_util; + lowest_gpu_util = result_util; } } } catch (error) { @@ -262,6 +264,8 @@ const getBestNvencDevice = async ({ if (gpu_num >= 0) { // eslint-disable-next-line no-param-reassign nvencDevice.inputArgs = `-hwaccel_device ${gpu_num}`; + // eslint-disable-next-line no-param-reassign + nvencDevice.outputArgs = `-gpu ${gpu_num}`; } return nvencDevice; @@ -586,9 +590,13 @@ const plugin = async (file, librarySettings, inputs, otherArguments) => { } } + const vEncode = `-cq:v 19 ${bitrateSettings}`; + response.preset += ` ${encoderProperties.inputArgs ? encoderProperties.inputArgs : ''} ${genpts}` - + ` -map 0 -c copy -c:v ${encoderProperties.encoder} -cq:v 19 ${bitrateSettings} ` - + `-spatial_aq:v 1 -rc-lookahead:v 32 -max_muxing_queue_size 9999 ${extraArguments}`; + + ` -map 0 -c copy -c:v ${encoderProperties.encoder}` + + ` ${encoderProperties.outputArgs ? encoderProperties.outputArgs : ''}` + + ` ${vEncode}` + + ` -spatial_aq:v 1 -rc-lookahead:v 32 -max_muxing_queue_size 9999 ${extraArguments}`; response.processFile = true; response.infoLog += `File is not in ${inputs.target_codec}. Transcoding. \n`; return response; diff --git a/tests/Community/Tdarr_Plugin_00td_action_transcode.js b/tests/Community/Tdarr_Plugin_00td_action_transcode.js index bb2ded6..5055986 100644 --- a/tests/Community/Tdarr_Plugin_00td_action_transcode.js +++ b/tests/Community/Tdarr_Plugin_00td_action_transcode.js @@ -12,7 +12,7 @@ const tests = [ }, output: { processFile: true, - preset: ' -map 0 -c copy -c:v libx265 -cq:v 19 -b:v 795571.5361445782 -minrate 556900.0753012047 -maxrate 1034242.9969879518 -bufsize 1591143.0722891565 -spatial_aq:v 1 -rc-lookahead:v 32 -max_muxing_queue_size 9999 ', + preset: ' -map 0 -c copy -c:v libx265 -cq:v 19 -b:v 795571.5361445782 -minrate 556900.0753012047 -maxrate 1034242.9969879518 -bufsize 1591143.0722891565 -spatial_aq:v 1 -rc-lookahead:v 32 -max_muxing_queue_size 9999 ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true, @@ -65,7 +65,7 @@ const tests = [ }, output: { processFile: true, - preset: ' -map 0 -c copy -c:v libx265 -cq:v 19 -b:v 1193357.3042168673 -minrate 835350.1129518071 -maxrate 1551364.4954819276 -bufsize 1591143.0722891565 -spatial_aq:v 1 -rc-lookahead:v 32 -max_muxing_queue_size 9999 ', + preset: ' -map 0 -c copy -c:v libx265 -cq:v 19 -b:v 1193357.3042168673 -minrate 835350.1129518071 -maxrate 1551364.4954819276 -bufsize 1591143.0722891565 -spatial_aq:v 1 -rc-lookahead:v 32 -max_muxing_queue_size 9999 ', handBrakeMode: false, FFmpegMode: true, reQueueAfter: true,