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..54afd94 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -9,10 +9,11 @@ 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 + MIT Malte Rosenbjerg, Vlad Jerca ffmpeg ffprobe convert video audio mediafile resize analyze muxing GitHub @@ -29,8 +30,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); } diff --git a/README.md b/README.md index 6fb7abe..0012def 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # FFMpegCore -[![NuGet Badge](https://buildstats.info/nuget/FFMpegCore)](https://www.nuget.org/packages/FFMpegCore/) [![CI](https://github.com/rosenbjerg/FFMpegCore/workflows/CI/badge.svg)](https://github.com/rosenbjerg/FFMpegCore/actions?query=workflow%3ACI) +[![NuGet Badge](https://buildstats.info/nuget/FFMpegCore)](https://www.nuget.org/packages/FFMpegCore/) +[![GitHub issues](https://img.shields.io/github/issues/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/issues) +[![GitHub stars](https://img.shields.io/github/stars/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/stargazers) +[![GitHub](https://img.shields.io/github/license/rosenbjerg/FFMpegCore)](https://github.com/rosenbjerg/FFMpegCore/blob/master/LICENSE) # Setup @@ -209,6 +212,7 @@ The root and temp directory for the ffmpeg binaries can be configured via the `f + ### License