diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index b510a640e4..519ff7947a 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -967,8 +967,6 @@ namespace MediaBrowser.Api.Playback private async void StreamToStandardInput(Process process, StreamState state) { - state.StandardInputCancellationTokenSource = new CancellationTokenSource(); - try { await StreamToStandardInputInternal(process, state).ConfigureAwait(false); @@ -1263,31 +1261,38 @@ namespace MediaBrowser.Api.Playback { if (videoRequest != null) { - videoRequest.MaxWidth = int.Parse(val, UsCulture); + videoRequest.MaxFramerate = double.Parse(val, UsCulture); } } else if (i == 12) { if (videoRequest != null) { - videoRequest.MaxHeight = int.Parse(val, UsCulture); + videoRequest.MaxWidth = int.Parse(val, UsCulture); } } else if (i == 13) { if (videoRequest != null) { - videoRequest.Framerate = int.Parse(val, UsCulture); + videoRequest.MaxHeight = int.Parse(val, UsCulture); } } else if (i == 14) { if (videoRequest != null) { - request.StartTimeTicks = long.Parse(val, UsCulture); + videoRequest.Framerate = int.Parse(val, UsCulture); } } else if (i == 15) + { + if (videoRequest != null) + { + request.StartTimeTicks = long.Parse(val, UsCulture); + } + } + else if (i == 16) { if (videoRequest != null) { diff --git a/MediaBrowser.MediaEncoding/Encoder/ImageEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/ImageEncoder.cs index d259c631d0..e0ca86c41a 100644 --- a/MediaBrowser.MediaEncoding/Encoder/ImageEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/ImageEncoder.cs @@ -1,10 +1,13 @@ -using MediaBrowser.Common.IO; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Model.Logging; using System; using System.Diagnostics; using System.Globalization; using System.IO; +using System.Linq; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -15,16 +18,18 @@ namespace MediaBrowser.MediaEncoding.Encoder private readonly string _ffmpegPath; private readonly ILogger _logger; private readonly IFileSystem _fileSystem; + private readonly IApplicationPaths _appPaths; private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private static readonly SemaphoreSlim ResourcePool = new SemaphoreSlim(10, 10); - public ImageEncoder(string ffmpegPath, ILogger logger, IFileSystem fileSystem) + public ImageEncoder(string ffmpegPath, ILogger logger, IFileSystem fileSystem, IApplicationPaths appPaths) { _ffmpegPath = ffmpegPath; _logger = logger; _fileSystem = fileSystem; + _appPaths = appPaths; } public async Task EncodeImage(ImageEncodingOptions options, CancellationToken cancellationToken) @@ -47,6 +52,15 @@ namespace MediaBrowser.MediaEncoding.Encoder { ValidateInput(options); + var inputPath = options.InputPath; + var filename = Path.GetFileName(inputPath); + + if (HasDiacritics(filename)) + { + inputPath = GetTempFile(inputPath); + filename = Path.GetFileName(inputPath); + } + var process = new Process { StartInfo = new ProcessStartInfo @@ -54,12 +68,12 @@ namespace MediaBrowser.MediaEncoding.Encoder CreateNoWindow = true, UseShellExecute = false, FileName = _ffmpegPath, - Arguments = GetArguments(options), + Arguments = GetArguments(options, filename), WindowStyle = ProcessWindowStyle.Hidden, ErrorDialog = false, RedirectStandardOutput = true, RedirectStandardError = true, - WorkingDirectory = Path.GetDirectoryName(options.InputPath) + WorkingDirectory = Path.GetDirectoryName(inputPath) } }; @@ -113,8 +127,19 @@ namespace MediaBrowser.MediaEncoding.Encoder memoryStream.Position = 0; return memoryStream; } + + private string GetTempFile(string path) + { + var extension = Path.GetExtension(path) ?? string.Empty; + + var tempPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString("N") + extension); + + File.Copy(path, tempPath); + + return tempPath; + } - private string GetArguments(ImageEncodingOptions options) + private string GetArguments(ImageEncodingOptions options, string inputFilename) { var vfScale = GetFilterGraph(options); var outputFormat = GetOutputFormat(options.Format); @@ -127,7 +152,7 @@ namespace MediaBrowser.MediaEncoding.Encoder qualityValue.ToString(_usCulture), vfScale, outputFormat, - Path.GetFileName(options.InputPath)); + inputFilename); } private string GetFilterGraph(ImageEncodingOptions options) @@ -163,10 +188,9 @@ namespace MediaBrowser.MediaEncoding.Encoder var scaleMethod = "lanczos"; - return string.Format("-vf scale=\"{0}:{1}\" -sws_flags {2}", + return string.Format("-vf scale=\"{0}:{1}\"", widthScale, - heightScale, - scaleMethod); + heightScale); } private string GetOutputFormat(string format) @@ -183,5 +207,29 @@ namespace MediaBrowser.MediaEncoding.Encoder { } + + /// + /// Determines whether the specified text has diacritics. + /// + /// The text. + /// true if the specified text has diacritics; otherwise, false. + private bool HasDiacritics(string text) + { + return !String.Equals(text, RemoveDiacritics(text), StringComparison.Ordinal); + } + + /// + /// Removes the diacritics. + /// + /// The text. + /// System.String. + private string RemoveDiacritics(string text) + { + return String.Concat( + text.Normalize(NormalizationForm.FormD) + .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != + UnicodeCategory.NonSpacingMark) + ).Normalize(NormalizationForm.FormC); + } } } diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 8b41d2105f..fac54ecfff 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -911,7 +911,7 @@ namespace MediaBrowser.MediaEncoding.Encoder public Task EncodeImage(ImageEncodingOptions options, CancellationToken cancellationToken) { - return new ImageEncoder(FFMpegPath, _logger, _fileSystem).EncodeImage(options, cancellationToken); + return new ImageEncoder(FFMpegPath, _logger, _fileSystem, _appPaths).EncodeImage(options, cancellationToken); } /// diff --git a/MediaBrowser.Model/Drawing/ImageOutputFormat.cs b/MediaBrowser.Model/Drawing/ImageOutputFormat.cs index 6cbe75a7a0..824970073a 100644 --- a/MediaBrowser.Model/Drawing/ImageOutputFormat.cs +++ b/MediaBrowser.Model/Drawing/ImageOutputFormat.cs @@ -25,6 +25,7 @@ namespace MediaBrowser.Model.Drawing /// /// The PNG /// - Png + Png, + Webp } } diff --git a/MediaBrowser.Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Providers/Music/LastfmArtistProvider.cs index a50e5f9d53..95169aef0c 100644 --- a/MediaBrowser.Providers/Music/LastfmArtistProvider.cs +++ b/MediaBrowser.Providers/Music/LastfmArtistProvider.cs @@ -130,30 +130,6 @@ namespace MediaBrowser.Providers.Music } } - /// - /// Determines whether the specified text has diacritics. - /// - /// The text. - /// true if the specified text has diacritics; otherwise, false. - private bool HasDiacritics(string text) - { - return !String.Equals(text, RemoveDiacritics(text), StringComparison.Ordinal); - } - - /// - /// Removes the diacritics. - /// - /// The text. - /// System.String. - private string RemoveDiacritics(string text) - { - return String.Concat( - text.Normalize(NormalizationForm.FormD) - .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) != - UnicodeCategory.NonSpacingMark) - ).Normalize(NormalizationForm.FormC); - } - /// /// Encodes an URL. /// diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs index 408d8c9b1f..c6c1ec050d 100644 --- a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs +++ b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs @@ -218,36 +218,36 @@ namespace MediaBrowser.Server.Implementations.Drawing { var hasPostProcessing = !string.IsNullOrEmpty(options.BackgroundColor) || options.UnplayedCount.HasValue || options.AddPlayedIndicator || options.PercentPlayed.HasValue; - if (!hasPostProcessing) - { - using (var outputStream = await _mediaEncoder.EncodeImage(new ImageEncodingOptions - { - InputPath = originalImagePath, - MaxHeight = options.MaxHeight, - MaxWidth = options.MaxWidth, - Height = options.Height, - Width = options.Width, - Quality = options.Quality, - Format = options.OutputFormat == ImageOutputFormat.Original ? Path.GetExtension(originalImagePath).TrimStart('.') : options.OutputFormat.ToString().ToLower() + //if (!hasPostProcessing) + //{ + // using (var outputStream = await _mediaEncoder.EncodeImage(new ImageEncodingOptions + // { + // InputPath = originalImagePath, + // MaxHeight = options.MaxHeight, + // MaxWidth = options.MaxWidth, + // Height = options.Height, + // Width = options.Width, + // Quality = options.Quality, + // Format = options.OutputFormat == ImageOutputFormat.Original ? Path.GetExtension(originalImagePath).TrimStart('.') : options.OutputFormat.ToString().ToLower() - }, CancellationToken.None).ConfigureAwait(false)) - { - using (var outputMemoryStream = new MemoryStream()) - { - // Save to the memory stream - await outputStream.CopyToAsync(outputMemoryStream).ConfigureAwait(false); + // }, CancellationToken.None).ConfigureAwait(false)) + // { + // using (var outputMemoryStream = new MemoryStream()) + // { + // // Save to the memory stream + // await outputStream.CopyToAsync(outputMemoryStream).ConfigureAwait(false); - var bytes = outputMemoryStream.ToArray(); + // var bytes = outputMemoryStream.ToArray(); - await toStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); + // await toStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); - // kick off a task to cache the result - await CacheResizedImage(cacheFilePath, bytes).ConfigureAwait(false); - } + // // kick off a task to cache the result + // await CacheResizedImage(cacheFilePath, bytes).ConfigureAwait(false); + // } - return; - } - } + // return; + // } + //} using (var fileStream = _fileSystem.GetFileStream(originalImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true)) {