Merge pull request #8137 from negulici-r-barnabas/master

This commit is contained in:
Cody Robibero 2022-11-27 07:53:18 -07:00 committed by GitHub
commit d4bd72049b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 8 deletions

View File

@ -51,6 +51,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly ILocalizationManager _localization; private readonly ILocalizationManager _localization;
private readonly IConfiguration _config; private readonly IConfiguration _config;
private readonly IServerConfigurationManager _serverConfig;
private readonly string _startupOptionFFmpegPath; private readonly string _startupOptionFFmpegPath;
private readonly SemaphoreSlim _thumbnailResourcePool = new SemaphoreSlim(2, 2); private readonly SemaphoreSlim _thumbnailResourcePool = new SemaphoreSlim(2, 2);
@ -93,13 +94,15 @@ namespace MediaBrowser.MediaEncoding.Encoder
IServerConfigurationManager configurationManager, IServerConfigurationManager configurationManager,
IFileSystem fileSystem, IFileSystem fileSystem,
ILocalizationManager localization, ILocalizationManager localization,
IConfiguration config) IConfiguration config,
IServerConfigurationManager serverConfig)
{ {
_logger = logger; _logger = logger;
_configurationManager = configurationManager; _configurationManager = configurationManager;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_localization = localization; _localization = localization;
_config = config; _config = config;
_serverConfig = serverConfig;
_startupOptionFFmpegPath = config.GetValue<string>(Controller.Extensions.ConfigurationExtensions.FfmpegPathKey) ?? string.Empty; _startupOptionFFmpegPath = config.GetValue<string>(Controller.Extensions.ConfigurationExtensions.FfmpegPathKey) ?? string.Empty;
_jsonSerializerOptions = JsonDefaults.Options; _jsonSerializerOptions = JsonDefaults.Options;
} }
@ -606,6 +609,32 @@ namespace MediaBrowser.MediaEncoding.Encoder
return await ExtractImageInternal(inputArgument, container, videoStream, imageStreamIndex, threedFormat, offset, false, targetFormat, cancellationToken).ConfigureAwait(false); return await ExtractImageInternal(inputArgument, container, videoStream, imageStreamIndex, threedFormat, offset, false, targetFormat, cancellationToken).ConfigureAwait(false);
} }
private string GetImageResolutionParameter()
{
string imageResolutionParameter;
imageResolutionParameter = _serverConfig.Configuration.ChapterImageResolution switch
{
ImageResolution.P144 => "256x144",
ImageResolution.P240 => "426x240",
ImageResolution.P360 => "640x360",
ImageResolution.P480 => "854x480",
ImageResolution.P720 => "1280x720",
ImageResolution.P1080 => "1920x1080",
ImageResolution.P1440 => "2560x1440",
ImageResolution.P2160 => "3840x2160",
_ => string.Empty
};
if (!string.IsNullOrEmpty(imageResolutionParameter))
{
imageResolutionParameter = " -s " + imageResolutionParameter;
}
return imageResolutionParameter;
}
private async Task<string> ExtractImageInternal(string inputPath, string container, MediaStream videoStream, int? imageStreamIndex, Video3DFormat? threedFormat, TimeSpan? offset, bool useIFrame, ImageFormat? targetFormat, CancellationToken cancellationToken) private async Task<string> ExtractImageInternal(string inputPath, string container, MediaStream videoStream, int? imageStreamIndex, Video3DFormat? threedFormat, TimeSpan? offset, bool useIFrame, ImageFormat? targetFormat, CancellationToken cancellationToken)
{ {
if (string.IsNullOrEmpty(inputPath)) if (string.IsNullOrEmpty(inputPath))
@ -676,7 +705,7 @@ namespace MediaBrowser.MediaEncoding.Encoder
var vf = string.Join(',', filters); var vf = string.Join(',', filters);
var mapArg = imageStreamIndex.HasValue ? (" -map 0:" + imageStreamIndex.Value.ToString(CultureInfo.InvariantCulture)) : string.Empty; var mapArg = imageStreamIndex.HasValue ? (" -map 0:" + imageStreamIndex.Value.ToString(CultureInfo.InvariantCulture)) : string.Empty;
var args = string.Format(CultureInfo.InvariantCulture, "-i {0}{3} -threads {4} -v quiet -vframes 1 -vf {2} -f image2 \"{1}\"", inputPath, tempExtractPath, vf, mapArg, _threads); var args = string.Format(CultureInfo.InvariantCulture, "-i {0}{3} -threads {4} -v quiet -vframes 1 -vf {2}{5} -f image2 \"{1}\"", inputPath, tempExtractPath, vf, mapArg, _threads, GetImageResolutionParameter());
if (offset.HasValue) if (offset.HasValue)
{ {

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Updates; using MediaBrowser.Model.Updates;
@ -240,5 +241,23 @@ namespace MediaBrowser.Model.Configuration
/// Gets or sets a value indicating whether clients should be allowed to upload logs. /// Gets or sets a value indicating whether clients should be allowed to upload logs.
/// </summary> /// </summary>
public bool AllowClientLogUpload { get; set; } = true; public bool AllowClientLogUpload { get; set; } = true;
/// <summary>
/// Gets or sets the dummy chapters duration in seconds.
/// </summary>
/// <value>The dummy chapters duration.</value>
public int DummyChapterDuration { get; set; } = 300;
/// <summary>
/// Gets or sets the dummy chapter count.
/// </summary>
/// <value>The dummy chapter count.</value>
public int DummyChapterCount { get; set; } = 100;
/// <summary>
/// Gets or sets the chapter image resolution.
/// </summary>
/// <value>The chapter image resolution.</value>
public ImageResolution ChapterImageResolution { get; set; } = ImageResolution.MatchSource;
} }
} }

View File

@ -0,0 +1,52 @@
namespace MediaBrowser.Model.Drawing;
/// <summary>
/// Enum ImageResolution.
/// </summary>
public enum ImageResolution
{
/// <summary>
/// MatchSource.
/// </summary>
MatchSource = 0,
/// <summary>
/// 144p.
/// </summary>
P144 = 1,
/// <summary>
/// 240p.
/// </summary>
P240 = 2,
/// <summary>
/// 360p.
/// </summary>
P360 = 3,
/// <summary>
/// 480p.
/// </summary>
P480 = 4,
/// <summary>
/// 720p.
/// </summary>
P720 = 5,
/// <summary>
/// 1080p.
/// </summary>
P1080 = 6,
/// <summary>
/// 1440p.
/// </summary>
P1440 = 7,
/// <summary>
/// 2160p.
/// </summary>
P2160 = 8
}

View File

@ -48,8 +48,6 @@ namespace MediaBrowser.Providers.MediaInfo
private readonly SubtitleResolver _subtitleResolver; private readonly SubtitleResolver _subtitleResolver;
private readonly IMediaSourceManager _mediaSourceManager; private readonly IMediaSourceManager _mediaSourceManager;
private readonly long _dummyChapterDuration = TimeSpan.FromMinutes(5).Ticks;
public FFProbeVideoInfo( public FFProbeVideoInfo(
ILogger<FFProbeVideoInfo> logger, ILogger<FFProbeVideoInfo> logger,
IMediaSourceManager mediaSourceManager, IMediaSourceManager mediaSourceManager,
@ -651,6 +649,7 @@ namespace MediaBrowser.Providers.MediaInfo
private ChapterInfo[] CreateDummyChapters(Video video) private ChapterInfo[] CreateDummyChapters(Video video)
{ {
var runtime = video.RunTimeTicks ?? 0; var runtime = video.RunTimeTicks ?? 0;
long dummyChapterDuration = TimeSpan.FromSeconds(_config.Configuration.DummyChapterDuration).Ticks;
if (runtime < 0) if (runtime < 0)
{ {
@ -662,13 +661,13 @@ namespace MediaBrowser.Providers.MediaInfo
runtime)); runtime));
} }
if (runtime < _dummyChapterDuration) if (runtime < dummyChapterDuration)
{ {
return Array.Empty<ChapterInfo>(); return Array.Empty<ChapterInfo>();
} }
// Limit to 100 chapters just in case there's some incorrect metadata here // Limit the chapters just in case there's some incorrect metadata here
int chapterCount = (int)Math.Min(runtime / _dummyChapterDuration, 100); int chapterCount = (int)Math.Min(runtime / dummyChapterDuration, _config.Configuration.DummyChapterCount);
var chapters = new ChapterInfo[chapterCount]; var chapters = new ChapterInfo[chapterCount];
long currentChapterTicks = 0; long currentChapterTicks = 0;
@ -679,7 +678,7 @@ namespace MediaBrowser.Providers.MediaInfo
StartPositionTicks = currentChapterTicks StartPositionTicks = currentChapterTicks
}; };
currentChapterTicks += _dummyChapterDuration; currentChapterTicks += dummyChapterDuration;
} }
return chapters; return chapters;