Skip to content

Commit

Permalink
Add option to extract keyframe only during trickplay image generation
Browse files Browse the repository at this point in the history
This would be significantly faster than decoding every frame, but it does have compatibility issues. Not all decoders support this mode, notably the VP9 decoder, CUVID decoders, and QSV decoders.

Some videos with very long key-frame intervals may also perform poorly with this mode, as the image timing could become too inaccurate to reflect the actual frame.

Signed-off-by: gnattu <gnattuoc@me.com>
  • Loading branch information
gnattu committed May 8, 2024
1 parent 8c583bb commit 2086d2e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public async Task RefreshTrickplayDataAsync(Video video, bool replace, Cancellat
options.ProcessThreads,
options.Qscale,
options.ProcessPriority,
options.EnableKeyFrameOnlyExtraction,
_encodingHelper,
cancellationToken).ConfigureAwait(false);

Expand Down
2 changes: 2 additions & 0 deletions MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public interface IMediaEncoder : ITranscoderSupport
/// <param name="threads">The input/output thread count for ffmpeg.</param>
/// <param name="qualityScale">The qscale value for ffmpeg.</param>
/// <param name="priority">The process priority for the ffmpeg process.</param>
/// <param name="enableKeyFrameOnlyExtraction">Whether to only extract key frames.</param>
/// <param name="encodingHelper">EncodingHelper instance.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Directory where images where extracted. A given image made before another will always be named with a lower number.</returns>
Expand All @@ -168,6 +169,7 @@ public interface IMediaEncoder : ITranscoderSupport
int? threads,
int? qualityScale,
ProcessPriorityClass? priority,
bool enableKeyFrameOnlyExtraction,
EncodingHelper encodingHelper,
CancellationToken cancellationToken);

Expand Down
6 changes: 6 additions & 0 deletions MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ private async Task<string> ExtractImageInternal(string inputPath, string contain
int? threads,
int? qualityScale,
ProcessPriorityClass? priority,
bool enableKeyFrameOnlyExtraction,
EncodingHelper encodingHelper,
CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -848,6 +849,11 @@ private async Task<string> ExtractImageInternal(string inputPath, string contain
inputArg = "-threads " + threads + " " + inputArg; // HW accel args set a different input thread count, only set if disabled
}

if (enableKeyFrameOnlyExtraction)
{
inputArg = "-skip_frame nokey " + inputArg;
}

var filterParam = encodingHelper.GetVideoProcessingFilterParam(jobState, options, vidEncoder).Trim();
if (string.IsNullOrWhiteSpace(filterParam))
{
Expand Down
6 changes: 6 additions & 0 deletions MediaBrowser.Model/Configuration/TrickplayOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class TrickplayOptions
/// </summary>
public bool EnableHwEncoding { get; set; } = false;

/// <summary>
/// Gets or sets a value indicating whether to only extract key frames.
/// Significantly faster, but is not compatible with all decoders and/or video files.
/// </summary>
public bool EnableKeyFrameOnlyExtraction { get; set; } = false;

/// <summary>
/// Gets or sets the behavior used by trickplay provider on library scan/update.
/// </summary>
Expand Down

0 comments on commit 2086d2e

Please sign in to comment.