diff --git a/FFMpegCore/FFMpeg/Arguments/InputExistingPipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/InputExistingPipeArgument.cs new file mode 100644 index 0000000..196c66c --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/InputExistingPipeArgument.cs @@ -0,0 +1,46 @@ +using System.Diagnostics; +using FFMpegCore.Pipes; + +namespace FFMpegCore.Arguments +{ + /// + /// Represents input parameter for a specific name pipe + /// + public class InputExistingPipeArgument : IInputArgument + { + public string PipeName { get; } + public string PipePath => PipeHelpers.GetPipePath(PipeName); + public string Text => $"-i \"{PipePath}\""; + + public InputExistingPipeArgument(string pipeName) + { + PipeName = pipeName; + } + + public void Pre() + { + if (string.IsNullOrEmpty(PipeName)) + { + throw new InvalidOperationException("Pipe name cannot be null or empty"); + } + } + + public async Task During(CancellationToken cancellationToken = default) + { + try + { + var tcs = new TaskCompletionSource(); + cancellationToken.Register(() => tcs.TrySetCanceled()); + await tcs.Task; + } + catch(OperationCanceledException) + { + Debug.WriteLine($"{GetType().Name} cancelled"); + } + } + + public void Post() + { + } + } +} diff --git a/FFMpegCore/FFMpeg/FFMpegArguments.cs b/FFMpegCore/FFMpeg/FFMpegArguments.cs index cfc6d9d..327c4f6 100644 --- a/FFMpegCore/FFMpeg/FFMpegArguments.cs +++ b/FFMpegCore/FFMpeg/FFMpegArguments.cs @@ -25,6 +25,7 @@ private string GetText() 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); public static FFMpegArguments FromPipeInput(IPipeSource sourcePipe, Action? addArguments = null) => new FFMpegArguments().WithInput(new InputPipeArgument(sourcePipe), addArguments); + public static FFMpegArguments FromPipeInput(string pipeName, Action? addArguments = null) => new FFMpegArguments().WithInput(new InputExistingPipeArgument(pipeName), addArguments); public FFMpegArguments WithGlobalOptions(Action configureOptions) { @@ -39,6 +40,7 @@ public FFMpegArguments WithGlobalOptions(Action configure 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); public FFMpegArguments AddPipeInput(IPipeSource sourcePipe, Action? addArguments = null) => WithInput(new InputPipeArgument(sourcePipe), addArguments); + public FFMpegArguments AddPipeInput(string pipeName, Action? addArguments = null) => WithInput(new InputExistingPipeArgument(pipeName), addArguments); public FFMpegArguments AddMetaData(string content, Action? addArguments = null) => WithInput(new MetaDataArgument(content), addArguments); public FFMpegArguments AddMetaData(IReadOnlyMetaData metaData, Action? addArguments = null) => WithInput(new MetaDataArgument(MetaDataSerializer.Instance.Serialize(metaData)), addArguments); diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index ed3b71c..827f33d 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