mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-16 02:35:54 -07:00
Update Tdarr_Plugin_vdka_Tiered_NVENC_CQV_BASED_CONFIGURABLE.js
Made the trash code at least look pretty
This commit is contained in:
parent
414755a543
commit
cae999585b
1 changed files with 108 additions and 109 deletions
|
|
@ -1,60 +1,59 @@
|
||||||
function details() {
|
function details () {
|
||||||
return {
|
return {
|
||||||
id: "Tdarr_Plugin_vdka_Tiered_NVENC_CQV_BASED_CONFIGURABLE",
|
id: 'Tdarr_Plugin_vdka_Tiered_NVENC_CQV_BASED_CONFIGURABLE',
|
||||||
Stage: "Pre-processing",
|
Stage: 'Pre-processing',
|
||||||
Name: "Tiered FFMPEG+NVENC CQ:V BASED CONFIGURABLE",
|
Name: 'Tiered FFMPEG+NVENC CQ:V BASED CONFIGURABLE',
|
||||||
Type: "Video",
|
Type: 'Video',
|
||||||
Operation: "Transcode",
|
Operation: 'Transcode',
|
||||||
Description:
|
Description: `[Contains built-in filter] This plugin uses different CQ:V values (similar to crf but for nvenc) depending on resolution,
|
||||||
`[Contains built-in filter] This plugin uses different CQ:V values (similar to crf but for nvenc) depending on resolution,
|
|
||||||
the CQ:V value is configurable per resolution.
|
the CQ:V value is configurable per resolution.
|
||||||
FFmpeg Preset can be configured, uses slow by default.
|
FFmpeg Preset can be configured, uses slow by default.
|
||||||
ALL OPTIONS MUST BE CONFIGURED UNLESS MARKED OPTIONAL!
|
ALL OPTIONS MUST BE CONFIGURED UNLESS MARKED OPTIONAL!
|
||||||
If files are not in hevc they will be transcoded.
|
If files are not in hevc they will be transcoded.
|
||||||
The output container is mkv. \n\n`,
|
The output container is mkv. \n\n`,
|
||||||
Version: "1.00",
|
Version: '1.00',
|
||||||
Link:
|
Link:
|
||||||
"https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_vdka_Tiered_NVENC_CQV_BASED_CONFIGURABLE.js",
|
'https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_vdka_Tiered_NVENC_CQV_BASED_CONFIGURABLE.js',
|
||||||
Tags: "pre-processing,ffmpeg,video only,nvenc h265,configurable",
|
Tags: 'pre-processing,ffmpeg,video only,nvenc h265,configurable',
|
||||||
|
|
||||||
Inputs: [
|
Inputs: [
|
||||||
{
|
{
|
||||||
name: "sdCQV",
|
name: 'sdCQV',
|
||||||
tooltip: `Enter the CQ:V value you want for 480p and 576p content.
|
tooltip: `Enter the CQ:V value you want for 480p and 576p content.
|
||||||
\\nExample:\\n
|
\\nExample:\\n
|
||||||
|
|
||||||
18`,
|
18`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "hdCQV",
|
name: 'hdCQV',
|
||||||
tooltip: `Enter the CQ:V value you want for 720p content.
|
tooltip: `Enter the CQ:V value you want for 720p content.
|
||||||
|
|
||||||
\\nExample:\\n
|
\\nExample:\\n
|
||||||
17`,
|
17`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "fullhdCQV",
|
name: 'fullhdCQV',
|
||||||
tooltip: `Enter the CQ:V value you want for 1080p content.
|
tooltip: `Enter the CQ:V value you want for 1080p content.
|
||||||
|
|
||||||
\\nExample:\\n
|
\\nExample:\\n
|
||||||
18`,
|
18`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "uhdCQV",
|
name: 'uhdCQV',
|
||||||
tooltip: `Enter the CQ:V value you want for 4K/UHD/2160p content.
|
tooltip: `Enter the CQ:V value you want for 4K/UHD/2160p content.
|
||||||
|
|
||||||
\\nExample:\\n
|
\\nExample:\\n
|
||||||
22`,
|
22`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bframe",
|
name: 'bframe',
|
||||||
tooltip: `Specify amount of b-frames to use, 0-5. Use 0 to disable. (GPU must support this, turing and newer supports this, except for the 1650)
|
tooltip: `Specify amount of b-frames to use, 0-5. Use 0 to disable. (GPU must support this, turing and newer supports this, except for the 1650)
|
||||||
|
|
||||||
\\nExample:\\n
|
\\nExample:\\n
|
||||||
3`,
|
3`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ffmpeg_preset",
|
name: 'ffmpeg_preset',
|
||||||
tooltip: `OPTIONAL, DEFAULTS TO SLOW IF NOT SET
|
tooltip: `OPTIONAL, DEFAULTS TO SLOW IF NOT SET
|
||||||
\\n Enter the ffmpeg preset you want, leave blank for default (slow)
|
\\n Enter the ffmpeg preset you want, leave blank for default (slow)
|
||||||
\\n This only applies if video is transcoded, video already in h264 will not be transcoded with this setting
|
\\n This only applies if video is transcoded, video already in h264 will not be transcoded with this setting
|
||||||
|
|
@ -69,159 +68,159 @@ function details() {
|
||||||
fast
|
fast
|
||||||
|
|
||||||
\\nExample:\\n
|
\\nExample:\\n
|
||||||
veryfast`,
|
veryfast`
|
||||||
},
|
}
|
||||||
],
|
]
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.plugin = function plugin(file, librarySettings, inputs) {
|
module.exports.plugin = function plugin (file, librarySettings, inputs) {
|
||||||
var transcode = 0; //if this var changes to 1 the file will be transcoded
|
var transcode = 0 //if this var changes to 1 the file will be transcoded
|
||||||
var subcli = `-c:s copy`;
|
var subcli = `-c:s copy`
|
||||||
var maxmux = "";
|
var maxmux = ''
|
||||||
var map = "-map 0";
|
var map = '-map 0'
|
||||||
var cqvinuse = "";
|
var cqvinuse = ''
|
||||||
//default values that will be returned
|
//default values that will be returned
|
||||||
var response = {
|
var response = {
|
||||||
processFile: false,
|
processFile: false,
|
||||||
preset: "",
|
preset: '',
|
||||||
container: ".mkv",
|
container: '.mkv',
|
||||||
handBrakeMode: false,
|
handBrakeMode: false,
|
||||||
FFmpegMode: false,
|
FFmpegMode: false,
|
||||||
reQueueAfter: true,
|
reQueueAfter: true,
|
||||||
infoLog: "",
|
infoLog: '',
|
||||||
maxmux: false,
|
maxmux: false
|
||||||
};
|
}
|
||||||
|
|
||||||
//check if the file is a video, if not the function will be stopped immediately
|
//check if the file is a video, if not the function will be stopped immediately
|
||||||
if (file.fileMedium !== "video") {
|
if (file.fileMedium !== 'video') {
|
||||||
response.processFile = false;
|
response.processFile = false
|
||||||
response.infoLog += "☒File is not a video! \n";
|
response.infoLog += '☒File is not a video! \n'
|
||||||
return response;
|
return response
|
||||||
} else {
|
} else {
|
||||||
// bitrateprobe = file.ffProbeData.streams[0].bit_rate;
|
// bitrateprobe = file.ffProbeData.streams[0].bit_rate;
|
||||||
response.infoLog += "☑File is a video! \n";
|
response.infoLog += '☑File is a video! \n'
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if the file is already hevc, it will not be transcoded if true and the function will be stopped immediately
|
//check if the file is already hevc, it will not be transcoded if true and the function will be stopped immediately
|
||||||
if (file.ffProbeData.streams[0].codec_name == "hevc") {
|
if (file.ffProbeData.streams[0].codec_name == 'hevc') {
|
||||||
response.processFile = false;
|
response.processFile = false
|
||||||
response.infoLog += "☑File is already in hevc! \n";
|
response.infoLog += '☑File is already in hevc! \n'
|
||||||
return response;
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if preset is configured, default to slow if not
|
// Check if preset is configured, default to slow if not
|
||||||
var ffmpeg_preset
|
var ffmpeg_preset
|
||||||
if (inputs.ffmpeg_preset === undefined) {
|
if (inputs.ffmpeg_preset === undefined) {
|
||||||
ffmpeg_preset = `slow`;
|
ffmpeg_preset = `slow`
|
||||||
response.infoLog += "☑Preset not set, defaulting to slow\n"
|
response.infoLog += '☑Preset not set, defaulting to slow\n'
|
||||||
} else {
|
} else {
|
||||||
ffmpeg_preset = `${inputs.ffmpeg_preset}`;
|
ffmpeg_preset = `${inputs.ffmpeg_preset}`
|
||||||
response.infoLog += `☑Preset set as ${inputs.ffmpeg_preset}\n`
|
response.infoLog += `☑Preset set as ${inputs.ffmpeg_preset}\n`
|
||||||
}
|
}
|
||||||
|
|
||||||
//codec will be checked so it can be transcoded correctly
|
//codec will be checked so it can be transcoded correctly
|
||||||
if (file.video_codec_name == "h263") {
|
if (file.video_codec_name == 'h263') {
|
||||||
response.preset = `-c:v h263_cuvid`;
|
response.preset = `-c:v h263_cuvid`
|
||||||
} else if (file.video_codec_name == "h264") {
|
} else if (file.video_codec_name == 'h264') {
|
||||||
if (file.ffProbeData.streams[0].profile != "High 10") {
|
if (file.ffProbeData.streams[0].profile != 'High 10') {
|
||||||
//Remove HW Decoding for High 10 Profile
|
//Remove HW Decoding for High 10 Profile
|
||||||
response.preset = `-c:v h264_cuvid`;
|
response.preset = `-c:v h264_cuvid`
|
||||||
}
|
}
|
||||||
} else if (file.video_codec_name == "mjpeg") {
|
} else if (file.video_codec_name == 'mjpeg') {
|
||||||
response.preset = `c:v mjpeg_cuvid`;
|
response.preset = `c:v mjpeg_cuvid`
|
||||||
} else if (file.video_codec_name == "mpeg1") {
|
} else if (file.video_codec_name == 'mpeg1') {
|
||||||
response.preset = `-c:v mpeg1_cuvid`;
|
response.preset = `-c:v mpeg1_cuvid`
|
||||||
} else if (file.video_codec_name == "mpeg2") {
|
} else if (file.video_codec_name == 'mpeg2') {
|
||||||
response.preset = `-c:v mpeg2_cuvid`;
|
response.preset = `-c:v mpeg2_cuvid`
|
||||||
}
|
}
|
||||||
// skipping this one because it's empty
|
// skipping this one because it's empty
|
||||||
// else if (file.video_codec_name == 'mpeg4') {
|
// else if (file.video_codec_name == 'mpeg4') {
|
||||||
// response.preset = ``
|
// response.preset = ``
|
||||||
// }
|
// }
|
||||||
else if (file.video_codec_name == "vc1") {
|
else if (file.video_codec_name == 'vc1') {
|
||||||
response.preset = `-c:v vc1_cuvid`;
|
response.preset = `-c:v vc1_cuvid`
|
||||||
} else if (file.video_codec_name == "vp8") {
|
} else if (file.video_codec_name == 'vp8') {
|
||||||
response.preset = `-c:v vp8_cuvid`;
|
response.preset = `-c:v vp8_cuvid`
|
||||||
} else if (file.video_codec_name == "vp9") {
|
} else if (file.video_codec_name == 'vp9') {
|
||||||
response.preset = `-c:v vp9_cuvid`;
|
response.preset = `-c:v vp9_cuvid`
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set Subtitle Var before adding encode cli
|
//Set Subtitle Var before adding encode cli
|
||||||
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
|
for (var i = 0; i < file.ffProbeData.streams.length; i++) {
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
file.ffProbeData.streams[i].codec_name.toLowerCase() == "mov_text" &&
|
file.ffProbeData.streams[i].codec_name.toLowerCase() == 'mov_text' &&
|
||||||
file.ffProbeData.streams[i].codec_type.toLowerCase() == "subtitle"
|
file.ffProbeData.streams[i].codec_type.toLowerCase() == 'subtitle'
|
||||||
) {
|
) {
|
||||||
subcli = `-c:s srt`;
|
subcli = `-c:s srt`
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
//mitigate TrueHD audio causing Too many packets error
|
//mitigate TrueHD audio causing Too many packets error
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
file.ffProbeData.streams[i].codec_name.toLowerCase() == "truehd" ||
|
file.ffProbeData.streams[i].codec_name.toLowerCase() == 'truehd' ||
|
||||||
(file.ffProbeData.streams[i].codec_name.toLowerCase() == "dts" &&
|
(file.ffProbeData.streams[i].codec_name.toLowerCase() == 'dts' &&
|
||||||
file.ffProbeData.streams[i].profile.toLowerCase() == "dts-hd ma") ||
|
file.ffProbeData.streams[i].profile.toLowerCase() == 'dts-hd ma') ||
|
||||||
(file.ffProbeData.streams[i].codec_name.toLowerCase() == "aac" &&
|
(file.ffProbeData.streams[i].codec_name.toLowerCase() == 'aac' &&
|
||||||
file.ffProbeData.streams[i].sample_rate.toLowerCase() == "44100" &&
|
file.ffProbeData.streams[i].sample_rate.toLowerCase() == '44100' &&
|
||||||
file.ffProbeData.streams[i].codec_type.toLowerCase() == "audio")
|
file.ffProbeData.streams[i].codec_type.toLowerCase() == 'audio')
|
||||||
) {
|
) {
|
||||||
maxmux = ` -max_muxing_queue_size 9999`;
|
maxmux = ` -max_muxing_queue_size 9999`
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
//mitigate errors due to embeded pictures
|
//mitigate errors due to embeded pictures
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
(file.ffProbeData.streams[i].codec_name.toLowerCase() == "png" ||
|
(file.ffProbeData.streams[i].codec_name.toLowerCase() == 'png' ||
|
||||||
file.ffProbeData.streams[i].codec_name.toLowerCase() == "bmp" ||
|
file.ffProbeData.streams[i].codec_name.toLowerCase() == 'bmp' ||
|
||||||
file.ffProbeData.streams[i].codec_name.toLowerCase() == "mjpeg") &&
|
file.ffProbeData.streams[i].codec_name.toLowerCase() == 'mjpeg') &&
|
||||||
file.ffProbeData.streams[i].codec_type.toLowerCase() == "video"
|
file.ffProbeData.streams[i].codec_type.toLowerCase() == 'video'
|
||||||
) {
|
) {
|
||||||
map = `-map 0:v:0 -map 0:a -map 0:s?`;
|
map = `-map 0:v:0 -map 0:a -map 0:s?`
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
//file will be encoded if the resolution is 480p or 576p
|
//file will be encoded if the resolution is 480p or 576p
|
||||||
//codec will be checked so it can be transcoded correctly
|
//codec will be checked so it can be transcoded correctly
|
||||||
if (file.video_resolution === "480p" || file.video_resolution === "576p") {
|
if (file.video_resolution === '480p' || file.video_resolution === '576p') {
|
||||||
cqvinuse = `${inputs.sdCQV}`;
|
cqvinuse = `${inputs.sdCQV}`
|
||||||
response.preset += `,${map} -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v ${inputs.sdCQV} -preset ${ffmpeg_preset} -rc-lookahead 32 -bf ${inputs.bframe} -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${subcli}${maxmux}`;
|
response.preset += `,${map} -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v ${inputs.sdCQV} -preset ${ffmpeg_preset} -rc-lookahead 32 -bf ${inputs.bframe} -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${subcli}${maxmux}`
|
||||||
transcode = 1;
|
transcode = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
//file will be encoded if the resolution is 720p
|
//file will be encoded if the resolution is 720p
|
||||||
//codec will be checked so it can be transcoded correctly
|
//codec will be checked so it can be transcoded correctly
|
||||||
if (file.video_resolution === "720p") {
|
if (file.video_resolution === '720p') {
|
||||||
cqvinuse = `${inputs.hdCQV}`;
|
cqvinuse = `${inputs.hdCQV}`
|
||||||
response.preset += `,${map} -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v ${inputs.hdCQV} -preset ${ffmpeg_preset} -rc-lookahead 32 -bf ${inputs.bframe} -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${subcli}${maxmux}`;
|
response.preset += `,${map} -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v ${inputs.hdCQV} -preset ${ffmpeg_preset} -rc-lookahead 32 -bf ${inputs.bframe} -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${subcli}${maxmux}`
|
||||||
transcode = 1;
|
transcode = 1
|
||||||
}
|
}
|
||||||
//file will be encoded if the resolution is 1080p
|
//file will be encoded if the resolution is 1080p
|
||||||
//codec will be checked so it can be transcoded correctly
|
//codec will be checked so it can be transcoded correctly
|
||||||
if (file.video_resolution === "1080p") {
|
if (file.video_resolution === '1080p') {
|
||||||
cqvinuse = `${inputs.fullhdCQV}`;
|
cqvinuse = `${inputs.fullhdCQV}`
|
||||||
response.preset += `,${map} -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v ${inputs.fullhdCQV} -preset ${ffmpeg_preset} -rc-lookahead 32 -bf ${inputs.bframe} -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${subcli}${maxmux}`;
|
response.preset += `,${map} -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v ${inputs.fullhdCQV} -preset ${ffmpeg_preset} -rc-lookahead 32 -bf ${inputs.bframe} -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${subcli}${maxmux}`
|
||||||
transcode = 1;
|
transcode = 1
|
||||||
}
|
}
|
||||||
//file will be encoded if the resolution is 4K
|
//file will be encoded if the resolution is 4K
|
||||||
//codec will be checked so it can be transcoded correctly
|
//codec will be checked so it can be transcoded correctly
|
||||||
if (file.video_resolution === "4KUHD") {
|
if (file.video_resolution === '4KUHD') {
|
||||||
cqvinuse = `${inputs.uhdCQV}`;
|
cqvinuse = `${inputs.uhdCQV}`
|
||||||
response.preset += `,${map} -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v ${inputs.uhdCQV} -preset ${ffmpeg_preset} -rc-lookahead 32 -bf ${inputs.bframe} -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${subcli}${maxmux}`;
|
response.preset += `,${map} -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v ${inputs.uhdCQV} -preset ${ffmpeg_preset} -rc-lookahead 32 -bf ${inputs.bframe} -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${subcli}${maxmux}`
|
||||||
transcode = 1;
|
transcode = 1
|
||||||
}
|
}
|
||||||
//check if the file is eligible for transcoding
|
//check if the file is eligible for transcoding
|
||||||
//if true the neccessary response values will be changed
|
//if true the neccessary response values will be changed
|
||||||
if (transcode == 1) {
|
if (transcode == 1) {
|
||||||
response.processFile = true;
|
response.processFile = true
|
||||||
response.FFmpegMode = true;
|
response.FFmpegMode = true
|
||||||
response.reQueueAfter = true;
|
response.reQueueAfter = true
|
||||||
response.infoLog += `☑File is ${file.video_resolution}, using CQ:V value of ${cqvinuse}!\n`;
|
response.infoLog += `☑File is ${file.video_resolution}, using CQ:V value of ${cqvinuse}!\n`
|
||||||
response.infoLog += `☒File is not hevc!\n`;
|
response.infoLog += `☒File is not hevc!\n`
|
||||||
response.infoLog += `File is being transcoded!\n`;
|
response.infoLog += `File is being transcoded!\n`
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response
|
||||||
}
|
}
|
||||||
module.exports.details = details;
|
module.exports.details = details
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue