From 23bef4c77829e16d8f3a0d40d67af09818160aa1 Mon Sep 17 00:00:00 2001 From: Boosh1 <45874141+Boosh1@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:30:08 +0000 Subject: [PATCH] Protection against errors if unable to use MediaInfo or ffprobe Just changed the videoBR logic to be inside a try block to avoid errors on rare instances where Media info & ffprobe fail --- ...Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js b/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js index e01a033..3d2d2c6 100644 --- a/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js +++ b/Community/Tdarr_Plugin_bsh1_Boosh_FFMPEG_QSV_HEVC.js @@ -357,21 +357,19 @@ const plugin = (file, librarySettings, inputs, otherArguments) => { // Check if stream is a video. if (videoIdx === -1 && strstreamType === 'video') { videoIdx = i; - videoBR = Number(file.mediaInfo.track[i + 1].BitRate) / 1000; - - // If MediaInfo fails somehow fallback to ffprobe - Try two types of tags that might exist - if (videoBR <= 0 || Number.isNaN(videoBR)) { - if (Number(file.ffProbeData.streams[i].tags.BPS) > 0) { - videoBR = file.ffProbeData.streams[i].tags.BPS / 1000; - } else { - try { - if (Number(file.ffProbeData.streams[i].tags.BPS['-eng']) > 0) { - videoBR = file.ffProbeData.streams[i].tags.BPS['-eng'] / 1000; - } - } catch (err) { - // Catch error - Ignore & carry on - If check can bomb out if tags don't exist... + // Try checking file stats using Mediainfo first, then ffprobe. + try { + videoBR = Number(file.mediaInfo.track[i + 1].BitRate) / 1000; + if (videoBR <= 0 || Number.isNaN(videoBR)) { + if (Number(file.ffProbeData.streams[i].tags.BPS) > 0) { + videoBR = file.ffProbeData.streams[i].tags.BPS / 1000; + } else if (Number(file.ffProbeData.streams[i].tags.BPS['-eng']) > 0) { + videoBR = file.ffProbeData.streams[i].tags.BPS['-eng'] / 1000; } } + } catch (err) { + // Catch error - Ignore & carry on - If check can bomb out if tags don't exist... + videoBR = 0; // Set videoBR to 0 for safety } // Check if duration info is filled, if so convert time format to minutes. if (Number.isNaN(file.meta.Duration) === false) {