aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MediaBrowser.Api/Playback/BaseStreamingService.cs17
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/ImageEncoder.cs66
-rw-r--r--MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs2
-rw-r--r--MediaBrowser.Model/Drawing/ImageOutputFormat.cs3
-rw-r--r--MediaBrowser.Providers/Music/LastfmArtistProvider.cs24
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs60
6 files changed, 101 insertions, 71 deletions
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs
index b510a640e..519ff7947 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,34 +1261,41 @@ 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)
+ {
videoRequest.Level = val;
}
}
diff --git a/MediaBrowser.MediaEncoding/Encoder/ImageEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/ImageEncoder.cs
index d259c631d..e0ca86c41 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<Stream> 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
{
}
+
+ /// <summary>
+ /// Determines whether the specified text has diacritics.
+ /// </summary>
+ /// <param name="text">The text.</param>
+ /// <returns><c>true</c> if the specified text has diacritics; otherwise, <c>false</c>.</returns>
+ private bool HasDiacritics(string text)
+ {
+ return !String.Equals(text, RemoveDiacritics(text), StringComparison.Ordinal);
+ }
+
+ /// <summary>
+ /// Removes the diacritics.
+ /// </summary>
+ /// <param name="text">The text.</param>
+ /// <returns>System.String.</returns>
+ 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 8b41d2105..fac54ecff 100644
--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
@@ -911,7 +911,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
public Task<Stream> EncodeImage(ImageEncodingOptions options, CancellationToken cancellationToken)
{
- return new ImageEncoder(FFMpegPath, _logger, _fileSystem).EncodeImage(options, cancellationToken);
+ return new ImageEncoder(FFMpegPath, _logger, _fileSystem, _appPaths).EncodeImage(options, cancellationToken);
}
/// <summary>
diff --git a/MediaBrowser.Model/Drawing/ImageOutputFormat.cs b/MediaBrowser.Model/Drawing/ImageOutputFormat.cs
index 6cbe75a7a..824970073 100644
--- a/MediaBrowser.Model/Drawing/ImageOutputFormat.cs
+++ b/MediaBrowser.Model/Drawing/ImageOutputFormat.cs
@@ -25,6 +25,7 @@ namespace MediaBrowser.Model.Drawing
/// <summary>
/// The PNG
/// </summary>
- Png
+ Png,
+ Webp
}
}
diff --git a/MediaBrowser.Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Providers/Music/LastfmArtistProvider.cs
index a50e5f9d5..95169aef0 100644
--- a/MediaBrowser.Providers/Music/LastfmArtistProvider.cs
+++ b/MediaBrowser.Providers/Music/LastfmArtistProvider.cs
@@ -131,30 +131,6 @@ namespace MediaBrowser.Providers.Music
}
/// <summary>
- /// Determines whether the specified text has diacritics.
- /// </summary>
- /// <param name="text">The text.</param>
- /// <returns><c>true</c> if the specified text has diacritics; otherwise, <c>false</c>.</returns>
- private bool HasDiacritics(string text)
- {
- return !String.Equals(text, RemoveDiacritics(text), StringComparison.Ordinal);
- }
-
- /// <summary>
- /// Removes the diacritics.
- /// </summary>
- /// <param name="text">The text.</param>
- /// <returns>System.String.</returns>
- private string RemoveDiacritics(string text)
- {
- return String.Concat(
- text.Normalize(NormalizationForm.FormD)
- .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) !=
- UnicodeCategory.NonSpacingMark)
- ).Normalize(NormalizationForm.FormC);
- }
-
- /// <summary>
/// Encodes an URL.
/// </summary>
/// <param name="name">The name.</param>
diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
index 408d8c9b1..c6c1ec050 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()
-
- }, CancellationToken.None).ConfigureAwait(false))
- {
- using (var outputMemoryStream = new MemoryStream())
- {
- // Save to the memory stream
- await outputStream.CopyToAsync(outputMemoryStream).ConfigureAwait(false);
-
- var bytes = outputMemoryStream.ToArray();
-
- await toStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
-
- // kick off a task to cache the result
- await CacheResizedImage(cacheFilePath, bytes).ConfigureAwait(false);
- }
-
- return;
- }
- }
+ //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);
+
+ // var bytes = outputMemoryStream.ToArray();
+
+ // await toStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
+
+ // // kick off a task to cache the result
+ // await CacheResizedImage(cacheFilePath, bytes).ConfigureAwait(false);
+ // }
+
+ // return;
+ // }
+ //}
using (var fileStream = _fileSystem.GetFileStream(originalImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
{