@ -6,7 +6,7 @@ function details() {
Type : "Video" ,
Operation : "Transcode" ,
Description : ` [Contains built-in filter] This plugin uses different FFMPEG NVENC transcoding settings for 480p,576p,720p,1080p and 4KUHD. If files are not in hevc they will be transcoded. The output container is mkv. \n \n ` ,
Version : "1.0 8 ",
Version : "1.0 9 ",
Link : "https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_d5d3_iiDrakeii_FFMPEG_NVENC_Tiered_MKV.js" ,
Tags : 'pre-processing,ffmpeg,video only,nvenc h265' ,
}
@ -18,7 +18,9 @@ function plugin(file) {
var bitratetarget = 0 ;
var bitratemax = 0 ;
var bitratecheck = 0 ;
var subcli = ` -c:s copy `
var subcli = ` -c:s copy ` ;
var maxmux = '' ;
var map = '-map 0'
//default values that will be returned
var response = {
processFile : false ,
@ -27,7 +29,8 @@ function plugin(file) {
handBrakeMode : false ,
FFmpegMode : false ,
reQueueAfter : true ,
infoLog : ''
infoLog : '' ,
maxmux : false ,
}
//check if the file is a video, if not the function will be stopped immediately
@ -79,7 +82,30 @@ function plugin(file) {
else if ( file . video _codec _name == 'vp9' ) {
response . preset = ` -c:v vp9_cuvid `
}
//Set Subtitle Var before adding encode cli
for ( var i = 0 ; i < file . ffProbeData . streams . length ; i ++ ) {
try {
if ( file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "mov_text" && file . ffProbeData . streams [ i ] . codec _type . toLowerCase ( ) == "subtitle" ) {
subcli = ` -c:s srt `
}
}
catch ( err ) { }
//mitigate TrueHD audio causing Too many packets error
try {
if ( file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "truehd" || ( file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "dts" && file . ffProbeData . streams [ i ] . profile . toLowerCase ( ) == "dts-hd ma" ) || file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "aac" && file . ffProbeData . streams [ i ] . sample _rate . toLowerCase ( ) == "44100" && file . ffProbeData . streams [ i ] . codec _type . toLowerCase ( ) == "audio" ) {
maxmux = ` -max_muxing_queue_size 9999 `
}
}
catch ( err ) { }
//mitigate errors due to embeded pictures
try {
if ( ( file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "png" || file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "bmp" || file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "mjpeg" ) && file . ffProbeData . streams [ i ] . codec _type . toLowerCase ( ) == "video" ) {
map = ` -map 0:v:0 -map 0:a -map 0:s `
}
}
catch ( err ) { }
}
//file will be encoded if the resolution is 480p or 576p
//codec will be checked so it can be transcoded correctly
if ( file . video _resolution === "480p" || file . video _resolution === "576p" ) {
@ -92,18 +118,10 @@ function plugin(file) {
bitratetarget = 1000 ;
bitratemax = 1500 ;
}
response . preset += ` , -map 0 -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 29 -b:v ${ bitratetarget } k -maxrate:v 1500k -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${ subcli } -dn ` ;
response . preset += ` , ${ map } -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 29 -b:v ${ bitratetarget } k -maxrate:v 1500k -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${ subcli } ${ maxmux } ` ;
transcode = 1 ;
}
//Set Subtitle Var before adding encode cli
for ( var i = 0 ; i < file . ffProbeData . streams . length ; i ++ ) {
try {
if ( file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "mov_text" && file . ffProbeData . streams [ i ] . codec _type . toLowerCase ( ) == "subtitle" ) {
subcli = ` -c:s srt `
}
}
catch ( err ) { }
}
//file will be encoded if the resolution is 720p
//codec will be checked so it can be transcoded correctly
if ( file . video _resolution === "720p" ) {
@ -116,7 +134,7 @@ function plugin(file) {
bitratetarget = 2000 ;
bitratemax = 4000 ;
}
response . preset += ` , -map 0 -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 30 -b:v ${ bitratetarget } k -maxrate:v ${ bitratemax } k -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${ subcli } -dn ` ;
response . preset += ` , ${ map } -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 30 -b:v ${ bitratetarget } k -maxrate:v ${ bitratemax } k -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${ subcli } ${ maxmux } ` ;
transcode = 1 ;
}
//file will be encoded if the resolution is 1080p
@ -131,7 +149,7 @@ function plugin(file) {
bitratetarget = 2500 ;
bitratemax = 5000 ;
}
response . preset += ` , -map 0 -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 31 -b:v ${ bitratetarget } k -maxrate:v ${ bitratemax } k -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${ subcli } -dn ` ;
response . preset += ` , ${ map } -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:V 31 -b:v ${ bitratetarget } k -maxrate:v ${ bitratemax } k -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${ subcli } ${ maxmux } ` ;
transcode = 1 ;
}
//file will be encoded if the resolution is 4K
@ -146,25 +164,9 @@ function plugin(file) {
bitratetarget = 14000 ;
bitratemax = 20000 ;
}
response . preset += ` , -map 0 -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 31 -b:v ${ bitratetarget } k -maxrate:v ${ bitratemax } k -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy -c:s copy -dn ` ;
response . preset += ` , ${ map } -dn -c:v hevc_nvenc -pix_fmt p010le -rc:v vbr_hq -qmin 0 -cq:v 31 -b:v ${ bitratetarget } k -maxrate:v ${ bitratemax } k -preset slow -rc-lookahead 32 -spatial_aq:v 1 -aq-strength:v 8 -a53cc 0 -c:a copy ${ subcli } ${ maxmux } ` ;
transcode = 1 ;
}
for ( var i = 0 ; i < file . ffProbeData . streams . length ; i ++ ) {
try {
//mitigate TrueHD audio causing Too many packets error
if ( file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "truehd" && file . ffProbeData . streams [ i ] . codec _type . toLowerCase ( ) == "audio" ) {
response . preset += ` -max_muxing_queue_size 1024 `
}
}
catch ( err ) { }
//mitigate errors due to embeded pictures
try {
if ( ( file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "png" || file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "bmp" || file . ffProbeData . streams [ i ] . codec _name . toLowerCase ( ) == "mjpeg" ) && file . ffProbeData . streams [ i ] . codec _type . toLowerCase ( ) == "video" ) {
response . preset += ` -map -0:v:1 `
}
}
catch ( err ) { }
}
//check if the file is eligible for transcoding
//if true the neccessary response values will be changed
if ( transcode == 1 ) {