71 lines
1.9 KiB
C#
Raw Normal View History

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()
{
var analyzer = CreateBlackFrameAnalyzer();
var episode = queueFile("credits.mp4");
episode.Duration = (int)new TimeSpan(0, 5, 30).TotalSeconds;
var result = analyzer.AnalyzeMediaFile(episode, AnalysisMode.Credits, 85);
Assert.NotNull(result);
Assert.Equal(300, result.IntroStart);
}
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
}