mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
9642e4473b
commit
6bb03f6e14
5 changed files with 20 additions and 20 deletions
|
@ -17,11 +17,11 @@ public class InputPipeArgument : Argument
|
||||||
{
|
{
|
||||||
public string PipeName { get; private set; }
|
public string PipeName { get; private set; }
|
||||||
public string PipePath => PipeHelpers.GetPipePath(PipeName);
|
public string PipePath => PipeHelpers.GetPipePath(PipeName);
|
||||||
public IPipeSource Source { get; private set; }
|
public IPipeDataWriter Source { get; private set; }
|
||||||
|
|
||||||
private NamedPipeServerStream pipe;
|
private NamedPipeServerStream pipe;
|
||||||
|
|
||||||
public InputPipeArgument(IPipeSource source)
|
public InputPipeArgument(IPipeDataWriter source)
|
||||||
{
|
{
|
||||||
Source = source;
|
Source = source;
|
||||||
PipeName = PipeHelpers.GetUnqiuePipeName();
|
PipeName = PipeHelpers.GetUnqiuePipeName();
|
||||||
|
@ -49,14 +49,14 @@ public override string GetStringValue()
|
||||||
public void FlushPipe()
|
public void FlushPipe()
|
||||||
{
|
{
|
||||||
pipe.WaitForConnection();
|
pipe.WaitForConnection();
|
||||||
Source.FlushData(pipe);
|
Source.WriteData(pipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task FlushPipeAsync()
|
public async Task FlushPipeAsync()
|
||||||
{
|
{
|
||||||
await pipe.WaitForConnectionAsync();
|
await pipe.WaitForConnectionAsync();
|
||||||
await Source.FlushDataAsync(pipe);
|
await Source.WriteDataAsync(pipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ namespace FFMpegCore.FFMPEG.Pipes
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for ffmpeg pipe source data IO
|
/// Interface for ffmpeg pipe source data IO
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IPipeSource
|
public interface IPipeDataWriter
|
||||||
{
|
{
|
||||||
string GetFormat();
|
string GetFormat();
|
||||||
void FlushData(System.IO.Stream pipe);
|
void WriteData(System.IO.Stream pipe);
|
||||||
Task FlushDataAsync(System.IO.Stream pipe);
|
Task WriteDataAsync(System.IO.Stream pipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,9 +7,9 @@
|
||||||
namespace FFMpegCore.FFMPEG.Pipes
|
namespace FFMpegCore.FFMPEG.Pipes
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation of <see cref="IPipeSource"/> for a raw video stream that is gathered from <see cref="IEnumerator{IVideoFrame}"/>
|
/// Implementation of <see cref="IPipeDataWriter"/> for a raw video stream that is gathered from <see cref="IEnumerator{IVideoFrame}"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RawVideoPipeSource : IPipeSource
|
public class RawVideoPipeDataWriter : IPipeDataWriter
|
||||||
{
|
{
|
||||||
public string StreamFormat { get; set; }
|
public string StreamFormat { get; set; }
|
||||||
public int Width { get; set; }
|
public int Width { get; set; }
|
||||||
|
@ -17,12 +17,12 @@ public class RawVideoPipeSource : IPipeSource
|
||||||
public int FrameRate { get; set; } = 25;
|
public int FrameRate { get; set; } = 25;
|
||||||
private IEnumerator<IVideoFrame> framesEnumerator;
|
private IEnumerator<IVideoFrame> framesEnumerator;
|
||||||
|
|
||||||
public RawVideoPipeSource(IEnumerator<IVideoFrame> framesEnumerator)
|
public RawVideoPipeDataWriter(IEnumerator<IVideoFrame> framesEnumerator)
|
||||||
{
|
{
|
||||||
this.framesEnumerator = framesEnumerator;
|
this.framesEnumerator = framesEnumerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RawVideoPipeSource(IEnumerable<IVideoFrame> framesEnumerator) : this(framesEnumerator.GetEnumerator()) { }
|
public RawVideoPipeDataWriter(IEnumerable<IVideoFrame> framesEnumerator) : this(framesEnumerator.GetEnumerator()) { }
|
||||||
|
|
||||||
public string GetFormat()
|
public string GetFormat()
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,7 @@ public string GetFormat()
|
||||||
return $"-f rawvideo -r {FrameRate} -pix_fmt {StreamFormat} -s {Width}x{Height}";
|
return $"-f rawvideo -r {FrameRate} -pix_fmt {StreamFormat} -s {Width}x{Height}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FlushData(System.IO.Stream stream)
|
public void WriteData(System.IO.Stream stream)
|
||||||
{
|
{
|
||||||
if (framesEnumerator.Current != null)
|
if (framesEnumerator.Current != null)
|
||||||
{
|
{
|
||||||
|
@ -53,7 +53,7 @@ public void FlushData(System.IO.Stream stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task FlushDataAsync(System.IO.Stream stream)
|
public async Task WriteDataAsync(System.IO.Stream stream)
|
||||||
{
|
{
|
||||||
if (framesEnumerator.Current != null)
|
if (framesEnumerator.Current != null)
|
||||||
{
|
{
|
|
@ -5,12 +5,12 @@
|
||||||
|
|
||||||
namespace FFMpegCore.FFMPEG.Pipes
|
namespace FFMpegCore.FFMPEG.Pipes
|
||||||
{
|
{
|
||||||
public class StreamPipedataReader : IPipeDataReader
|
public class StreamPipeDataReader : IPipeDataReader
|
||||||
{
|
{
|
||||||
public System.IO.Stream DestanationStream { get; private set; }
|
public System.IO.Stream DestanationStream { get; private set; }
|
||||||
public int BlockSize { get; set; } = 4096;
|
public int BlockSize { get; set; } = 4096;
|
||||||
|
|
||||||
public StreamPipedataReader(System.IO. Stream destanationStream)
|
public StreamPipeDataReader(System.IO. Stream destanationStream)
|
||||||
{
|
{
|
||||||
DestanationStream = destanationStream;
|
DestanationStream = destanationStream;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,19 +6,19 @@
|
||||||
namespace FFMpegCore.FFMPEG.Pipes
|
namespace FFMpegCore.FFMPEG.Pipes
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation of <see cref="IPipeSource"/> used for stream redirection
|
/// Implementation of <see cref="IPipeDataWriter"/> used for stream redirection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class StreamPipeSource : IPipeSource
|
public class StreamPipeDataWriter : IPipeDataWriter
|
||||||
{
|
{
|
||||||
public System.IO.Stream Source { get; private set; }
|
public System.IO.Stream Source { get; private set; }
|
||||||
public int BlockSize { get; set; } = 4096;
|
public int BlockSize { get; set; } = 4096;
|
||||||
|
|
||||||
public StreamPipeSource(System.IO.Stream stream)
|
public StreamPipeDataWriter(System.IO.Stream stream)
|
||||||
{
|
{
|
||||||
Source = stream;
|
Source = stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FlushData(System.IO.Stream pipe)
|
public void WriteData(System.IO.Stream pipe)
|
||||||
{
|
{
|
||||||
var buffer = new byte[BlockSize];
|
var buffer = new byte[BlockSize];
|
||||||
int read;
|
int read;
|
||||||
|
@ -28,7 +28,7 @@ public void FlushData(System.IO.Stream pipe)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task FlushDataAsync(System.IO.Stream pipe)
|
public async Task WriteDataAsync(System.IO.Stream pipe)
|
||||||
{
|
{
|
||||||
var buffer = new byte[BlockSize];
|
var buffer = new byte[BlockSize];
|
||||||
int read;
|
int read;
|
Loading…
Reference in a new issue