aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.MediaEncoding')
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs2
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs18
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs118
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs59
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs2
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs182
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs102
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs4
-rw-r--r--MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj2
-rw-r--r--MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs17
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs18
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs4
-rw-r--r--MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs48
13 files changed, 169 insertions, 407 deletions
diff --git a/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs
index 566e7946d..2a874eba1 100644
--- a/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/AudioEncoder.cs
@@ -3,7 +3,7 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using System;
using MediaBrowser.Model.Diagnostics;
diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs
index 3383276bc..187f350b8 100644
--- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs
@@ -7,7 +7,7 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using MediaBrowser.Model.MediaInfo;
using System;
using System.Collections.Generic;
@@ -105,7 +105,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
OnTranscodeBeginning(encodingJob);
var commandLineLogMessage = process.StartInfo.FileName + " " + process.StartInfo.Arguments;
- Logger.Info(commandLineLogMessage);
+ Logger.LogInformation(commandLineLogMessage);
var logFilePath = Path.Combine(ConfigurationManager.CommonApplicationPaths.LogDirectoryPath, "transcode-" + Guid.NewGuid() + ".txt");
FileSystem.CreateDirectory(FileSystem.GetDirectoryName(logFilePath));
@@ -124,7 +124,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
catch (Exception ex)
{
- Logger.ErrorException("Error starting ffmpeg", ex);
+ Logger.LogError(ex, "Error starting ffmpeg");
OnTranscodeFailedToStart(encodingJob.OutputFilePath, encodingJob);
@@ -150,7 +150,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
private void Cancel(IProcess process, EncodingJob job)
{
- Logger.Info("Killing ffmpeg process for {0}", job.OutputFilePath);
+ Logger.LogInformation("Killing ffmpeg process for {0}", job.OutputFilePath);
//process.Kill();
process.StandardInput.WriteLine("q");
@@ -167,7 +167,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
job.HasExited = true;
- Logger.Debug("Disposing stream resources");
+ Logger.LogDebug("Disposing stream resources");
job.Dispose();
var isSuccesful = false;
@@ -175,13 +175,13 @@ namespace MediaBrowser.MediaEncoding.Encoder
try
{
var exitCode = process.ExitCode;
- Logger.Info("FFMpeg exited with code {0}", exitCode);
+ Logger.LogInformation("FFMpeg exited with code {0}", exitCode);
isSuccesful = exitCode == 0;
}
- catch
+ catch (Exception ex)
{
- Logger.Error("FFMpeg exited with an error.");
+ Logger.LogError(ex, "FFMpeg exited with an error.");
}
if (isSuccesful && !job.IsCancelled)
@@ -231,7 +231,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
//}
//catch (Exception ex)
//{
- // Logger.ErrorException("Error disposing ffmpeg.", ex);
+ // Logger.LogError("Error disposing ffmpeg.", ex);
//}
}
diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
index 59f3576ec..b68961889 100644
--- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Globalization;
+using System.Linq;
+using System.Text.RegularExpressions;
using MediaBrowser.Model.Diagnostics;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
namespace MediaBrowser.MediaEncoding.Encoder
{
@@ -18,21 +19,21 @@ namespace MediaBrowser.MediaEncoding.Encoder
_processFactory = processFactory;
}
- public Tuple<List<string>, List<string>> Validate(string encoderPath)
+ public (IEnumerable<string> decoders, IEnumerable<string> encoders) Validate(string encoderPath)
{
- _logger.Info("Validating media encoder at {0}", encoderPath);
+ _logger.LogInformation("Validating media encoder at {EncoderPath}", encoderPath);
- var decoders = GetDecoders(encoderPath);
- var encoders = GetEncoders(encoderPath);
+ var decoders = GetCodecs(encoderPath, Codec.Decoder);
+ var encoders = GetCodecs(encoderPath, Codec.Encoder);
- _logger.Info("Encoder validation complete");
+ _logger.LogInformation("Encoder validation complete");
- return new Tuple<List<string>, List<string>>(decoders, encoders);
+ return (decoders, encoders);
}
public bool ValidateVersion(string encoderAppPath, bool logOutput)
{
- string output = string.Empty;
+ string output = null;
try
{
output = GetProcessOutput(encoderAppPath, "-version");
@@ -41,7 +42,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
if (logOutput)
{
- _logger.ErrorException("Error validating encoder", ex);
+ _logger.LogError(ex, "Error validating encoder");
}
}
@@ -50,7 +51,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
return false;
}
- _logger.Info("ffmpeg info: {0}", output);
+ _logger.LogInformation("ffmpeg info: {0}", output);
if (output.IndexOf("Libav developers", StringComparison.OrdinalIgnoreCase) != -1)
{
@@ -71,20 +72,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
return true;
}
- private List<string> GetDecoders(string encoderAppPath)
- {
- string output = string.Empty;
- try
- {
- output = GetProcessOutput(encoderAppPath, "-decoders");
- }
- catch (Exception )
- {
- //_logger.ErrorException("Error detecting available decoders", ex);
- }
-
- var found = new List<string>();
- var required = new[]
+ private static readonly string[] requiredDecoders = new[]
{
"mpeg2video",
"h264_qsv",
@@ -101,33 +89,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
"hevc"
};
- foreach (var codec in required)
- {
- var srch = " " + codec + " ";
-
- if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1)
- {
- _logger.Info("Decoder available: " + codec);
- found.Add(codec);
- }
- }
-
- return found;
- }
-
- private List<string> GetEncoders(string encoderAppPath)
- {
- string output = null;
- try
- {
- output = GetProcessOutput(encoderAppPath, "-encoders");
- }
- catch
- {
- }
-
- var found = new List<string>();
- var required = new[]
+ private static readonly string[] requiredEncoders = new[]
{
"libx264",
"libx265",
@@ -151,32 +113,46 @@ namespace MediaBrowser.MediaEncoding.Encoder
"ac3"
};
- output = output ?? string.Empty;
+ private enum Codec
+ {
+ Encoder,
+ Decoder
+ }
- var index = 0;
+ private IEnumerable<string> GetCodecs(string encoderAppPath, Codec codec)
+ {
+ string codecstr = codec == Codec.Encoder ? "encoders" : "decoders";
+ string output = null;
+ try
+ {
+ output = GetProcessOutput(encoderAppPath, "-" + codecstr);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error detecting available {Codec}", codecstr);
+ }
- foreach (var codec in required)
+ if (string.IsNullOrWhiteSpace(output))
{
- var srch = " " + codec + " ";
+ return Enumerable.Empty<string>();
+ }
- if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) != -1)
- {
- if (index < required.Length - 1)
- {
- _logger.Info("Encoder available: " + codec);
- }
+ var required = codec == Codec.Encoder ? requiredEncoders : requiredDecoders;
- found.Add(codec);
- }
- index++;
- }
+ var found = Regex
+ .Matches(output, @"^\s\S{6}\s(?<codec>[\w|-]+)\s+.+$", RegexOptions.Multiline)
+ .Cast<Match>()
+ .Select(x => x.Groups["codec"].Value)
+ .Where(x => required.Contains(x));
+
+ _logger.LogInformation("Available {Codec}: {Codecs}", codecstr, found);
return found;
}
private string GetProcessOutput(string path, string arguments)
{
- var process = _processFactory.Create(new ProcessOptions
+ IProcess process = _processFactory.Create(new ProcessOptions
{
CreateNoWindow = true,
UseShellExecute = false,
@@ -187,7 +163,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
RedirectStandardOutput = true
});
- _logger.Info("Running {0} {1}", path, arguments);
+ _logger.LogInformation("Running {Path} {Arguments}", path, arguments);
using (process)
{
@@ -199,16 +175,16 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
catch
{
- _logger.Info("Killing process {0} {1}", path, arguments);
+ _logger.LogInformation("Killing process {path} {arguments}", path, arguments);
// Hate having to do this
try
{
process.Kill();
}
- catch (Exception ex1)
+ catch (Exception ex)
{
- _logger.ErrorException("Error killing process", ex1);
+ _logger.LogError(ex, "Error killing process");
}
throw;
diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs
index 294181fcc..9761de98f 100644
--- a/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs
@@ -1,19 +1,11 @@
-using MediaBrowser.Controller.Library;
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Dlna;
-using MediaBrowser.Model.Drawing;
-using MediaBrowser.Model.Dto;
-using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Logging;
-using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Net;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
+using Microsoft.Extensions.Logging;
namespace MediaBrowser.MediaEncoding.Encoder
{
@@ -81,7 +73,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
catch (Exception ex)
{
- _logger.ErrorException("Error disposing log stream", ex);
+ _logger.LogError(ex, "Error disposing log stream");
}
LogFileStream = null;
@@ -98,7 +90,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
catch (Exception ex)
{
- _logger.ErrorException("Error closing media source", ex);
+ _logger.LogError(ex, "Error closing media source");
}
}
}
@@ -153,7 +145,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
var ticks = transcodingPosition.HasValue ? transcodingPosition.Value.Ticks : (long?)null;
- // job.Framerate = framerate;
+ //job.Framerate = framerate;
if (!percentComplete.HasValue && ticks.HasValue && RunTimeTicks.HasValue)
{
@@ -166,8 +158,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
Progress.Report(percentComplete.Value);
}
- // job.TranscodingPositionTicks = ticks;
- // job.BytesTranscoded = bytesTranscoded;
+ /*
+ job.TranscodingPositionTicks = ticks;
+ job.BytesTranscoded = bytesTranscoded;
var deviceId = Options.DeviceId;
@@ -176,21 +169,21 @@ namespace MediaBrowser.MediaEncoding.Encoder
var audioCodec = ActualOutputVideoCodec;
var videoCodec = ActualOutputVideoCodec;
- // SessionManager.ReportTranscodingInfo(deviceId, new TranscodingInfo
- // {
- // Bitrate = job.TotalOutputBitrate,
- // AudioCodec = audioCodec,
- // VideoCodec = videoCodec,
- // Container = job.Options.OutputContainer,
- // Framerate = framerate,
- // CompletionPercentage = percentComplete,
- // Width = job.OutputWidth,
- // Height = job.OutputHeight,
- // AudioChannels = job.OutputAudioChannels,
- // IsAudioDirect = string.Equals(job.OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase),
- // IsVideoDirect = string.Equals(job.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase)
- // });
- }
+ SessionManager.ReportTranscodingInfo(deviceId, new TranscodingInfo
+ {
+ Bitrate = job.TotalOutputBitrate,
+ AudioCodec = audioCodec,
+ VideoCodec = videoCodec,
+ Container = job.Options.OutputContainer,
+ Framerate = framerate,
+ CompletionPercentage = percentComplete,
+ Width = job.OutputWidth,
+ Height = job.OutputHeight,
+ AudioChannels = job.OutputAudioChannels,
+ IsAudioDirect = string.Equals(job.OutputAudioCodec, "copy", StringComparison.OrdinalIgnoreCase),
+ IsVideoDirect = string.Equals(job.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase)
+ });
+ }*/
}
}
}
diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs
index 8d8d05a16..4e6ee89e1 100644
--- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs
@@ -5,7 +5,7 @@ using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using MediaBrowser.Model.MediaInfo;
using System;
using System.Collections.Generic;
diff --git a/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs b/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs
deleted file mode 100644
index e21292cbd..000000000
--- a/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs
+++ /dev/null
@@ -1,182 +0,0 @@
-using System;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Common.Configuration;
-
-using MediaBrowser.Common.Net;
-using MediaBrowser.Common.Progress;
-using MediaBrowser.Controller.IO;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Logging;
-using MediaBrowser.Model.Net;
-
-namespace MediaBrowser.MediaEncoding.Encoder
-{
- public class FontConfigLoader
- {
- private readonly IHttpClient _httpClient;
- private readonly IApplicationPaths _appPaths;
- private readonly ILogger _logger;
- private readonly IZipClient _zipClient;
- private readonly IFileSystem _fileSystem;
-
- private readonly string[] _fontUrls =
- {
- "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/ARIALUNI.7z"
- };
-
- public FontConfigLoader(IHttpClient httpClient, IApplicationPaths appPaths, ILogger logger, IZipClient zipClient, IFileSystem fileSystem)
- {
- _httpClient = httpClient;
- _appPaths = appPaths;
- _logger = logger;
- _zipClient = zipClient;
- _fileSystem = fileSystem;
- }
-
- /// <summary>
- /// Extracts the fonts.
- /// </summary>
- /// <param name="targetPath">The target path.</param>
- /// <returns>Task.</returns>
- public async Task DownloadFonts(string targetPath)
- {
- try
- {
- var fontsDirectory = Path.Combine(targetPath, "fonts");
-
- _fileSystem.CreateDirectory(fontsDirectory);
-
- const string fontFilename = "ARIALUNI.TTF";
-
- var fontFile = Path.Combine(fontsDirectory, fontFilename);
-
- if (_fileSystem.FileExists(fontFile))
- {
- await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false);
- }
- else
- {
- // Kick this off, but no need to wait on it
- var task = Task.Run(async () =>
- {
- await DownloadFontFile(fontsDirectory, fontFilename, new SimpleProgress<double>()).ConfigureAwait(false);
-
- await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false);
- });
- }
- }
- catch (HttpException ex)
- {
- // Don't let the server crash because of this
- _logger.ErrorException("Error downloading ffmpeg font files", ex);
- }
- catch (Exception ex)
- {
- // Don't let the server crash because of this
- _logger.ErrorException("Error writing ffmpeg font files", ex);
- }
- }
-
- /// <summary>
- /// Downloads the font file.
- /// </summary>
- /// <param name="fontsDirectory">The fonts directory.</param>
- /// <param name="fontFilename">The font filename.</param>
- /// <returns>Task.</returns>
- private async Task DownloadFontFile(string fontsDirectory, string fontFilename, IProgress<double> progress)
- {
- var existingFile = _fileSystem
- .GetFilePaths(_appPaths.ProgramDataPath, true)
- .FirstOrDefault(i => string.Equals(fontFilename, Path.GetFileName(i), StringComparison.OrdinalIgnoreCase));
-
- if (existingFile != null)
- {
- try
- {
- _fileSystem.CopyFile(existingFile, Path.Combine(fontsDirectory, fontFilename), true);
- return;
- }
- catch (IOException ex)
- {
- // Log this, but don't let it fail the operation
- _logger.ErrorException("Error copying file", ex);
- }
- }
-
- string tempFile = null;
-
- foreach (var url in _fontUrls)
- {
- progress.Report(0);
-
- try
- {
- tempFile = await _httpClient.GetTempFile(new HttpRequestOptions
- {
- Url = url,
- Progress = progress
-
- }).ConfigureAwait(false);
-
- break;
- }
- catch (Exception ex)
- {
- // The core can function without the font file, so handle this
- _logger.ErrorException("Failed to download ffmpeg font file from {0}", ex, url);
- }
- }
-
- if (string.IsNullOrEmpty(tempFile))
- {
- return;
- }
-
- Extract7zArchive(tempFile, fontsDirectory);
-
- try
- {
- _fileSystem.DeleteFile(tempFile);
- }
- catch (IOException ex)
- {
- // Log this, but don't let it fail the operation
- _logger.ErrorException("Error deleting temp file {0}", ex, tempFile);
- }
- }
- private void Extract7zArchive(string archivePath, string targetPath)
- {
- _logger.Info("Extracting {0} to {1}", archivePath, targetPath);
-
- _zipClient.ExtractAllFrom7z(archivePath, targetPath, true);
- }
-
- /// <summary>
- /// Writes the font config file.
- /// </summary>
- /// <param name="fontsDirectory">The fonts directory.</param>
- /// <returns>Task.</returns>
- private async Task WriteFontConfigFile(string fontsDirectory)
- {
- const string fontConfigFilename = "fonts.conf";
- var fontConfigFile = Path.Combine(fontsDirectory, fontConfigFilename);
-
- if (!_fileSystem.FileExists(fontConfigFile))
- {
- var contents = string.Format("<?xml version=\"1.0\"?><fontconfig><dir>{0}</dir><alias><family>Arial</family><prefer>Arial Unicode MS</prefer></alias></fontconfig>", fontsDirectory);
-
- var bytes = Encoding.UTF8.GetBytes(contents);
-
- using (var fileStream = _fileSystem.GetFileStream(fontConfigFile, FileOpenMode.Create, FileAccessMode.Write,
- FileShareMode.Read, true))
- {
- await fileStream.WriteAsync(bytes, 0, bytes.Length);
- }
- }
- }
- }
-}
diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
index 64372c072..a93dd9742 100644
--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
@@ -6,10 +6,8 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Session;
using MediaBrowser.MediaEncoding.Probing;
using MediaBrowser.Model.Dlna;
-using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Logging;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
using System;
@@ -25,6 +23,7 @@ using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Diagnostics;
using MediaBrowser.Model.System;
+using Microsoft.Extensions.Logging;
namespace MediaBrowser.MediaEncoding.Encoder
{
@@ -71,13 +70,27 @@ namespace MediaBrowser.MediaEncoding.Encoder
private readonly string _originalFFMpegPath;
private readonly string _originalFFProbePath;
private readonly int DefaultImageExtractionTimeoutMs;
- private readonly bool EnableEncoderFontFile;
-
private readonly IEnvironmentInfo _environmentInfo;
- public MediaEncoder(ILogger logger, IJsonSerializer jsonSerializer, string ffMpegPath, string ffProbePath, bool hasExternalEncoder, IServerConfigurationManager configurationManager, IFileSystem fileSystem, ILiveTvManager liveTvManager, IIsoManager isoManager, ILibraryManager libraryManager, IChannelManager channelManager, ISessionManager sessionManager, Func<ISubtitleEncoder> subtitleEncoder, Func<IMediaSourceManager> mediaSourceManager, IHttpClient httpClient, IZipClient zipClient, IProcessFactory processFactory,
+ public MediaEncoder(ILogger logger,
+ IJsonSerializer jsonSerializer,
+ string ffMpegPath,
+ string ffProbePath,
+ bool hasExternalEncoder,
+ IServerConfigurationManager configurationManager,
+ IFileSystem fileSystem,
+ ILiveTvManager liveTvManager,
+ IIsoManager isoManager,
+ ILibraryManager libraryManager,
+ IChannelManager channelManager,
+ ISessionManager sessionManager,
+ Func<ISubtitleEncoder> subtitleEncoder,
+ Func<IMediaSourceManager> mediaSourceManager,
+ IHttpClient httpClient,
+ IZipClient zipClient,
+ IProcessFactory processFactory,
int defaultImageExtractionTimeoutMs,
- bool enableEncoderFontFile, IEnvironmentInfo environmentInfo)
+ IEnvironmentInfo environmentInfo)
{
_logger = logger;
_jsonSerializer = jsonSerializer;
@@ -94,7 +107,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
_zipClient = zipClient;
_processFactory = processFactory;
DefaultImageExtractionTimeoutMs = defaultImageExtractionTimeoutMs;
- EnableEncoderFontFile = enableEncoderFontFile;
_environmentInfo = environmentInfo;
FFProbePath = ffProbePath;
FFMpegPath = ffMpegPath;
@@ -102,8 +114,6 @@ namespace MediaBrowser.MediaEncoding.Encoder
_originalFFMpegPath = ffMpegPath;
_hasExternalEncoder = hasExternalEncoder;
-
- SetEnvironmentVariable();
}
private readonly object _logLock = new object();
@@ -117,7 +127,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
catch (Exception ex)
{
- _logger.ErrorException("Error setting FFREPORT environment variable", ex);
+ _logger.LogError(ex, "Error setting FFREPORT environment variable");
}
}
}
@@ -132,31 +142,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
catch (Exception ex)
{
- //_logger.ErrorException("Error setting FFREPORT environment variable", ex);
+ _logger.LogError(ex, "Error setting FFREPORT environment variable");
}
}
}
- private void SetEnvironmentVariable()
- {
- try
- {
- //_environmentInfo.SetProcessEnvironmentVariable("FFREPORT", "file=program-YYYYMMDD-HHMMSS.txt:level=32");
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error setting FFREPORT environment variable", ex);
- }
- try
- {
- //_environmentInfo.SetUserEnvironmentVariable("FFREPORT", "file=program-YYYYMMDD-HHMMSS.txt:level=32");
- }
- catch (Exception ex)
- {
- _logger.ErrorException("Error setting FFREPORT environment variable", ex);
- }
- }
-
public string EncoderLocationType
{
get
@@ -198,18 +188,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
var result = new EncoderValidator(_logger, _processFactory).Validate(FFMpegPath);
- SetAvailableDecoders(result.Item1);
- SetAvailableEncoders(result.Item2);
-
- if (EnableEncoderFontFile)
- {
- var directory = FileSystem.GetDirectoryName(FFMpegPath);
-
- if (!string.IsNullOrWhiteSpace(directory) && FileSystem.ContainsSubPath(ConfigurationManager.ApplicationPaths.ProgramDataPath, directory))
- {
- new FontConfigLoader(_httpClient, ConfigurationManager.ApplicationPaths, _logger, _zipClient, FileSystem).DownloadFonts(directory).ConfigureAwait(false);
- }
- }
+ SetAvailableDecoders(result.decoders);
+ SetAvailableEncoders(result.encoders);
}
}
@@ -252,7 +232,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
return;
}
- _logger.Info("Attempting to update encoder path to {0}. pathType: {1}", path ?? string.Empty, pathType ?? string.Empty);
+ _logger.LogInformation("Attempting to update encoder path to {0}. pathType: {1}", path ?? string.Empty, pathType ?? string.Empty);
Tuple<string, string> newPaths;
@@ -414,8 +394,8 @@ namespace MediaBrowser.MediaEncoding.Encoder
private void LogPaths()
{
- _logger.Info("FFMpeg: {0}", FFMpegPath ?? "not found");
- _logger.Info("FFProbe: {0}", FFProbePath ?? "not found");
+ _logger.LogInformation("FFMpeg: {0}", FFMpegPath ?? "not found");
+ _logger.LogInformation("FFProbe: {0}", FFProbePath ?? "not found");
}
private EncodingOptions GetEncodingOptions()
@@ -424,14 +404,14 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
private List<string> _encoders = new List<string>();
- public void SetAvailableEncoders(List<string> list)
+ public void SetAvailableEncoders(IEnumerable<string> list)
{
_encoders = list.ToList();
//_logger.Info("Supported encoders: {0}", string.Join(",", list.ToArray()));
}
private List<string> _decoders = new List<string>();
- public void SetAvailableDecoders(List<string> list)
+ public void SetAvailableDecoders(IEnumerable<string> list)
{
_decoders = list.ToList();
//_logger.Info("Supported decoders: {0}", string.Join(",", list.ToArray()));
@@ -557,11 +537,11 @@ namespace MediaBrowser.MediaEncoding.Encoder
if (forceEnableLogging)
{
- _logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ _logger.LogInformation("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
}
else
{
- _logger.Debug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ _logger.LogDebug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
}
using (var processWrapper = new ProcessWrapper(process, this, _logger))
@@ -572,7 +552,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
//process.BeginErrorReadLine();
- var result = _jsonSerializer.DeserializeFromStream<InternalMediaInfoResult>(process.StandardOutput.BaseStream);
+ var result = await _jsonSerializer.DeserializeFromStreamAsync<InternalMediaInfoResult>(process.StandardOutput.BaseStream).ConfigureAwait(false);
if (result == null || (result.streams == null && result.format == null))
{
@@ -649,9 +629,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
throw;
}
- catch
+ catch (Exception ex)
{
- _logger.Error("I-frame image extraction failed, will attempt standard way. Input: {0}", inputArgument);
+ _logger.LogError(ex, "I-frame image extraction failed, will attempt standard way. Input: {arguments}", inputArgument);
}
}
@@ -755,7 +735,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
ErrorDialog = false
});
- _logger.Debug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ _logger.LogDebug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
using (var processWrapper = new ProcessWrapper(process, this, _logger))
{
@@ -783,7 +763,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
var msg = string.Format("ffmpeg image extraction failed for {0}", inputPath);
- _logger.Error(msg);
+ _logger.LogError(msg);
throw new Exception(msg);
}
@@ -877,7 +857,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
ErrorDialog = false
});
- _logger.Info(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
+ _logger.LogInformation(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
@@ -929,7 +909,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
{
var msg = string.Format("ffmpeg image extraction failed for {0}", inputArgument);
- _logger.Error(msg);
+ _logger.LogError(msg);
throw new Exception(msg);
}
@@ -961,7 +941,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
IProgress<double> progress,
CancellationToken cancellationToken)
{
- _logger.Error("EncodeVideo");
+ _logger.LogError("EncodeVideo");
var job = await new VideoEncoder(this,
_logger,
ConfigurationManager,
@@ -999,18 +979,18 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
catch (Exception ex)
{
- _logger.Error("Error in WaitForExit", ex);
+ _logger.LogError(ex, "Error in WaitForExit");
}
try
{
- _logger.Info("Killing ffmpeg process");
+ _logger.LogInformation("Killing ffmpeg process");
process.Process.Kill();
}
catch (Exception ex)
{
- _logger.ErrorException("Error killing process", ex);
+ _logger.LogError(ex, "Error killing process");
}
}
diff --git a/MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs
index 96c126923..732b5bf84 100644
--- a/MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/VideoEncoder.cs
@@ -4,7 +4,7 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Threading.Tasks;
@@ -63,4 +63,4 @@ namespace MediaBrowser.MediaEncoding.Encoder
}
}
-} \ No newline at end of file
+}
diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj
index d9d2b4bf9..d93394957 100644
--- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj
+++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj
@@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
- <Compile Include="..\SharedVersion.cs"/>
+ <Compile Include="..\SharedVersion.cs" />
</ItemGroup>
<ItemGroup>
diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
index 0a3532b8c..5367a87f7 100644
--- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
+++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs
@@ -1,20 +1,17 @@
-using MediaBrowser.Model.Dto;
-using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Extensions;
-using System;
+using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
-using MediaBrowser.Model.IO;
-
-using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
+using MediaBrowser.Model.Dto;
+using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Logging;
using MediaBrowser.Model.MediaInfo;
+using Microsoft.Extensions.Logging;
namespace MediaBrowser.MediaEncoding.Probing
{
@@ -1351,11 +1348,11 @@ namespace MediaBrowser.MediaEncoding.Probing
{
video.Timestamp = GetMpegTimestamp(video.Path);
- _logger.Debug("Video has {0} timestamp", video.Timestamp);
+ _logger.LogDebug("Video has {timestamp} timestamp", video.Timestamp);
}
catch (Exception ex)
{
- _logger.ErrorException("Error extracting timestamp info from {0}", ex, video.Path);
+ _logger.LogError(ex, "Error extracting timestamp info from {path}", video.Path);
video.Timestamp = null;
}
}
diff --git a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs
index 3954897ca..2d29f29e3 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/OpenSubtitleDownloader.cs
@@ -15,9 +15,9 @@ using MediaBrowser.Controller.Subtitles;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
+using Microsoft.Extensions.Logging;
using OpenSubtitlesHandler;
namespace MediaBrowser.MediaEncoding.Subtitles
@@ -34,9 +34,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles
private readonly IJsonSerializer _json;
private readonly IFileSystem _fileSystem;
- public OpenSubtitleDownloader(ILogManager logManager, IHttpClient httpClient, IServerConfigurationManager config, IEncryptionManager encryption, IJsonSerializer json, IFileSystem fileSystem)
+ public OpenSubtitleDownloader(ILoggerFactory loggerFactory, IHttpClient httpClient, IServerConfigurationManager config, IEncryptionManager encryption, IJsonSerializer json, IFileSystem fileSystem)
{
- _logger = logManager.GetLogger(GetType().Name);
+ _logger = loggerFactory.CreateLogger(GetType().Name);
_httpClient = httpClient;
_config = config;
_encryption = encryption;
@@ -208,7 +208,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var result = OpenSubtitles.GetSubLanguages("en");
if (!(result is MethodResponseGetSubLanguages))
{
- _logger.Error("Invalid response type");
+ _logger.LogError("Invalid response type");
return new List<NameIdPair>();
}
@@ -243,19 +243,19 @@ namespace MediaBrowser.MediaEncoding.Subtitles
case VideoContentType.Episode:
if (!request.IndexNumber.HasValue || !request.ParentIndexNumber.HasValue || string.IsNullOrEmpty(request.SeriesName))
{
- _logger.Debug("Episode information missing");
+ _logger.LogDebug("Episode information missing");
return new List<RemoteSubtitleInfo>();
}
break;
case VideoContentType.Movie:
if (string.IsNullOrEmpty(request.Name))
{
- _logger.Debug("Movie name missing");
+ _logger.LogDebug("Movie name missing");
return new List<RemoteSubtitleInfo>();
}
if (string.IsNullOrWhiteSpace(imdbIdText) || !long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId))
{
- _logger.Debug("Imdb id missing");
+ _logger.LogDebug("Imdb id missing");
return new List<RemoteSubtitleInfo>();
}
break;
@@ -263,7 +263,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
if (string.IsNullOrEmpty(request.MediaPath))
{
- _logger.Debug("Path Missing");
+ _logger.LogDebug("Path Missing");
return new List<RemoteSubtitleInfo>();
}
@@ -300,7 +300,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var result = await OpenSubtitles.SearchSubtitlesAsync(parms.ToArray(), cancellationToken).ConfigureAwait(false);
if (!(result is MethodResponseSubtitleSearch))
{
- _logger.Error("Invalid response type");
+ _logger.LogError("Invalid response type");
return new List<RemoteSubtitleInfo>();
}
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs
index de6d7bc72..7ca8aa1fd 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs
@@ -1,5 +1,5 @@
using MediaBrowser.Model.Extensions;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -50,7 +50,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
// This occurs when subtitle text has an empty line as part of the text.
// Need to adjust the break statement below to resolve this.
- _logger.Warn("Unrecognized line in srt: {0}", line);
+ _logger.LogWarning("Unrecognized line in srt: {0}", line);
continue;
}
subEvent.StartPositionTicks = GetTicks(time[0]);
diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs
index d565ff3e2..43f775392 100644
--- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs
@@ -5,7 +5,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Logging;
+using Microsoft.Extensions.Logging;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Serialization;
using System;
@@ -190,7 +190,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var bytes = await GetBytes(path, protocol, cancellationToken).ConfigureAwait(false);
var charset = _textEncoding.GetDetectedEncodingName(bytes, bytes.Length, language, true);
- _logger.Debug("charset {0} detected for {1}", charset ?? "null", path);
+ _logger.LogDebug("charset {0} detected for {1}", charset ?? "null", path);
if (!string.IsNullOrEmpty(charset))
{
@@ -423,7 +423,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
ErrorDialog = false
});
- _logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ _logger.LogInformation("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
try
{
@@ -431,7 +431,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
catch (Exception ex)
{
- _logger.ErrorException("Error starting ffmpeg", ex);
+ _logger.LogError(ex, "Error starting ffmpeg");
throw;
}
@@ -442,13 +442,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
try
{
- _logger.Info("Killing ffmpeg subtitle conversion process");
+ _logger.LogInformation("Killing ffmpeg subtitle conversion process");
process.Kill();
}
catch (Exception ex)
{
- _logger.ErrorException("Error killing subtitle conversion process", ex);
+ _logger.LogError(ex, "Error killing subtitle conversion process");
}
}
@@ -466,12 +466,12 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
try
{
- _logger.Info("Deleting converted subtitle due to failure: ", outputPath);
+ _logger.LogInformation("Deleting converted subtitle due to failure: ", outputPath);
_fileSystem.DeleteFile(outputPath);
}
catch (IOException ex)
{
- _logger.ErrorException("Error deleting converted subtitle {0}", ex, outputPath);
+ _logger.LogError(ex, "Error deleting converted subtitle {0}", outputPath);
}
}
}
@@ -484,13 +484,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
var msg = string.Format("ffmpeg subtitle conversion failed for {0}", inputPath);
- _logger.Error(msg);
+ _logger.LogError(msg);
throw new Exception(msg);
}
await SetAssFont(outputPath).ConfigureAwait(false);
- _logger.Info("ffmpeg subtitle conversion succeeded for {0}", inputPath);
+ _logger.LogInformation("ffmpeg subtitle conversion succeeded for {0}", inputPath);
}
/// <summary>
@@ -553,7 +553,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
ErrorDialog = false
});
- _logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
+ _logger.LogInformation("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments);
try
{
@@ -561,7 +561,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
catch (Exception ex)
{
- _logger.ErrorException("Error starting ffmpeg", ex);
+ _logger.LogError(ex, "Error starting ffmpeg");
throw;
}
@@ -572,13 +572,13 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
try
{
- _logger.Info("Killing ffmpeg subtitle extraction process");
+ _logger.LogInformation("Killing ffmpeg subtitle extraction process");
process.Kill();
}
catch (Exception ex)
{
- _logger.ErrorException("Error killing subtitle extraction process", ex);
+ _logger.LogError(ex, "Error killing subtitle extraction process");
}
}
@@ -594,7 +594,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
try
{
- _logger.Info("Deleting extracted subtitle due to failure: {0}", outputPath);
+ _logger.LogInformation("Deleting extracted subtitle due to failure: {0}", outputPath);
_fileSystem.DeleteFile(outputPath);
}
catch (FileNotFoundException)
@@ -603,7 +603,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
catch (IOException ex)
{
- _logger.ErrorException("Error deleting extracted subtitle {0}", ex, outputPath);
+ _logger.LogError(ex, "Error deleting extracted subtitle {0}", outputPath);
}
}
else if (!_fileSystem.FileExists(outputPath))
@@ -615,7 +615,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
var msg = string.Format("ffmpeg subtitle extraction failed for {0} to {1}", inputPath, outputPath);
- _logger.Error(msg);
+ _logger.LogError(msg);
throw new Exception(msg);
}
@@ -623,7 +623,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{
var msg = string.Format("ffmpeg subtitle extraction completed for {0} to {1}", inputPath, outputPath);
- _logger.Info(msg);
+ _logger.LogInformation(msg);
}
if (string.Equals(outputCodec, "ass", StringComparison.OrdinalIgnoreCase))
@@ -639,7 +639,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
/// <returns>Task.</returns>
private async Task SetAssFont(string file)
{
- _logger.Info("Setting ass font within {0}", file);
+ _logger.LogInformation("Setting ass font within {0}", file);
string text;
Encoding encoding;
@@ -659,11 +659,9 @@ namespace MediaBrowser.MediaEncoding.Subtitles
if (!string.Equals(text, newText))
{
using (var fileStream = _fileSystem.GetFileStream(file, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
+ using (var writer = new StreamWriter(fileStream, encoding))
{
- using (var writer = new StreamWriter(fileStream, encoding))
- {
- writer.Write(newText);
- }
+ writer.Write(newText);
}
}
}
@@ -698,7 +696,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
var charset = _textEncoding.GetDetectedEncodingName(bytes, bytes.Length, language, true);
- _logger.Debug("charset {0} detected for {1}", charset ?? "null", path);
+ _logger.LogDebug("charset {0} detected for {1}", charset ?? "null", path);
return charset;
}
@@ -730,4 +728,4 @@ namespace MediaBrowser.MediaEncoding.Subtitles
}
}
-} \ No newline at end of file
+}