Bugfix-FFmpegWrapper
This commit is contained in:
parent
9abcf253a7
commit
3b4c4bf464
@ -81,7 +81,7 @@ public class TestAudioFingerprinting
|
|||||||
{77, 5},
|
{77, 5},
|
||||||
};
|
};
|
||||||
|
|
||||||
var actual = FFmpegWrapper.CreateInvertedIndex(Guid.NewGuid(), fpr);
|
var actual = FFmpegWrapper.CreateInvertedIndex(Guid.NewGuid(), fpr, AnalysisMode.Introduction);
|
||||||
|
|
||||||
Assert.Equal(expected, actual);
|
Assert.Equal(expected, actual);
|
||||||
}
|
}
|
||||||
|
@ -261,8 +261,8 @@ public class ChromaprintAnalyzer : IMediaFileAnalyzer
|
|||||||
var rhsRanges = new List<TimeRange>();
|
var rhsRanges = new List<TimeRange>();
|
||||||
|
|
||||||
// Generate inverted indexes for the left and right episodes.
|
// Generate inverted indexes for the left and right episodes.
|
||||||
var lhsIndex = FFmpegWrapper.CreateInvertedIndex(lhsId, lhsPoints);
|
var lhsIndex = FFmpegWrapper.CreateInvertedIndex(lhsId, lhsPoints, this._analysisMode);
|
||||||
var rhsIndex = FFmpegWrapper.CreateInvertedIndex(rhsId, rhsPoints);
|
var rhsIndex = FFmpegWrapper.CreateInvertedIndex(rhsId, rhsPoints, this._analysisMode);
|
||||||
var indexShifts = new HashSet<int>();
|
var indexShifts = new HashSet<int>();
|
||||||
|
|
||||||
// For all audio points in the left episode, check if the right episode has a point which matches exactly.
|
// For all audio points in the left episode, check if the right episode has a point which matches exactly.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
@ -14,8 +15,6 @@ namespace ConfusedPolarBear.Plugin.IntroSkipper;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class FFmpegWrapper
|
public static class FFmpegWrapper
|
||||||
{
|
{
|
||||||
private static readonly object InvertedIndexCacheLock = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used with FFmpeg's silencedetect filter to extract the start and end times of silence.
|
/// Used with FFmpeg's silencedetect filter to extract the start and end times of silence.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -34,7 +33,7 @@ public static class FFmpegWrapper
|
|||||||
|
|
||||||
private static Dictionary<string, string> ChromaprintLogs { get; set; } = new();
|
private static Dictionary<string, string> ChromaprintLogs { get; set; } = new();
|
||||||
|
|
||||||
private static Dictionary<Guid, Dictionary<uint, int>> InvertedIndexCache { get; set; } = new();
|
private static ConcurrentDictionary<AnalysisMode, ConcurrentDictionary<Guid, Dictionary<uint, int>>> InvertedIndexCache { get; set; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check that the installed version of ffmpeg supports chromaprint.
|
/// Check that the installed version of ffmpeg supports chromaprint.
|
||||||
@ -137,16 +136,17 @@ public static class FFmpegWrapper
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">Episode ID.</param>
|
/// <param name="id">Episode ID.</param>
|
||||||
/// <param name="fingerprint">Chromaprint fingerprint.</param>
|
/// <param name="fingerprint">Chromaprint fingerprint.</param>
|
||||||
|
/// <param name="mode">Mode.</param>
|
||||||
/// <returns>Inverted index.</returns>
|
/// <returns>Inverted index.</returns>
|
||||||
public static Dictionary<uint, int> CreateInvertedIndex(Guid id, uint[] fingerprint)
|
public static Dictionary<uint, int> CreateInvertedIndex(Guid id, uint[] fingerprint, AnalysisMode mode)
|
||||||
{
|
{
|
||||||
lock (InvertedIndexCacheLock)
|
var innerDictionary = InvertedIndexCache.GetOrAdd(mode, _ => new ConcurrentDictionary<Guid, Dictionary<uint, int>>());
|
||||||
{
|
|
||||||
if (InvertedIndexCache.TryGetValue(id, out var cached))
|
// Check if cached for the ID
|
||||||
|
if (innerDictionary.TryGetValue(id, out var cached))
|
||||||
{
|
{
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var invIndex = new Dictionary<uint, int>();
|
var invIndex = new Dictionary<uint, int>();
|
||||||
|
|
||||||
@ -159,10 +159,7 @@ public static class FFmpegWrapper
|
|||||||
invIndex[point] = i;
|
invIndex[point] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (InvertedIndexCacheLock)
|
innerDictionary[id] = invIndex;
|
||||||
{
|
|
||||||
InvertedIndexCache[id] = invIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
return invIndex;
|
return invIndex;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user