| | | 1 | | using System; |
| | | 2 | | using System.Diagnostics.CodeAnalysis; |
| | | 3 | | using Jellyfin.MediaEncoding.Keyframes; |
| | | 4 | | using Microsoft.Extensions.Logging; |
| | | 5 | | using Extractor = Jellyfin.MediaEncoding.Keyframes.Matroska.MatroskaKeyframeExtractor; |
| | | 6 | | |
| | | 7 | | namespace Jellyfin.MediaEncoding.Hls.Extractors; |
| | | 8 | | |
| | | 9 | | /// <inheritdoc /> |
| | | 10 | | public class MatroskaKeyframeExtractor : IKeyframeExtractor |
| | | 11 | | { |
| | | 12 | | private readonly ILogger<MatroskaKeyframeExtractor> _logger; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Initializes a new instance of the <see cref="MatroskaKeyframeExtractor"/> class. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <param name="logger">An instance of the <see cref="ILogger{MatroskaKeyframeExtractor}"/> interface.</param> |
| | | 18 | | public MatroskaKeyframeExtractor(ILogger<MatroskaKeyframeExtractor> logger) |
| | 21 | 19 | | { |
| | 21 | 20 | | _logger = logger; |
| | 21 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | 21 | 24 | | public bool IsMetadataBased => true; |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public bool TryExtractKeyframes(Guid itemId, string filePath, [NotNullWhen(true)] out KeyframeData? keyframeData) |
| | 0 | 28 | | { |
| | 0 | 29 | | if (!filePath.AsSpan().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase)) |
| | 0 | 30 | | { |
| | 0 | 31 | | keyframeData = null; |
| | 0 | 32 | | return false; |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | try |
| | 0 | 36 | | { |
| | 0 | 37 | | keyframeData = Extractor.GetKeyframeData(filePath); |
| | 0 | 38 | | return keyframeData.KeyframeTicks.Count > 0; |
| | | 39 | | } |
| | 0 | 40 | | catch (Exception ex) |
| | 0 | 41 | | { |
| | 0 | 42 | | _logger.LogError(ex, "Extracting keyframes from {FilePath} using matroska metadata failed", filePath); |
| | 0 | 43 | | } |
| | | 44 | | |
| | 0 | 45 | | keyframeData = null; |
| | 0 | 46 | | return false; |
| | 0 | 47 | | } |
| | | 48 | | } |