using System; using System.Diagnostics.CodeAnalysis; using Jellyfin.MediaEncoding.Keyframes; using Microsoft.Extensions.Logging; using Extractor = Jellyfin.MediaEncoding.Keyframes.Matroska.MatroskaKeyframeExtractor; namespace Jellyfin.MediaEncoding.Hls.Extractors; /// public class MatroskaKeyframeExtractor : IKeyframeExtractor { private readonly ILogger _logger; /// /// Initializes a new instance of the class. /// /// An instance of the interface. public MatroskaKeyframeExtractor(ILogger logger) { _logger = logger; } /// public bool IsMetadataBased => true; /// public bool TryExtractKeyframes(string filePath, [NotNullWhen(true)] out KeyframeData? keyframeData) { if (!filePath.AsSpan().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) { keyframeData = null; return false; } try { keyframeData = Extractor.GetKeyframeData(filePath); return keyframeData.KeyframeTicks.Count > 0; } catch (Exception ex) { _logger.LogError(ex, "Extracting keyframes from {FilePath} using matroska metadata failed", filePath); } keyframeData = null; return false; } }