From 9c15f96e12a0d48a70cbca8380bf78a4f2512b03 Mon Sep 17 00:00:00 2001 From: cvium Date: Thu, 23 Sep 2021 15:29:12 +0200 Subject: Add first draft of keyframe extraction for Matroska --- .../KeyframeExtractor.cs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/Jellyfin.MediaEncoding.Keyframes/KeyframeExtractor.cs (limited to 'src/Jellyfin.MediaEncoding.Keyframes/KeyframeExtractor.cs') diff --git a/src/Jellyfin.MediaEncoding.Keyframes/KeyframeExtractor.cs b/src/Jellyfin.MediaEncoding.Keyframes/KeyframeExtractor.cs new file mode 100644 index 000000000..2ee6b43e6 --- /dev/null +++ b/src/Jellyfin.MediaEncoding.Keyframes/KeyframeExtractor.cs @@ -0,0 +1,56 @@ +using System; +using System.IO; +using Jellyfin.MediaEncoding.Keyframes.FfProbe; +using Jellyfin.MediaEncoding.Keyframes.FfTool; +using Jellyfin.MediaEncoding.Keyframes.Matroska; +using Microsoft.Extensions.Logging; + +namespace Jellyfin.MediaEncoding.Keyframes +{ + /// + /// Manager class for the set of keyframe extractors. + /// + public class KeyframeExtractor + { + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + /// An instance of the interface. + public KeyframeExtractor(ILogger logger) + { + _logger = logger; + } + + /// + /// Extracts the keyframe positions from a video file. + /// + /// Absolute file path to the media file. + /// Absolute file path to the ffprobe executable. + /// Absolute file path to the fftool executable. + /// + public KeyframeData GetKeyframeData(string filePath, string ffProbePath, string ffToolPath) + { + var extension = Path.GetExtension(filePath); + if (string.Equals(extension, ".mkv", StringComparison.OrdinalIgnoreCase)) + { + try + { + return MatroskaKeyframeExtractor.GetKeyframeData(filePath); + } + catch (InvalidOperationException ex) + { + _logger.LogError(ex, "{MatroskaKeyframeExtractor} failed to extract keyframes", nameof(MatroskaKeyframeExtractor)); + } + } + + if (!string.IsNullOrEmpty(ffToolPath)) + { + return FfToolKeyframeExtractor.GetKeyframeData(ffToolPath, filePath); + } + + return FfProbeKeyframeExtractor.GetKeyframeData(ffProbePath, filePath); + } + } +} -- cgit v1.2.3