From dd8ef08592830236b31307e2424b491e974f024a Mon Sep 17 00:00:00 2001 From: Nick <20588554+nicknsy@users.noreply.github.com> Date: Wed, 29 Mar 2023 16:43:17 -0700 Subject: [PATCH] Move fps filter to GetVideoProcessingFilterParam --- .../MediaEncoding/EncodingHelper.cs | 9 +++++++++ .../Encoder/MediaEncoder.cs | 19 ++++--------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index 0889a90f4..bcdf2934a 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -4806,6 +4806,15 @@ namespace MediaBrowser.Controller.MediaEncoding subFilters?.RemoveAll(filter => string.IsNullOrEmpty(filter)); overlayFilters?.RemoveAll(filter => string.IsNullOrEmpty(filter)); + var framerate = GetFramerateParam(state); + if (framerate.HasValue) + { + mainFilters.Insert(0, string.Format( + CultureInfo.InvariantCulture, + "fps={0}", + framerate.Value)); + } + var mainStr = string.Empty; if (mainFilters?.Count > 0) { diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 11f42c3f9..4692bf504 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -804,7 +804,7 @@ namespace MediaBrowser.MediaEncoding.Encoder options.EnableTonemapping = false; } - var baseRequest = new BaseEncodingJobOptions { MaxWidth = maxWidth }; + var baseRequest = new BaseEncodingJobOptions { MaxWidth = maxWidth, MaxFramerate = (float)(1.0 / interval.TotalSeconds) }; var jobState = new EncodingJobInfo(TranscodingJobType.Progressive) { IsVideoRequest = true, // must be true for InputVideoHwaccelArgs to return non-empty value @@ -829,18 +829,17 @@ namespace MediaBrowser.MediaEncoding.Encoder } var filterParam = encodingHelper.GetVideoProcessingFilterParam(jobState, options, jobState.OutputVideoCodec).Trim(); - if (string.IsNullOrWhiteSpace(filterParam) || filterParam.IndexOf("\"", StringComparison.Ordinal) == -1) + if (string.IsNullOrWhiteSpace(filterParam)) { throw new InvalidOperationException("EncodingHelper returned empty or invalid filter parameters."); } - return ExtractVideoImagesOnIntervalInternal(inputArg, filterParam, interval, vidEncoder, threads, qualityScale, priority, cancellationToken); + return ExtractVideoImagesOnIntervalInternal(inputArg, filterParam, vidEncoder, threads, qualityScale, priority, cancellationToken); } private async Task ExtractVideoImagesOnIntervalInternal( string inputArg, string filterParam, - TimeSpan interval, string vidEncoder, int? outputThreads, int? qualityScale, @@ -853,16 +852,6 @@ namespace MediaBrowser.MediaEncoding.Encoder } // Output arguments - string fps = "fps=1/" + interval.TotalSeconds.ToString(CultureInfo.InvariantCulture); - if (string.IsNullOrWhiteSpace(filterParam)) - { - filterParam = "-vf \"" + fps + "\""; - } - else if (filterParam.IndexOf("\"", StringComparison.Ordinal) != -1) - { - filterParam = filterParam.Insert(filterParam.IndexOf("\"", StringComparison.Ordinal) + 1, fps + ","); - } - var targetDirectory = Path.Combine(_configurationManager.ApplicationPaths.TempDirectory, Guid.NewGuid().ToString("N")); Directory.CreateDirectory(targetDirectory); var outputPath = Path.Combine(targetDirectory, "%08d.jpg"); @@ -895,7 +884,7 @@ namespace MediaBrowser.MediaEncoding.Encoder }; var processDescription = string.Format(CultureInfo.InvariantCulture, "{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); - _logger.LogDebug("{ProcessDescription}", processDescription); + _logger.LogInformation("Trickplay generation: {ProcessDescription}", processDescription); using (var processWrapper = new ProcessWrapper(process, this)) {