From 8a764eccc7e0ca37d9df2e0da8694a8dbdb2bdcc Mon Sep 17 00:00:00 2001 From: AddyMills <74471839+AddyMills@users.noreply.github.com> Date: Fri, 1 Mar 2024 07:08:16 -0600 Subject: [PATCH] Add MultiInputArgument --- .../FFMpeg/Arguments/MultiInputArgument.cs | 47 +++++++++++++++++++ FFMpegCore/FFMpeg/FFMpegArguments.cs | 2 + FFMpegCore/FFMpegCore.csproj | 4 +- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 FFMpegCore/FFMpeg/Arguments/MultiInputArgument.cs diff --git a/FFMpegCore/FFMpeg/Arguments/MultiInputArgument.cs b/FFMpegCore/FFMpeg/Arguments/MultiInputArgument.cs new file mode 100644 index 0000000..e64d96a --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/MultiInputArgument.cs @@ -0,0 +1,47 @@ +namespace FFMpegCore.Arguments +{ + /// + /// Represents input parameters for multiple files + /// + public class MultiInputArgument : IInputArgument + { + public readonly bool VerifyExists; + public readonly string[] FilePaths; + + public MultiInputArgument(bool verifyExists, params string[] filePaths) + { + VerifyExists = verifyExists; + FilePaths = filePaths; + } + + public MultiInputArgument(string[] filePaths, bool verifyExists) : this(verifyExists, filePaths) { } + + public void Pre() + { + if (VerifyExists) + { + var missingFiles = new List(); + foreach (var filePath in FilePaths) + { + if (!File.Exists(filePath)) + { + missingFiles.Add(filePath); + } + } + + if (missingFiles.Any()) + { + throw new FileNotFoundException($"The following input files were not found: {string.Join(", ", missingFiles)}"); + } + } + } + + public Task During(CancellationToken cancellationToken = default) => Task.CompletedTask; + public void Post() { } + + /// + /// Generates a combined input argument text for all file paths + /// + public string Text => string.Join(" ", FilePaths.Select(filePath => $"-i \"{filePath}\"")); + } +} diff --git a/FFMpegCore/FFMpeg/FFMpegArguments.cs b/FFMpegCore/FFMpeg/FFMpegArguments.cs index cfc6d9d..cf57b84 100644 --- a/FFMpegCore/FFMpeg/FFMpegArguments.cs +++ b/FFMpegCore/FFMpeg/FFMpegArguments.cs @@ -21,6 +21,7 @@ private string GetText() public static FFMpegArguments FromConcatInput(IEnumerable filePaths, Action? addArguments = null) => new FFMpegArguments().WithInput(new ConcatArgument(filePaths), addArguments); public static FFMpegArguments FromDemuxConcatInput(IEnumerable filePaths, Action? addArguments = null) => new FFMpegArguments().WithInput(new DemuxConcatArgument(filePaths), addArguments); public static FFMpegArguments FromFileInput(string filePath, bool verifyExists = true, Action? addArguments = null) => new FFMpegArguments().WithInput(new InputArgument(verifyExists, filePath), addArguments); + public static FFMpegArguments FromFileInput(string[] filePath, bool verifyExists = true, Action? addArguments = null) => new FFMpegArguments().WithInput(new MultiInputArgument(verifyExists, filePath), addArguments); public static FFMpegArguments FromFileInput(FileInfo fileInfo, Action? addArguments = null) => new FFMpegArguments().WithInput(new InputArgument(fileInfo.FullName, false), addArguments); public static FFMpegArguments FromUrlInput(Uri uri, Action? addArguments = null) => new FFMpegArguments().WithInput(new InputArgument(uri.AbsoluteUri, false), addArguments); public static FFMpegArguments FromDeviceInput(string device, Action? addArguments = null) => new FFMpegArguments().WithInput(new InputDeviceArgument(device), addArguments); @@ -35,6 +36,7 @@ public FFMpegArguments WithGlobalOptions(Action configure public FFMpegArguments AddConcatInput(IEnumerable filePaths, Action? addArguments = null) => WithInput(new ConcatArgument(filePaths), addArguments); public FFMpegArguments AddDemuxConcatInput(IEnumerable filePaths, Action? addArguments = null) => WithInput(new DemuxConcatArgument(filePaths), addArguments); public FFMpegArguments AddFileInput(string filePath, bool verifyExists = true, Action? addArguments = null) => WithInput(new InputArgument(verifyExists, filePath), addArguments); + public FFMpegArguments AddFileInput(string[] filePath, bool verifyExists = true, Action? addArguments = null) => WithInput(new MultiInputArgument(verifyExists, filePath), addArguments); public FFMpegArguments AddFileInput(FileInfo fileInfo, Action? addArguments = null) => WithInput(new InputArgument(fileInfo.FullName, false), addArguments); public FFMpegArguments AddUrlInput(Uri uri, Action? addArguments = null) => WithInput(new InputArgument(uri.AbsoluteUri, false), addArguments); public FFMpegArguments AddDeviceInput(string device, Action? addArguments = null) => WithInput(new InputDeviceArgument(device), addArguments); diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index ed3b71c..e6a45e9 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -3,7 +3,7 @@ true A .NET Standard FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your .NET applications - 5.1.0 + 5.1.1 ../nupkg @@ -20,5 +20,7 @@ + +