From 717d61dd0771789d4060fec1513ddb5bb54202b3 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 25 Nov 2020 16:15:16 +0100 Subject: [PATCH] Update dependencies and add StreamPipeSink constructor Former-commit-id: 5ba2ed97cf1401fc539ec82e70c7c6db6e1023bf --- FFMpegCore.Test/FFMpegCore.Test.csproj | 4 ++-- .../FFMpeg/Arguments/InputPipeArgument.cs | 2 +- .../FFMpeg/Arguments/OutputPipeArgument.cs | 2 +- FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs | 2 +- FFMpegCore/FFMpeg/FFMpegOptions.cs | 2 +- FFMpegCore/FFMpeg/Pipes/IPipeSink.cs | 2 +- FFMpegCore/FFMpeg/Pipes/IPipeSource.cs | 2 +- FFMpegCore/FFMpeg/Pipes/RawVideoPipeSource.cs | 2 +- FFMpegCore/FFMpeg/Pipes/StreamPipeSink.cs | 18 ++++++++++++------ FFMpegCore/FFMpeg/Pipes/StreamPipeSource.cs | 2 +- FFMpegCore/FFMpegCore.csproj | 10 +++++----- FFMpegCore/FFProbe/FFProbe.cs | 2 +- 12 files changed, 28 insertions(+), 22 deletions(-) diff --git a/FFMpegCore.Test/FFMpegCore.Test.csproj b/FFMpegCore.Test/FFMpegCore.Test.csproj index 971b098..59f2645 100644 --- a/FFMpegCore.Test/FFMpegCore.Test.csproj +++ b/FFMpegCore.Test/FFMpegCore.Test.csproj @@ -36,8 +36,8 @@ - - + + diff --git a/FFMpegCore/FFMpeg/Arguments/InputPipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/InputPipeArgument.cs index 17d0372..adc25fb 100644 --- a/FFMpegCore/FFMpeg/Arguments/InputPipeArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/InputPipeArgument.cs @@ -24,7 +24,7 @@ protected override async Task ProcessDataAsync(CancellationToken token) await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); if (!Pipe.IsConnected) throw new TaskCanceledException(); - await Writer.CopyAsync(Pipe, token).ConfigureAwait(false); + await Writer.WriteAsync(Pipe, token).ConfigureAwait(false); } } } diff --git a/FFMpegCore/FFMpeg/Arguments/OutputPipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/OutputPipeArgument.cs index ebf1e7f..f089a1e 100644 --- a/FFMpegCore/FFMpeg/Arguments/OutputPipeArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/OutputPipeArgument.cs @@ -21,7 +21,7 @@ protected override async Task ProcessDataAsync(CancellationToken token) await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); if (!Pipe.IsConnected) throw new TaskCanceledException(); - await Reader.CopyAsync(Pipe, token).ConfigureAwait(false); + await Reader.ReadAsync(Pipe, token).ConfigureAwait(false); } } } diff --git a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs index 92fa6fe..8a30dfc 100644 --- a/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs +++ b/FFMpegCore/FFMpeg/FFMpegArgumentProcessor.cs @@ -98,7 +98,7 @@ public async Task ProcessAsynchronously(bool throwOnError = true) void OnCancelEvent(object sender, EventArgs args) { - instance?.SendInput("q"); + instance.SendInput("q"); cancellationTokenSource.Cancel(); instance.Started = false; } diff --git a/FFMpegCore/FFMpeg/FFMpegOptions.cs b/FFMpegCore/FFMpeg/FFMpegOptions.cs index 8a98a0a..947f942 100644 --- a/FFMpegCore/FFMpeg/FFMpegOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegOptions.cs @@ -32,7 +32,7 @@ static FFMpegOptions() { if (File.Exists(ConfigFile)) { - Options = JsonSerializer.Deserialize(File.ReadAllText(ConfigFile)); + Options = JsonSerializer.Deserialize(File.ReadAllText(ConfigFile))!; foreach (var pair in DefaultExtensionsOverrides) if (!Options.ExtensionOverrides.ContainsKey(pair.Key)) Options.ExtensionOverrides.Add(pair.Key, pair.Value); } diff --git a/FFMpegCore/FFMpeg/Pipes/IPipeSink.cs b/FFMpegCore/FFMpeg/Pipes/IPipeSink.cs index 8010d87..875407e 100644 --- a/FFMpegCore/FFMpeg/Pipes/IPipeSink.cs +++ b/FFMpegCore/FFMpeg/Pipes/IPipeSink.cs @@ -5,7 +5,7 @@ namespace FFMpegCore.Pipes { public interface IPipeSink { - Task CopyAsync(System.IO.Stream inputStream, CancellationToken cancellationToken); + Task ReadAsync(System.IO.Stream inputStream, CancellationToken cancellationToken); string GetFormat(); } } diff --git a/FFMpegCore/FFMpeg/Pipes/IPipeSource.cs b/FFMpegCore/FFMpeg/Pipes/IPipeSource.cs index 35766d0..55fdcc3 100644 --- a/FFMpegCore/FFMpeg/Pipes/IPipeSource.cs +++ b/FFMpegCore/FFMpeg/Pipes/IPipeSource.cs @@ -9,6 +9,6 @@ namespace FFMpegCore.Pipes public interface IPipeSource { string GetFormat(); - Task CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken); + Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken); } } diff --git a/FFMpegCore/FFMpeg/Pipes/RawVideoPipeSource.cs b/FFMpegCore/FFMpeg/Pipes/RawVideoPipeSource.cs index 8739a40..eef4343 100644 --- a/FFMpegCore/FFMpeg/Pipes/RawVideoPipeSource.cs +++ b/FFMpegCore/FFMpeg/Pipes/RawVideoPipeSource.cs @@ -45,7 +45,7 @@ public string GetFormat() return $"-f rawvideo -r {FrameRate} -pix_fmt {StreamFormat} -s {Width}x{Height}"; } - public async Task CopyAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) + public async Task WriteAsync(System.IO.Stream outputStream, CancellationToken cancellationToken) { if (_framesEnumerator.Current != null) { diff --git a/FFMpegCore/FFMpeg/Pipes/StreamPipeSink.cs b/FFMpegCore/FFMpeg/Pipes/StreamPipeSink.cs index ca2246f..cd13f40 100644 --- a/FFMpegCore/FFMpeg/Pipes/StreamPipeSink.cs +++ b/FFMpegCore/FFMpeg/Pipes/StreamPipeSink.cs @@ -1,21 +1,27 @@ -using System.Threading; +using System; +using System.IO; +using System.Threading; using System.Threading.Tasks; namespace FFMpegCore.Pipes { public class StreamPipeSink : IPipeSink { - public System.IO.Stream Destination { get; } + public Func Writer { get; } public int BlockSize { get; set; } = 4096; public string Format { get; set; } = string.Empty; - public StreamPipeSink(System.IO.Stream destination) + public StreamPipeSink(Func writer) { - Destination = destination; + Writer = writer; + } + public StreamPipeSink(Stream destination) + { + Writer = (inputStream, cancellationToken) => inputStream.CopyToAsync(destination, BlockSize, cancellationToken); } - public Task CopyAsync(System.IO.Stream inputStream, CancellationToken cancellationToken) => - inputStream.CopyToAsync(Destination, BlockSize, cancellationToken); + public Task ReadAsync(System.IO.Stream inputStream, CancellationToken cancellationToken) + => Writer(inputStream, cancellationToken); public string GetFormat() => Format; } diff --git a/FFMpegCore/FFMpeg/Pipes/StreamPipeSource.cs b/FFMpegCore/FFMpeg/Pipes/StreamPipeSource.cs index db41eb7..b364037 100644 --- a/FFMpegCore/FFMpeg/Pipes/StreamPipeSource.cs +++ b/FFMpegCore/FFMpeg/Pipes/StreamPipeSource.cs @@ -17,7 +17,7 @@ public StreamPipeSource(System.IO.Stream source) Source = source; } - public Task CopyAsync(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); public string GetFormat() => StreamFormat; } diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index 057f605..27a80ff 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -9,10 +9,10 @@ 3.0.0.0 3.0.0.0 3.0.0.0 - - Fix hanging pipes on unix sockets -- Internal API cleanup + - Updated dependencies +- Additional StreamPipeSink constructor 8 - 3.1.0 + 3.2.0 Malte Rosenbjerg, Vlad Jerca ffmpeg ffprobe convert video audio mediafile resize analyze muxing GitHub @@ -29,8 +29,8 @@ - - + + diff --git a/FFMpegCore/FFProbe/FFProbe.cs b/FFMpegCore/FFProbe/FFProbe.cs index f650371..5b7a1e4 100644 --- a/FFMpegCore/FFProbe/FFProbe.cs +++ b/FFMpegCore/FFProbe/FFProbe.cs @@ -98,7 +98,7 @@ private static IMediaAnalysis ParseOutput(string filePath, Instance instance) var ffprobeAnalysis = JsonSerializer.Deserialize(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true - }); + })!; return new MediaAnalysis(filePath, ffprobeAnalysis); }