mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Merge branch 'dev/fixes' into refactor-tests
Former-commit-id: 6c51f634c2
This commit is contained in:
commit
2fc64f3ac7
4 changed files with 12 additions and 11 deletions
|
@ -17,7 +17,7 @@ public InputPipeArgument(IPipeSource writer) : base(PipeDirection.Out)
|
||||||
Writer = writer;
|
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)
|
protected override async Task ProcessDataAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace FFMpegCore.Pipes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IPipeSource
|
public interface IPipeSource
|
||||||
{
|
{
|
||||||
string Format { get; }
|
string GetStreamArguments();
|
||||||
Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken);
|
Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,9 @@ namespace FFMpegCore.Pipes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RawVideoPipeSource : IPipeSource
|
public class RawVideoPipeSource : IPipeSource
|
||||||
{
|
{
|
||||||
|
public string StreamFormat { get; private set; } = null!;
|
||||||
public int Width { get; private set; }
|
public int Width { get; private set; }
|
||||||
public int Height { get; private set; }
|
public int Height { get; private set; }
|
||||||
|
|
||||||
public string Format { get; private set; }
|
|
||||||
public int FrameRate { get; set; } = 25;
|
public int FrameRate { get; set; } = 25;
|
||||||
private bool _formatInitialized;
|
private bool _formatInitialized;
|
||||||
private readonly IEnumerator<IVideoFrame> _framesEnumerator;
|
private readonly IEnumerator<IVideoFrame> _framesEnumerator;
|
||||||
|
@ -26,7 +25,7 @@ public RawVideoPipeSource(IEnumerator<IVideoFrame> framesEnumerator)
|
||||||
|
|
||||||
public RawVideoPipeSource(IEnumerable<IVideoFrame> framesEnumerator) : this(framesEnumerator.GetEnumerator()) { }
|
public RawVideoPipeSource(IEnumerable<IVideoFrame> framesEnumerator) : this(framesEnumerator.GetEnumerator()) { }
|
||||||
|
|
||||||
public string GetFormat()
|
public string GetStreamArguments()
|
||||||
{
|
{
|
||||||
if (!_formatInitialized)
|
if (!_formatInitialized)
|
||||||
{
|
{
|
||||||
|
@ -36,14 +35,14 @@ public string GetFormat()
|
||||||
if (!_framesEnumerator.MoveNext())
|
if (!_framesEnumerator.MoveNext())
|
||||||
throw new InvalidOperationException("Enumerator is empty, unable to get frame");
|
throw new InvalidOperationException("Enumerator is empty, unable to get frame");
|
||||||
}
|
}
|
||||||
Format = _framesEnumerator.Current!.Format;
|
StreamFormat = _framesEnumerator.Current!.Format;
|
||||||
Width = _framesEnumerator.Current!.Width;
|
Width = _framesEnumerator.Current!.Width;
|
||||||
Height = _framesEnumerator.Current!.Height;
|
Height = _framesEnumerator.Current!.Height;
|
||||||
|
|
||||||
_formatInitialized = true;
|
_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)
|
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)
|
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" +
|
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" +
|
$"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}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,15 @@ public class StreamPipeSource : IPipeSource
|
||||||
{
|
{
|
||||||
public System.IO.Stream Source { get; }
|
public System.IO.Stream Source { get; }
|
||||||
public int BlockSize { get; } = 4096;
|
public int BlockSize { get; } = 4096;
|
||||||
|
public string StreamFormat { get; } = string.Empty;
|
||||||
public string Format { get; }
|
|
||||||
|
|
||||||
public StreamPipeSource(System.IO.Stream source)
|
public StreamPipeSource(System.IO.Stream source)
|
||||||
{
|
{
|
||||||
Source = source;
|
Source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetStreamArguments() => StreamFormat;
|
||||||
|
|
||||||
public Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) => Source.CopyToAsync(outputStream, BlockSize, cancellationToken);
|
public Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) => Source.CopyToAsync(outputStream, BlockSize, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue