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
make-only-subtitle-default
Boosh1 2 years ago
parent 7f87af3c1b
commit 23bef4c778

@ -357,21 +357,19 @@ const plugin = (file, librarySettings, inputs, otherArguments) => {
// Check if stream is a video. // Check if stream is a video.
if (videoIdx === -1 && strstreamType === 'video') { if (videoIdx === -1 && strstreamType === 'video') {
videoIdx = i; videoIdx = i;
// Try checking file stats using Mediainfo first, then ffprobe.
try {
videoBR = Number(file.mediaInfo.track[i + 1].BitRate) / 1000; 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 (videoBR <= 0 || Number.isNaN(videoBR)) {
if (Number(file.ffProbeData.streams[i].tags.BPS) > 0) { if (Number(file.ffProbeData.streams[i].tags.BPS) > 0) {
videoBR = file.ffProbeData.streams[i].tags.BPS / 1000; videoBR = file.ffProbeData.streams[i].tags.BPS / 1000;
} else { } else if (Number(file.ffProbeData.streams[i].tags.BPS['-eng']) > 0) {
try {
if (Number(file.ffProbeData.streams[i].tags.BPS['-eng']) > 0) {
videoBR = file.ffProbeData.streams[i].tags.BPS['-eng'] / 1000; videoBR = file.ffProbeData.streams[i].tags.BPS['-eng'] / 1000;
} }
}
} catch (err) { } catch (err) {
// Catch error - Ignore & carry on - If check can bomb out if tags don't exist... // 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. // Check if duration info is filled, if so convert time format to minutes.
if (Number.isNaN(file.meta.Duration) === false) { if (Number.isNaN(file.meta.Duration) === false) {

Loading…
Cancel
Save