2022-11-01 00:53:56 -05:00
|
|
|
namespace ConfusedPolarBear.Plugin.IntroSkipper.Tests;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-11-02 17:06:21 -05:00
|
|
|
using Microsoft.Extensions.Logging;
|
2022-11-01 00:53:56 -05:00
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
public class TestBlackFrames
|
|
|
|
{
|
|
|
|
[FactSkipFFmpegTests]
|
|
|
|
public void TestBlackFrameDetection()
|
|
|
|
{
|
2022-11-02 17:06:21 -05:00
|
|
|
var range = 1e-5;
|
|
|
|
|
2022-11-01 00:53:56 -05:00
|
|
|
var expected = new List<BlackFrame>();
|
|
|
|
expected.AddRange(CreateFrameSequence(2, 3));
|
|
|
|
expected.AddRange(CreateFrameSequence(5, 6));
|
|
|
|
expected.AddRange(CreateFrameSequence(8, 9.96));
|
|
|
|
|
2022-11-02 17:06:21 -05:00
|
|
|
var actual = FFmpegWrapper.DetectBlackFrames(queueFile("rainbow.mp4"), new(0, 10), 85);
|
2022-11-01 00:53:56 -05:00
|
|
|
|
|
|
|
for (var i = 0; i < expected.Count; i++)
|
|
|
|
{
|
|
|
|
var (e, a) = (expected[i], actual[i]);
|
|
|
|
Assert.Equal(e.Percentage, a.Percentage);
|
2022-11-02 17:06:21 -05:00
|
|
|
Assert.InRange(a.Time, e.Time - range, e.Time + range);
|
2022-11-01 00:53:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-02 17:06:21 -05:00
|
|
|
[FactSkipFFmpegTests]
|
|
|
|
public void TestEndCreditDetection()
|
|
|
|
{
|
2022-11-29 20:11:22 -06:00
|
|
|
var range = 1;
|
|
|
|
|
2022-11-02 17:06:21 -05:00
|
|
|
var analyzer = CreateBlackFrameAnalyzer();
|
|
|
|
|
|
|
|
var episode = queueFile("credits.mp4");
|
|
|
|
episode.Duration = (int)new TimeSpan(0, 5, 30).TotalSeconds;
|
|
|
|
|
2024-05-01 11:13:13 +02:00
|
|
|
var result = analyzer.AnalyzeMediaFile(episode, 240, 30, 85);
|
2022-11-02 17:06:21 -05:00
|
|
|
Assert.NotNull(result);
|
2022-11-29 20:11:22 -06:00
|
|
|
Assert.InRange(result.IntroStart, 300 - range, 300 + range);
|
2022-11-02 17:06:21 -05:00
|
|
|
}
|
|
|
|
|
2022-11-01 00:53:56 -05:00
|
|
|
private QueuedEpisode queueFile(string path)
|
|
|
|
{
|
|
|
|
return new()
|
|
|
|
{
|
|
|
|
EpisodeId = Guid.NewGuid(),
|
2022-11-02 17:06:21 -05:00
|
|
|
Name = path,
|
2022-11-01 00:53:56 -05:00
|
|
|
Path = "../../../video/" + path
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private BlackFrame[] CreateFrameSequence(double start, double end)
|
|
|
|
{
|
|
|
|
var frames = new List<BlackFrame>();
|
|
|
|
|
|
|
|
for (var i = start; i < end; i += 0.04)
|
|
|
|
{
|
|
|
|
frames.Add(new(100, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return frames.ToArray();
|
|
|
|
}
|
2022-11-02 17:06:21 -05:00
|
|
|
|
|
|
|
private BlackFrameAnalyzer CreateBlackFrameAnalyzer()
|
|
|
|
{
|
|
|
|
var logger = new LoggerFactory().CreateLogger<BlackFrameAnalyzer>();
|
|
|
|
return new(logger);
|
|
|
|
}
|
2022-11-01 00:53:56 -05:00
|
|
|
}
|