< Summary

Information
Class: Anichron.Worker.Ingestion.Proxy.FfmpegFrameExtractor
Assembly: Anichron.Worker
File(s): /home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Proxy/VideoFrameExtractor.cs
Tag: 19_45211875487
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 30
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExtractAsync()100%44100%
ReadFrameAsync(...)100%11100%

File(s)

/home/runner/work/anichron/anichron/src/Anichron.Worker/Ingestion/Proxy/VideoFrameExtractor.cs

#LineLine coverage
 1using Anichron.Worker.Settings;
 2using Microsoft.Extensions.Options;
 3using SixLabors.ImageSharp;
 4using SixLabors.ImageSharp.PixelFormats;
 5
 6namespace Anichron.Worker.Ingestion.Proxy;
 7
 8internal interface IVideoFrameExtractor
 9{
 10    Task<Image<Rgb24>> ExtractAsync(string sourcePath, CancellationToken ct);
 11}
 12
 513internal sealed class FfmpegFrameExtractor(IProcessLauncher processLauncher, IOptions<WorkerSettings> options) : IVideoF
 14{
 15    public async Task<Image<Rgb24>> ExtractAsync(string sourcePath, CancellationToken ct)
 516    {
 517        var frame = await ReadFrameAsync(["-ss", "1", "-i", sourcePath], ct);
 418        if (frame.Length == 0)
 319            frame = await ReadFrameAsync(["-i", sourcePath], ct);
 320        if (frame.Length == 0)
 121            throw new FfmpegException($"FFmpeg read no frame from {sourcePath}.");
 222        return Image.Load<Rgb24>(frame);
 223    }
 24
 25    private Task<byte[]> ReadFrameAsync(string[] input, CancellationToken ct)
 826        => processLauncher.RunFfmpegQuietlyAsync(
 827            options.Value.FfmpegPath,
 828            [.. input, "-frames:v", "1", "-pix_fmt", "rgb24", "-c:v", "png", "-f", "image2pipe", "-"],
 829            ct);
 30}