Reduce log spam and clean up EncoderValidator

This commit is contained in:
Bond_009 2019-01-02 01:01:36 +01:00 committed by Vasily
parent 68715bb1dc
commit 96ad22a009

View File

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.Diagnostics;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -73,7 +72,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
private List<string> GetDecoders(string encoderAppPath) private List<string> GetDecoders(string encoderAppPath)
{ {
string output = string.Empty; string output = null;
try try
{ {
output = GetProcessOutput(encoderAppPath, "-decoders"); output = GetProcessOutput(encoderAppPath, "-decoders");
@ -83,7 +82,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
_logger.LogError(ex, "Error detecting available decoders"); _logger.LogError(ex, "Error detecting available decoders");
} }
var found = new List<string>(); if (string.IsNullOrWhiteSpace(output))
{
return new List<string>();
}
var required = new[] var required = new[]
{ {
"mpeg2video", "mpeg2video",
@ -101,17 +104,19 @@ namespace MediaBrowser.MediaEncoding.Encoder
"hevc" "hevc"
}; };
var found = new List<string>();
foreach (var codec in required) foreach (var codec in required)
{ {
var srch = " " + codec + " "; var srch = " " + codec + " ";
if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1) if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1)
{ {
_logger.LogInformation("Decoder available: " + codec);
found.Add(codec); found.Add(codec);
} }
} }
_logger.LogInformation("Available decoders: {Codecs}", found);
return found; return found;
} }
@ -122,11 +127,16 @@ namespace MediaBrowser.MediaEncoding.Encoder
{ {
output = GetProcessOutput(encoderAppPath, "-encoders"); output = GetProcessOutput(encoderAppPath, "-encoders");
} }
catch catch (Exception ex)
{ {
_logger.LogError(ex, "Error getting encoders");
}
if (string.IsNullOrWhiteSpace(output))
{
return new List<string>();
} }
var found = new List<string>();
var required = new[] var required = new[]
{ {
"libx264", "libx264",
@ -151,26 +161,19 @@ namespace MediaBrowser.MediaEncoding.Encoder
"ac3" "ac3"
}; };
output = output ?? string.Empty; var found = new List<string>();
var index = 0;
foreach (var codec in required) foreach (var codec in required)
{ {
var srch = " " + codec + " "; var srch = " " + codec + " ";
if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1) if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1)
{ {
if (index < required.Length - 1)
{
_logger.LogInformation("Encoder available: " + codec);
}
found.Add(codec); found.Add(codec);
} }
index++;
} }
_logger.LogInformation("Available encoders: {Codecs}", found);
return found; return found;
} }