Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a support for pre-exsiting pipe #494

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions FFMpegCore/FFMpeg/Arguments/InputExistingPipeArgument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Diagnostics;
using FFMpegCore.Pipes;

namespace FFMpegCore.Arguments
{
/// <summary>
/// Represents input parameter for a specific name pipe
/// </summary>
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<bool>();
cancellationToken.Register(() => tcs.TrySetCanceled());
await tcs.Task;
}
catch(OperationCanceledException)
{
Debug.WriteLine($"{GetType().Name} cancelled");
}
}

public void Post()
{
}
}
}
2 changes: 2 additions & 0 deletions FFMpegCore/FFMpeg/FFMpegArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private string GetText()
public static FFMpegArguments FromUrlInput(Uri uri, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new InputArgument(uri.AbsoluteUri, false), addArguments);
public static FFMpegArguments FromDeviceInput(string device, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new InputDeviceArgument(device), addArguments);
public static FFMpegArguments FromPipeInput(IPipeSource sourcePipe, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new InputPipeArgument(sourcePipe), addArguments);
public static FFMpegArguments FromPipeInput(string pipeName, Action<FFMpegArgumentOptions>? addArguments = null) => new FFMpegArguments().WithInput(new InputExistingPipeArgument(pipeName), addArguments);

public FFMpegArguments WithGlobalOptions(Action<FFMpegGlobalArguments> configureOptions)
{
Expand All @@ -39,6 +40,7 @@ public FFMpegArguments WithGlobalOptions(Action<FFMpegGlobalArguments> configure
public FFMpegArguments AddUrlInput(Uri uri, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new InputArgument(uri.AbsoluteUri, false), addArguments);
public FFMpegArguments AddDeviceInput(string device, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new InputDeviceArgument(device), addArguments);
public FFMpegArguments AddPipeInput(IPipeSource sourcePipe, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new InputPipeArgument(sourcePipe), addArguments);
public FFMpegArguments AddPipeInput(string pipeName, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new InputExistingPipeArgument(pipeName), addArguments);
public FFMpegArguments AddMetaData(string content, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new MetaDataArgument(content), addArguments);
public FFMpegArguments AddMetaData(IReadOnlyMetaData metaData, Action<FFMpegArgumentOptions>? addArguments = null) => WithInput(new MetaDataArgument(MetaDataSerializer.Instance.Serialize(metaData)), addArguments);

Expand Down
2 changes: 1 addition & 1 deletion FFMpegCore/FFMpegCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<Description>A .NET Standard FFMpeg/FFProbe wrapper for easily integrating media analysis and conversion into your .NET applications</Description>
<PackageVersion>5.1.0</PackageVersion>
<PackageVersion>5.1.1</PackageVersion>
<PackageOutputPath>../nupkg</PackageOutputPath>
<PackageReleaseNotes>
</PackageReleaseNotes>
Expand Down
Loading