From a88010d7a102768205cfd766d0bb5cc04c69e4d8 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sun, 26 Jul 2020 02:55:42 +0200 Subject: [PATCH] Changed input for SeekedFileInputArgument Former-commit-id: ef49542de050427926ae89c98a6f7f7d13d2b789 --- .../Arguments/SeekedFileInputArgument.cs | 19 +++++++++++-------- FFMpegCore/FFMpeg/FFMpeg.cs | 2 +- FFMpegCore/FFMpeg/FFMpegArguments.cs | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/FFMpegCore/FFMpeg/Arguments/SeekedFileInputArgument.cs b/FFMpegCore/FFMpeg/Arguments/SeekedFileInputArgument.cs index 6770b8e..4a29116 100644 --- a/FFMpegCore/FFMpeg/Arguments/SeekedFileInputArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/SeekedFileInputArgument.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -7,22 +8,24 @@ namespace FFMpegCore.Arguments { public class SeekedFileInputArgument : IInputArgument { - public readonly string FilePath; - public readonly TimeSpan StartTime; + public readonly (string FilePath, TimeSpan StartTime)[] SeekedFiles; - public SeekedFileInputArgument(string filePath, TimeSpan startTime) + public SeekedFileInputArgument((string file, TimeSpan startTime)[] seekedFiles) { - FilePath = filePath; - StartTime = startTime; + SeekedFiles = seekedFiles; } + public void Pre() { - if (!File.Exists(FilePath)) - throw new FileNotFoundException("Input file not found", FilePath); + foreach (var (seekedFile, _) in SeekedFiles) + { + if (!File.Exists(seekedFile)) + throw new FileNotFoundException("Input file not found", seekedFile); + } } public Task During(CancellationToken? cancellationToken = null) => Task.CompletedTask; public void Post() { } - public string Text => $"-ss {StartTime} -i \"{FilePath}\""; + public string Text => string.Join(" ", SeekedFiles.Select(seekedFile => $"-ss {seekedFile.StartTime} -i \"{seekedFile.FilePath}\"")); } } \ No newline at end of file diff --git a/FFMpegCore/FFMpeg/FFMpeg.cs b/FFMpegCore/FFMpeg/FFMpeg.cs index 9d95ce2..6e70354 100644 --- a/FFMpegCore/FFMpeg/FFMpeg.cs +++ b/FFMpegCore/FFMpeg/FFMpeg.cs @@ -30,7 +30,7 @@ public static bool Snapshot(MediaAnalysis source, string output, Size? size = nu size = PrepareSnapshotSize(source, size); return FFMpegArguments - .FromSeekedFile(source.Path, captureTime ?? TimeSpan.Zero) + .FromSeekedFiles((source.Path, captureTime ?? TimeSpan.Zero)) .WithVideoCodec(VideoCodec.Png) .WithFrameOutputCount(1) .Resize(size) diff --git a/FFMpegCore/FFMpeg/FFMpegArguments.cs b/FFMpegCore/FFMpeg/FFMpegArguments.cs index 9118458..b3285f6 100644 --- a/FFMpegCore/FFMpeg/FFMpegArguments.cs +++ b/FFMpegCore/FFMpeg/FFMpegArguments.cs @@ -25,7 +25,7 @@ private FFMpegArguments(IInputArgument inputArgument) public string Text => string.Join(" ", _arguments.Select(arg => arg.Text)); - public static FFMpegArguments FromSeekedFile(string file, TimeSpan startTime) => new FFMpegArguments(new SeekedFileInputArgument(file, startTime)); + public static FFMpegArguments FromSeekedFiles(params (string file, TimeSpan startTime)[] seekedFiles) => new FFMpegArguments(new SeekedFileInputArgument(seekedFiles)); public static FFMpegArguments FromInputFiles(params string[] files) => new FFMpegArguments(new InputArgument(true, files)); public static FFMpegArguments FromInputFiles(bool verifyExists, params string[] files) => new FFMpegArguments(new InputArgument(verifyExists, files)); public static FFMpegArguments FromInputFiles(params Uri[] uris) => new FFMpegArguments(new InputArgument(false, uris));