| | 1 | | using System; |
| | 2 | | using System.Diagnostics.CodeAnalysis; |
| | 3 | | using System.IO; |
| | 4 | | using Emby.Naming.Common; |
| | 5 | | using Jellyfin.Extensions; |
| | 6 | | using Jellyfin.MediaEncoding.Keyframes; |
| | 7 | | using MediaBrowser.Controller.MediaEncoding; |
| | 8 | | using Microsoft.Extensions.Logging; |
| | 9 | | using Extractor = Jellyfin.MediaEncoding.Keyframes.FfProbe.FfProbeKeyframeExtractor; |
| | 10 | |
|
| | 11 | | namespace Jellyfin.MediaEncoding.Hls.Extractors; |
| | 12 | |
|
| | 13 | | /// <inheritdoc /> |
| | 14 | | public class FfProbeKeyframeExtractor : IKeyframeExtractor |
| | 15 | | { |
| | 16 | | private readonly IMediaEncoder _mediaEncoder; |
| | 17 | | private readonly NamingOptions _namingOptions; |
| | 18 | | private readonly ILogger<FfProbeKeyframeExtractor> _logger; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Initializes a new instance of the <see cref="FfProbeKeyframeExtractor"/> class. |
| | 22 | | /// </summary> |
| | 23 | | /// <param name="mediaEncoder">An instance of the <see cref="IMediaEncoder"/> interface.</param> |
| | 24 | | /// <param name="namingOptions">An instance of <see cref="NamingOptions"/>.</param> |
| | 25 | | /// <param name="logger">An instance of the <see cref="ILogger{FfprobeKeyframeExtractor}"/> interface.</param> |
| | 26 | | public FfProbeKeyframeExtractor(IMediaEncoder mediaEncoder, NamingOptions namingOptions, ILogger<FfProbeKeyframeExtr |
| 21 | 27 | | { |
| 21 | 28 | | _mediaEncoder = mediaEncoder; |
| 21 | 29 | | _namingOptions = namingOptions; |
| 21 | 30 | | _logger = logger; |
| 21 | 31 | | } |
| | 32 | |
|
| | 33 | | /// <inheritdoc /> |
| 21 | 34 | | public bool IsMetadataBased => false; |
| | 35 | |
|
| | 36 | | /// <inheritdoc /> |
| | 37 | | public bool TryExtractKeyframes(string filePath, [NotNullWhen(true)] out KeyframeData? keyframeData) |
| 0 | 38 | | { |
| 0 | 39 | | if (!_namingOptions.VideoFileExtensions.Contains(Path.GetExtension(filePath.AsSpan()), StringComparison.OrdinalI |
| 0 | 40 | | { |
| 0 | 41 | | keyframeData = null; |
| 0 | 42 | | return false; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | try |
| 0 | 46 | | { |
| 0 | 47 | | keyframeData = Extractor.GetKeyframeData(_mediaEncoder.ProbePath, filePath); |
| 0 | 48 | | return keyframeData.KeyframeTicks.Count > 0; |
| | 49 | | } |
| 0 | 50 | | catch (Exception ex) |
| 0 | 51 | | { |
| 0 | 52 | | _logger.LogError(ex, "Extracting keyframes from {FilePath} using ffprobe failed", filePath); |
| 0 | 53 | | } |
| | 54 | |
|
| 0 | 55 | | keyframeData = null; |
| 0 | 56 | | return false; |
| 0 | 57 | | } |
| | 58 | | } |