From c97fdeff989441472531bd554790a681753de08c Mon Sep 17 00:00:00 2001 From: Migz93 <33037112+Migz93@users.noreply.github.com> Date: Sun, 9 Feb 2020 02:31:10 +0000 Subject: [PATCH] Migz Plugins: Bug Fixes 1) Fixed bug with Migz1FFMPEG where sometimes duration was not available, get duration from stream 0, if duration still not available then exit plugin. 2) Fixed bug with Migz1FFMPEG where it would fail if using mkv and source has a data stream (mkv does not support data streams). 3) Fixed bug with Migz2CleanTitle where if title info did not exist at all it would fail rather then skip. --- Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js | 35 +++++++++++++------ .../Tdarr_Plugin_MC93_Migz2CleanTitle.js | 27 ++++++++------ 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js index effccd3..381d69c 100644 --- a/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js +++ b/Community/Tdarr_Plugin_MC93_Migz1FFMPEG.js @@ -34,14 +34,6 @@ function plugin(file, librarySettings, inputs) { infoLog: '' } - var bitrateSettings = "" - var filesize = (file.file_size / 1000) - var duration = (file.meta.Duration * 0.0166667) - var targetBitrate = ~~((file.file_size / (duration * 0.0075)) / 2) - var minimumBitrate = ~~(targetBitrate * 0.7) - var maximumBitrate = ~~(targetBitrate * 1.3) - bitrateSettings = `-b:v ${targetBitrate}k -minrate ${minimumBitrate}k -maxrate ${maximumBitrate}k` - if (inputs.container == "") { response.infoLog += "☒Container has not been configured within plugin settings, please configure required options. Skipping this plugin. \n" response.processFile = false @@ -55,8 +47,27 @@ function plugin(file, librarySettings, inputs) { response.infoLog += "☒File is not a video. \n" return response } + + if (typeof file.meta.Duration != 'undefined') { + var duration = (file.meta.Duration * 0.0166667) + } else { + var duration = (file.ffProbeData.streams[0].duration * 0.0166667) + } + + var bitrateSettings = "" + var filesize = (file.file_size / 1000) + var targetBitrate = ~~((file.file_size / (duration * 0.0075)) / 2) + var minimumBitrate = ~~(targetBitrate * 0.7) + var maximumBitrate = ~~(targetBitrate * 1.3) + + if (targetBitrate == "0") { + response.processFile = false + response.infoLog += "☒Target bitrate could not be calculated. Skipping this plugin. \n" + return response + } -response.infoLog += `Container for output selected as ${inputs.container}. \n Current bitrate = ${~~(file.file_size / (duration * 0.0075))} \n Bitrate settings: \nTarget = ${targetBitrate} \nMinimum = ${minimumBitrate} \nMaximum = ${maximumBitrate} \n` + bitrateSettings = `-b:v ${targetBitrate}k -minrate ${minimumBitrate}k -maxrate ${maximumBitrate}k` + response.infoLog += `Container for output selected as ${inputs.container}. \n Current bitrate = ${~~(file.file_size / (duration * 0.0075))} \n Bitrate settings: \nTarget = ${targetBitrate} \nMinimum = ${minimumBitrate} \nMaximum = ${maximumBitrate} \n` if (file.ffProbeData.streams[0].codec_name == 'hevc' && file.container == inputs.container) { response.processFile = false @@ -99,7 +110,11 @@ response.infoLog += `Container for output selected as ${inputs.container}. \n Cu response.preset = `-c:v vp9_cuvid` } - response.preset += `,-map 0 -c:v hevc_nvenc -rc:v vbr_hq ${bitrateSettings} -bufsize 2M -spatial_aq:v 1 -c:a copy -c:s copy -max_muxing_queue_size 4096` + if (inputs.container == "mkv") { + extraArguments = "-map -0:d " + } + + response.preset += `,-map 0 -c:v hevc_nvenc -rc:v vbr_hq ${bitrateSettings} -bufsize 2M -spatial_aq:v 1 -c:a copy -c:s copy -max_muxing_queue_size 4096 ${extraArguments}` response.processFile = true response.infoLog += `☒File is not hevc. Transcoding. \n` return response diff --git a/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js b/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js index ef3a9b3..0b84ce1 100644 --- a/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js +++ b/Community/Tdarr_Plugin_MC93_Migz2CleanTitle.js @@ -6,14 +6,13 @@ function details() { Type: "Video", Operation: "Clean", Description: `[TESTING]This plugin removes video title metadata if it exists. \n\n`, - Version: "1.00", + Version: "1.10", Link: "" } } function plugin(file) { var response = { - processFile : false, preset : '', container: '.' + file.container, @@ -35,18 +34,24 @@ function plugin(file) { return response } - if(file.meta.Title != undefined ){ - ffmpegCommandInsert += ` -metadata title="" ` - convert = true - } + try { + if (typeof file.meta.Title != 'undefined' ){ + ffmpegCommandInsert += ` -metadata title="" ` + response.infoLog += "1" + convert = true + } + } catch (err) { } for (var i = 0; i < file.ffProbeData.streams.length; i++) { if (file.ffProbeData.streams[i].codec_type.toLowerCase() == "video") { - if (file.ffProbeData.streams[i].tags.title != undefined) { - ffmpegCommandInsert += ` -metadata:s:v:${videoIdx} title="" ` - convert = true - } - videoIdx++ + try { + if (typeof file.ffProbeData.streams[i].tags.title != 'undefined') { + ffmpegCommandInsert += ` -metadata:s:v:${videoIdx} title="" ` + response.infoLog += "2" + convert = true + } + } catch (err) { } + videoIdx++ } }