blob: 5304a55f88cf882436831fad27b35243955a06e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
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
{
/// <summary>
/// Manager class for the set of keyframe extractors.
/// </summary>
public class KeyframeExtractor
{
private readonly ILogger<KeyframeExtractor> _logger;
/// <summary>
/// Initializes a new instance of the <see cref="KeyframeExtractor"/> class.
/// </summary>
/// <param name="logger">An instance of the <see cref="ILogger{KeyframeExtractor}"/> interface.</param>
public KeyframeExtractor(ILogger<KeyframeExtractor> logger)
{
_logger = logger;
}
/// <summary>
/// Extracts the keyframe positions from a video file.
/// </summary>
/// <param name="filePath">Absolute file path to the media file.</param>
/// <param name="ffProbePath">Absolute file path to the ffprobe executable.</param>
/// <param name="ffToolPath">Absolute file path to the fftool executable.</param>
/// <returns>An instance of <see cref="KeyframeData"/>.</returns>
public KeyframeData GetKeyframeData(string filePath, string ffProbePath, string ffToolPath)
{
var extension = Path.GetExtension(filePath.AsSpan());
if (extension.Equals(".mkv", StringComparison.OrdinalIgnoreCase))
{
try
{
return MatroskaKeyframeExtractor.GetKeyframeData(filePath);
}
catch (Exception ex)
{
_logger.LogError(ex, "{ExtractorType} failed to extract keyframes", nameof(MatroskaKeyframeExtractor));
}
}
try
{
return FfToolKeyframeExtractor.GetKeyframeData(ffToolPath, filePath);
}
catch (Exception ex)
{
_logger.LogError(ex, "{ExtractorType} failed to extract keyframes", nameof(FfToolKeyframeExtractor));
}
try
{
return FfProbeKeyframeExtractor.GetKeyframeData(ffProbePath, filePath);
}
catch (Exception ex)
{
_logger.LogError(ex, "{ExtractorType} failed to extract keyframes", nameof(FfProbeKeyframeExtractor));
}
return new KeyframeData(0, Array.Empty<long>());
}
}
}
|