Add some analyzers to MediaBrowser.MediaEncoding

This commit is contained in:
Bond-009
2020-08-04 17:08:09 +02:00
parent 18efa25a6f
commit 53f99d5d4b
11 changed files with 210 additions and 169 deletions

View File

@@ -14,7 +14,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
private const string DefaultEncoderPath = "ffmpeg";
private static readonly string[] requiredDecoders = new[]
private static readonly string[] _requiredDecoders = new[]
{
"h264",
"hevc",
@@ -57,7 +57,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
"vc1_opencl"
};
private static readonly string[] requiredEncoders = new[]
private static readonly string[] _requiredEncoders = new[]
{
"libx264",
"libx265",
@@ -112,6 +112,12 @@ namespace MediaBrowser.MediaEncoding.Encoder
_encoderPath = encoderPath;
}
private enum Codec
{
Encoder,
Decoder
}
public static Version MinVersion { get; } = new Version(4, 0);
public static Version MaxVersion { get; } = null;
@@ -195,8 +201,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
/// If that fails then we use one of the main libraries to determine if it's new/older than the latest
/// we have stored.
/// </summary>
/// <param name="output"></param>
/// <returns></returns>
/// <param name="output">The output from "ffmpeg -version".</param>
/// <returns>The FFmpeg version.</returns>
internal static Version GetFFmpegVersion(string output)
{
// For pre-built binaries the FFmpeg version should be mentioned at the very start of the output
@@ -218,10 +224,10 @@ namespace MediaBrowser.MediaEncoding.Encoder
/// <summary>
/// Grabs the library names and major.minor version numbers from the 'ffmpeg -version' output
/// and condenses them on to one line. Output format is "name1=major.minor,name2=major.minor,etc."
/// and condenses them on to one line. Output format is "name1=major.minor,name2=major.minor,etc.".
/// </summary>
/// <param name="output"></param>
/// <returns></returns>
/// <param name="output">The 'ffmpeg -version' output.</param>
/// <returns>The library names and major.minor version numbers.</returns>
private static string GetLibrariesVersionString(string output)
{
var rc = new StringBuilder(144);
@@ -241,12 +247,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
return rc.Length == 0 ? null : rc.ToString();
}
private enum Codec
{
Encoder,
Decoder
}
private IEnumerable<string> GetHwaccelTypes()
{
string output = null;
@@ -264,7 +264,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
return Enumerable.Empty<string>();
}
var found = output.Split(new char[] {'\r','\n'}, StringSplitOptions.RemoveEmptyEntries).Skip(1).Distinct().ToList();
var found = output.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Skip(1).Distinct().ToList();
_logger.LogInformation("Available hwaccel types: {Types}", found);
return found;
@@ -288,7 +288,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
return Enumerable.Empty<string>();
}
var required = codec == Codec.Encoder ? requiredEncoders : requiredDecoders;
var required = codec == Codec.Encoder ? _requiredEncoders : _requiredDecoders;
var found = Regex
.Matches(output, @"^\s\S{6}\s(?<codec>[\w|-]+)\s+.+$", RegexOptions.Multiline)