diff options
| author | Bond-009 <bond.009@outlook.com> | 2024-09-12 21:44:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-12 13:44:57 -0600 |
| commit | 6b646e24eabdfdd150f1ff72f837d37b43f3b985 (patch) | |
| tree | 3552333df64baa236a6f0ce3ea8a98c2272a2656 /Emby.Server.Implementations | |
| parent | 62712aa12cdc88c524923cb318783b23a8a7a2c5 (diff) | |
Don't extract chapter images if chapters are <1s long on average (#11832)
Diffstat (limited to 'Emby.Server.Implementations')
| -rw-r--r-- | Emby.Server.Implementations/MediaEncoder/EncodingManager.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Emby.Server.Implementations/MediaEncoder/EncodingManager.cs b/Emby.Server.Implementations/MediaEncoder/EncodingManager.cs index 896f47923..784bac5d0 100644 --- a/Emby.Server.Implementations/MediaEncoder/EncodingManager.cs +++ b/Emby.Server.Implementations/MediaEncoder/EncodingManager.cs @@ -91,8 +91,30 @@ namespace Emby.Server.Implementations.MediaEncoder return video.DefaultVideoStreamIndex.HasValue; } + private long GetAverageDurationBetweenChapters(IReadOnlyList<ChapterInfo> chapters) + { + if (chapters.Count < 2) + { + return 0; + } + + long sum = 0; + for (int i = 1; i < chapters.Count; i++) + { + sum += chapters[i].StartPositionTicks - chapters[i - 1].StartPositionTicks; + } + + return sum / chapters.Count; + } + + public async Task<bool> RefreshChapterImages(Video video, IDirectoryService directoryService, IReadOnlyList<ChapterInfo> chapters, bool extractImages, bool saveChapters, CancellationToken cancellationToken) { + if (chapters.Count == 0) + { + return true; + } + var libraryOptions = _libraryManager.GetLibraryOptions(video); if (!IsEligibleForChapterImageExtraction(video, libraryOptions)) @@ -100,6 +122,14 @@ namespace Emby.Server.Implementations.MediaEncoder extractImages = false; } + var averageChapterDuration = GetAverageDurationBetweenChapters(chapters); + var threshold = TimeSpan.FromSeconds(1).Ticks; + if (averageChapterDuration < threshold) + { + _logger.LogInformation("Skipping chapter image extraction for {Video} as the average chapter duration {AverageDuration} was lower than the minimum threshold {Threshold}", video.Name, averageChapterDuration, threshold); + extractImages = false; + } + var success = true; var changesMade = false; |
