Partial revert

Former-commit-id: 8e2b146f95
This commit is contained in:
Malte Rosenbjerg 2020-12-07 01:11:09 +01:00
parent c691dba8e8
commit 105a9fd1f6
4 changed files with 12 additions and 11 deletions

View file

@ -17,7 +17,7 @@ public InputPipeArgument(IPipeSource writer) : base(PipeDirection.Out)
Writer = writer;
}
public override string Text => $"{(!string.IsNullOrEmpty(Writer.Format) ? $"-f {Writer.Format} " : string.Empty)}-i \"{PipePath}\"";
public override string Text => $"-y {Writer.GetStreamArguments()} -i \"{PipePath}\"";
protected override async Task ProcessDataAsync(CancellationToken token)
{

View file

@ -8,7 +8,7 @@ namespace FFMpegCore.Pipes
/// </summary>
public interface IPipeSource
{
string Format { get; }
string GetStreamArguments();
Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken);
}
}

View file

@ -11,10 +11,9 @@ namespace FFMpegCore.Pipes
/// </summary>
public class RawVideoPipeSource : IPipeSource
{
public string StreamFormat { get; private set; } = null!;
public int Width { get; private set; }
public int Height { get; private set; }
public string Format { get; private set; }
public int FrameRate { get; set; } = 25;
private bool _formatInitialized;
private readonly IEnumerator<IVideoFrame> _framesEnumerator;
@ -26,7 +25,7 @@ public RawVideoPipeSource(IEnumerator<IVideoFrame> framesEnumerator)
public RawVideoPipeSource(IEnumerable<IVideoFrame> framesEnumerator) : this(framesEnumerator.GetEnumerator()) { }
public string GetFormat()
public string GetStreamArguments()
{
if (!_formatInitialized)
{
@ -36,14 +35,14 @@ public string GetFormat()
if (!_framesEnumerator.MoveNext())
throw new InvalidOperationException("Enumerator is empty, unable to get frame");
}
Format = _framesEnumerator.Current!.Format;
StreamFormat = _framesEnumerator.Current!.Format;
Width = _framesEnumerator.Current!.Width;
Height = _framesEnumerator.Current!.Height;
_formatInitialized = true;
}
return $"-f rawvideo -r {FrameRate} -pix_fmt {Format} -s {Width}x{Height}";
return $"-f rawvideo -r {FrameRate} -pix_fmt {StreamFormat} -s {Width}x{Height}";
}
public async Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken)
@ -63,10 +62,10 @@ public async Task WriteAsync(System.IO.Stream outputStream, CancellationToken ca
private void CheckFrameAndThrow(IVideoFrame frame)
{
if (frame.Width != Width || frame.Height != Height || frame.Format != Format)
if (frame.Width != Width || frame.Height != Height || frame.Format != StreamFormat)
throw new FFMpegException(FFMpegExceptionType.Operation, "Video frame is not the same format as created raw video stream\r\n" +
$"Frame format: {frame.Width}x{frame.Height} pix_fmt: {frame.Format}\r\n" +
$"Stream format: {Width}x{Height} pix_fmt: {Format}");
$"Stream format: {Width}x{Height} pix_fmt: {StreamFormat}");
}
}
}

View file

@ -10,13 +10,15 @@ public class StreamPipeSource : IPipeSource
{
public System.IO.Stream Source { get; }
public int BlockSize { get; } = 4096;
public string Format { get; }
public string StreamFormat { get; } = string.Empty;
public StreamPipeSource(System.IO.Stream source)
{
Source = source;
}
public string GetStreamArguments() => StreamFormat;
public Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) => Source.CopyToAsync(outputStream, BlockSize, cancellationToken);
}
}