From 77a6a9cd6cf11ff0d42d9e73bc22137bd922070a Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Wed, 6 May 2020 23:39:45 +0200 Subject: [PATCH 01/13] Make tests faster Former-commit-id: 560c9c8d9859afb2875c10d54c743a2da9d4c2f0 --- FFMpegCore.Test/VideoTest.cs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 0f4fc7f..e45d59c 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -219,13 +219,6 @@ public void Convert(VideoType type, ArgumentContainer container) } } - public void ConvertFromPipe(VideoType type, ArgumentContainer container) - { - ConvertFromPipe(type, container, PixelFormat.Format24bppRgb); - ConvertFromPipe(type, container, PixelFormat.Format32bppArgb); - ConvertFromPipe(type, container, PixelFormat.Format48bppRgb); - } - public void ConvertFromPipe(VideoType type, ArgumentContainer container, PixelFormat fmt) { var output = Input.OutputLocation(type); @@ -294,7 +287,7 @@ public void Video_ToMP4_Args() public void Video_ToMP4_Args_Pipe() { var container = new ArgumentContainer { new VideoCodecArgument(VideoCodec.LibX264) }; - ConvertFromPipe(VideoType.Mp4, container); + ConvertFromPipe(VideoType.Mp4, container, PixelFormat.Format24bppRgb); } [TestMethod] @@ -395,7 +388,7 @@ public void Video_ToTS_Args_Pipe() { new ForceFormatArgument(VideoCodec.MpegTs) }; - ConvertFromPipe(VideoType.Ts, container); + ConvertFromPipe(VideoType.Ts, container, PixelFormat.Format32bppArgb); } [TestMethod] @@ -423,7 +416,7 @@ public void Video_ToOGV_Resize_Args_Pipe() new ScaleArgument(VideoSize.Ed), new VideoCodecArgument(VideoCodec.LibTheora) }; - ConvertFromPipe(VideoType.Ogv, container); + ConvertFromPipe(VideoType.Ogv, container, PixelFormat.Format48bppRgb); } [TestMethod] @@ -448,10 +441,9 @@ public void Video_ToMP4_Resize_Args_Pipe() { var container = new ArgumentContainer { - new ScaleArgument(VideoSize.Ld), new VideoCodecArgument(VideoCodec.LibX264) }; - ConvertFromPipe(VideoType.Mp4, container); + ConvertFromPipe(VideoType.Mp4, container, PixelFormat.Format24bppRgb); } [TestMethod] From c6fbda042bc9a5795c070e951b6f38becc9a215f Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Thu, 7 May 2020 00:14:40 +0200 Subject: [PATCH 02/13] Add timeouts Former-commit-id: f791f6b059dcd370472113b14386ea3830ffea0d --- FFMpegCore.Test/VideoTest.cs | 58 ++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index e45d59c..5ff5da9 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -270,34 +270,34 @@ public void ConvertFromPipe(VideoType type, ArgumentContainer container, PixelFo } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4() { Convert(VideoType.Mp4); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Args() { var container = new ArgumentContainer { new VideoCodecArgument(VideoCodec.LibX264) }; Convert(VideoType.Mp4, container); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Args_Pipe() { var container = new ArgumentContainer { new VideoCodecArgument(VideoCodec.LibX264) }; ConvertFromPipe(VideoType.Mp4, container, PixelFormat.Format24bppRgb); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Args_StreamPipe() { var container = new ArgumentContainer { new VideoCodecArgument(VideoCodec.LibX264) }; ConvertFromStreamPipe(VideoType.Mp4, container); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() { Assert.ThrowsException(() => @@ -319,7 +319,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() }); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Args_StreamOutputPipe_Failure() { Assert.ThrowsException(() => @@ -333,7 +333,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Failure() } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Args_StreamOutputPipe_Async() { using (var ms = new MemoryStream()) @@ -352,7 +352,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async() } } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Args_StreamOutputPipe() { var container = new ArgumentContainer @@ -363,13 +363,13 @@ public void Video_ToMP4_Args_StreamOutputPipe() ConvertToStreamPipe(VideoType.Mp4, container); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToTS() { Convert(VideoType.Ts); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToTS_Args() { var container = new ArgumentContainer @@ -381,7 +381,7 @@ public void Video_ToTS_Args() Convert(VideoType.Ts, container); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToTS_Args_Pipe() { var container = new ArgumentContainer @@ -391,13 +391,13 @@ public void Video_ToTS_Args_Pipe() ConvertFromPipe(VideoType.Ts, container, PixelFormat.Format32bppArgb); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToOGV_Resize() { Convert(VideoType.Ogv, true, VideoSize.Ed); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToOGV_Resize_Args() { var container = new ArgumentContainer @@ -408,7 +408,7 @@ public void Video_ToOGV_Resize_Args() Convert(VideoType.Ogv, container); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToOGV_Resize_Args_Pipe() { var container = new ArgumentContainer @@ -419,13 +419,13 @@ public void Video_ToOGV_Resize_Args_Pipe() ConvertFromPipe(VideoType.Ogv, container, PixelFormat.Format48bppRgb); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Resize() { Convert(VideoType.Mp4, true, VideoSize.Ed); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Resize_Args() { var container = new ArgumentContainer @@ -436,7 +436,7 @@ public void Video_ToMP4_Resize_Args() Convert(VideoType.Mp4, container); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_Resize_Args_Pipe() { var container = new ArgumentContainer @@ -446,31 +446,31 @@ public void Video_ToMP4_Resize_Args_Pipe() ConvertFromPipe(VideoType.Mp4, container, PixelFormat.Format24bppRgb); } - [TestMethod] + [TestMethod, Timeout(30000)] public void Video_ToOGV() { Convert(VideoType.Ogv); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToMP4_MultiThread() { Convert(VideoType.Mp4, true); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToTS_MultiThread() { Convert(VideoType.Ts, true); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_ToOGV_MultiThread() { Convert(VideoType.Ogv, true); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_Snapshot() { var output = Input.OutputLocation(ImageType.Png); @@ -491,7 +491,7 @@ public void Video_Snapshot() } } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_Snapshot_PersistSnapshot() { var output = Input.OutputLocation(ImageType.Png); @@ -512,7 +512,7 @@ public void Video_Snapshot_PersistSnapshot() } } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_Join() { var output = Input.OutputLocation(VideoType.Mp4); @@ -544,7 +544,7 @@ public void Video_Join() } } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_Join_Image_Sequence() { try @@ -580,7 +580,7 @@ public void Video_Join_Image_Sequence() } } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_With_Only_Audio_Should_Extract_Metadata() { var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideoAudioOnly); @@ -590,7 +590,7 @@ public void Video_With_Only_Audio_Should_Extract_Metadata() Assert.AreEqual(1.25, video.Size); } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_Duration() { var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo); @@ -622,7 +622,7 @@ public void Video_Duration() } } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_UpdatesProgress() { var output = Input.OutputLocation(VideoType.Mp4); @@ -653,7 +653,7 @@ public void Video_UpdatesProgress() } } - [TestMethod] + [TestMethod, Timeout(15000)] public void Video_TranscodeInMemory() { using (var resStream = new MemoryStream()) From c4e067f5b534ad09e12a5aec77c222746405cc2a Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sat, 9 May 2020 17:53:49 +0200 Subject: [PATCH 03/13] Support piping on unix or at least trying Former-commit-id: eb9bc9807a2bd366dabfc71900bf7e5f70411da5 --- FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs index 6717dac..3cde7fa 100644 --- a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs +++ b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs @@ -10,7 +10,10 @@ static class PipeHelpers public static string GetPipePath(string pipeName) { - return $@"\\.\pipe\{pipeName}"; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + return $@"\\.\pipe\{pipeName}"; + else + return $"unix:/tmp/CoreFxPipe_{pipeName}"; // dotnet uses unix sockets on unix, for more see https://github.com/dotnet/runtime/issues/24390 } } } From ee15c20bc7191d64bd9d3475b1bd86f5960e2b7a Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sat, 9 May 2020 17:54:36 +0200 Subject: [PATCH 04/13] Add using directive Former-commit-id: ccdf7d943e36d81a391f1866884f3aed0cff2c07 --- FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs index 3cde7fa..8d5b0b8 100644 --- a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs +++ b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs @@ -1,6 +1,5 @@ using System; -using System.Collections.Generic; -using System.Text; +using System.Runtime.InteropServices; namespace FFMpegCore.FFMPEG.Pipes { From e002f3fdcd4ed5bd029de454bf433d0124e10ab7 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sat, 9 May 2020 18:00:51 +0200 Subject: [PATCH 05/13] Update PipeHelpers.cs Former-commit-id: 3e58020c2e8790d62c5e6c9bc0b23cea81bb0aa5 --- FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs index 8d5b0b8..b30e490 100644 --- a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs +++ b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs @@ -12,7 +12,7 @@ public static string GetPipePath(string pipeName) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return $@"\\.\pipe\{pipeName}"; else - return $"unix:/tmp/CoreFxPipe_{pipeName}"; // dotnet uses unix sockets on unix, for more see https://github.com/dotnet/runtime/issues/24390 + return $"unix://tmp/CoreFxPipe_{pipeName}"; // dotnet uses unix sockets on unix, for more see https://github.com/dotnet/runtime/issues/24390 } } } From da3f82b08f56a15d82476bbbe85163bc90a581d9 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sat, 9 May 2020 18:18:42 +0200 Subject: [PATCH 06/13] Update PipeHelpers.cs Former-commit-id: 45f2b54384f7f3b6b922384ef1a8a43a3ce9ec54 --- FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs index b30e490..b3509a2 100644 --- a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs +++ b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs @@ -12,7 +12,7 @@ public static string GetPipePath(string pipeName) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return $@"\\.\pipe\{pipeName}"; else - return $"unix://tmp/CoreFxPipe_{pipeName}"; // dotnet uses unix sockets on unix, for more see https://github.com/dotnet/runtime/issues/24390 + return $"/tmp/CoreFxPipe_{pipeName}"; // dotnet uses unix sockets on unix, for more see https://github.com/dotnet/runtime/issues/24390 } } } From 23de941df327eb31590f8fb562e0040f9cf2ed9e Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sat, 9 May 2020 20:34:27 +0200 Subject: [PATCH 07/13] Attempt at unix pipe support Former-commit-id: 6c843968980093b92470877dca8746a0c498b5c0 --- FFMpegCore.Test/FFProbeTests.cs | 1 - .../Argument/Atoms/InputPipeArgument.cs | 6 +- .../Argument/Atoms/OutputPipeArgument.cs | 6 +- .../FFMPEG/Argument/Atoms/PipeArgument.cs | 22 ++-- .../FFMPEG/Argument/Atoms/UnixNamedPipe.cs | 105 ++++++++++++++++++ FFMpegCore/FFMPEG/FFProbe.cs | 2 +- FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs | 18 --- FFMpegCore/FFMpegCore.csproj | 1 + 8 files changed, 123 insertions(+), 38 deletions(-) create mode 100644 FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs delete mode 100644 FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 5e877ff..c931e9d 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -52,7 +52,6 @@ public void Probe_Success_FromStream_Async() using (var stream = File.OpenRead(VideoLibrary.LocalVideo.FullName)) { var info = output.ParseVideoInfoAsync(stream).WaitForResult(); - Assert.AreEqual(13, info.Duration.Seconds); } } diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/InputPipeArgument.cs b/FFMpegCore/FFMPEG/Argument/Atoms/InputPipeArgument.cs index 6197a23..4bd2357 100644 --- a/FFMpegCore/FFMPEG/Argument/Atoms/InputPipeArgument.cs +++ b/FFMpegCore/FFMPEG/Argument/Atoms/InputPipeArgument.cs @@ -30,10 +30,8 @@ public override string GetStringValue() public override async Task ProcessDataAsync(CancellationToken token) { - await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); - if (!Pipe.IsConnected) - throw new TaskCanceledException(); - await Writer.WriteDataAsync(Pipe).ConfigureAwait(false); + await Pipe.During(token).ConfigureAwait(false); + await Writer.WriteDataAsync(Pipe.GetStream()).ConfigureAwait(false); } } } diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/OutputPipeArgument.cs b/FFMpegCore/FFMPEG/Argument/Atoms/OutputPipeArgument.cs index fd02df2..389e204 100644 --- a/FFMpegCore/FFMPEG/Argument/Atoms/OutputPipeArgument.cs +++ b/FFMpegCore/FFMPEG/Argument/Atoms/OutputPipeArgument.cs @@ -24,10 +24,8 @@ public override string GetStringValue() public override async Task ProcessDataAsync(CancellationToken token) { - await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); - if (!Pipe.IsConnected) - throw new TaskCanceledException(); - await Reader.ReadDataAsync(Pipe).ConfigureAwait(false); + await Pipe.During(token).ConfigureAwait(false); + await Reader.ReadDataAsync(Pipe.GetStream()).ConfigureAwait(false); } } } diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs b/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs index 81fb872..3ca3efe 100644 --- a/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs +++ b/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs @@ -2,38 +2,40 @@ using System; using System.Collections.Generic; using System.IO.Pipes; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Mono.Unix; namespace FFMpegCore.FFMPEG.Argument { public abstract class PipeArgument : Argument { - public string PipeName { get; private set; } - public string PipePath => PipeHelpers.GetPipePath(PipeName); + public string PipePath => Pipe.PipePath; - protected NamedPipeServerStream Pipe { get; private set; } + protected INamedPipe Pipe { get; private set; } private PipeDirection direction; protected PipeArgument(PipeDirection direction) { - PipeName = PipeHelpers.GetUnqiuePipeName(); + var pipeName = "FFMpegCore_Pipe_" + Guid.NewGuid(); + Pipe = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) switch + { + true => new WindowsNamedPipe(pipeName), + false => new UnixNamedPipe(pipeName) + }; this.direction = direction; } public void OpenPipe() { - if (Pipe != null) - throw new InvalidOperationException("Pipe already has been opened"); - - Pipe = new NamedPipeServerStream(PipeName, direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); + Pipe.Open(direction); } public void ClosePipe() { - Pipe?.Dispose(); - Pipe = null; + Pipe.Close(); } public Task ProcessDataAsync() { diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs b/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs new file mode 100644 index 0000000..3cbe30d --- /dev/null +++ b/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs @@ -0,0 +1,105 @@ +using System; +using System.IO; +using System.IO.Pipes; +using System.Threading; +using System.Threading.Tasks; +using Instances; + +namespace FFMpegCore.FFMPEG.Argument +{ + + public interface INamedPipe + { + public void Open(PipeDirection direction); + public Task During(CancellationToken cancellationToken); + public void Close(); + System.IO.Stream GetStream(); + string PipePath { get; } + } + + public class WindowsNamedPipe : INamedPipe + { + private readonly string _pipeName; + + public WindowsNamedPipe(string pipeName) + { + _pipeName = pipeName; + } + public void Open(PipeDirection direction) + { + if (Pipe != null) + throw new InvalidOperationException("Pipe already has been opened"); + + Pipe = new NamedPipeServerStream(_pipeName, direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); + } + + public async Task During(CancellationToken cancellationToken) + { + await Pipe.WaitForConnectionAsync(cancellationToken).ConfigureAwait(false); + if (!Pipe.IsConnected) + throw new TaskCanceledException(); + } + + public System.IO.Stream GetStream() + { + return Pipe; + } + + public NamedPipeServerStream Pipe { get; set; } + + public void Close() + { + Pipe?.Dispose(); + Pipe = null; + } + public string PipePath => $@"\\.\pipe\{_pipeName}"; + } + public class UnixNamedPipe : INamedPipe + { + private readonly string _pipeName; + private PipeDirection _direction; + + public UnixNamedPipe(string pipeName) + { + _pipeName = pipeName; + } + + public void Open(PipeDirection direction) + { + if (direction == PipeDirection.InOut) + throw new NotImplementedException(); + _direction = direction; + + if (File.Exists(PipePath)) + throw new IOException($"Pipe name is already in use ({PipePath})"); + + var (exitCode, _) = Instance.Finish("mkfifo", PipePath); + if (exitCode != 0) + throw new IOException($"Could not create FIFO file. (mkfifo failed with argument '{PipePath}')"); + } + public Task During(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public void Close() + { + if (!File.Exists(PipePath)) + throw new IOException($"Could not find pipe to close"); + + File.Delete(PipePath); + } + + public System.IO.Stream GetStream() + { + return _direction switch + { + PipeDirection.In => File.OpenRead(PipePath), + PipeDirection.Out => File.OpenWrite(PipePath), + _ => throw new NotImplementedException() + }; + } + + public string PipePath => $"/tmp/CoreFxPipe_FIFO_{_pipeName}"; + } +} \ No newline at end of file diff --git a/FFMpegCore/FFMPEG/FFProbe.cs b/FFMpegCore/FFMPEG/FFProbe.cs index d73a8f5..5f54303 100644 --- a/FFMpegCore/FFMPEG/FFProbe.cs +++ b/FFMpegCore/FFMPEG/FFProbe.cs @@ -121,7 +121,7 @@ public async Task ParseVideoInfoAsync(System.IO.Stream stream) var task = instance.FinishedRunning(); try { - await pipeArgument.ProcessDataAsync(); + await pipeArgument.ProcessDataAsync().ConfigureAwait(false); pipeArgument.ClosePipe(); } catch (IOException) diff --git a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs deleted file mode 100644 index b3509a2..0000000 --- a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace FFMpegCore.FFMPEG.Pipes -{ - static class PipeHelpers - { - public static string GetUnqiuePipeName() => "FFMpegCore_Pipe_" + Guid.NewGuid(); - - public static string GetPipePath(string pipeName) - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - return $@"\\.\pipe\{pipeName}"; - else - return $"/tmp/CoreFxPipe_{pipeName}"; // dotnet uses unix sockets on unix, for more see https://github.com/dotnet/runtime/issues/24390 - } - } -} diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index f400dc0..7308d0e 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -32,6 +32,7 @@ Thanks to max619 and WeihanLi + From 7167b4f7289fb7b0f660dc9cc2d08e31355d282c Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sat, 9 May 2020 20:42:20 +0200 Subject: [PATCH 08/13] Remove timeouts Former-commit-id: 8787ccaa8d22a54125adc0f7125f479a88244b43 --- FFMpegCore.Test/VideoTest.cs | 56 ++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 5ff5da9..53024ed 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -270,34 +270,34 @@ public void ConvertFromPipe(VideoType type, ArgumentContainer container, PixelFo } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4() { Convert(VideoType.Mp4); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Args() { var container = new ArgumentContainer { new VideoCodecArgument(VideoCodec.LibX264) }; Convert(VideoType.Mp4, container); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Args_Pipe() { var container = new ArgumentContainer { new VideoCodecArgument(VideoCodec.LibX264) }; ConvertFromPipe(VideoType.Mp4, container, PixelFormat.Format24bppRgb); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Args_StreamPipe() { var container = new ArgumentContainer { new VideoCodecArgument(VideoCodec.LibX264) }; ConvertFromStreamPipe(VideoType.Mp4, container); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() { Assert.ThrowsException(() => @@ -319,7 +319,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() }); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Args_StreamOutputPipe_Failure() { Assert.ThrowsException(() => @@ -333,7 +333,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Failure() } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Args_StreamOutputPipe_Async() { using (var ms = new MemoryStream()) @@ -352,7 +352,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async() } } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Args_StreamOutputPipe() { var container = new ArgumentContainer @@ -363,13 +363,13 @@ public void Video_ToMP4_Args_StreamOutputPipe() ConvertToStreamPipe(VideoType.Mp4, container); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToTS() { Convert(VideoType.Ts); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToTS_Args() { var container = new ArgumentContainer @@ -381,7 +381,7 @@ public void Video_ToTS_Args() Convert(VideoType.Ts, container); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToTS_Args_Pipe() { var container = new ArgumentContainer @@ -391,13 +391,13 @@ public void Video_ToTS_Args_Pipe() ConvertFromPipe(VideoType.Ts, container, PixelFormat.Format32bppArgb); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToOGV_Resize() { Convert(VideoType.Ogv, true, VideoSize.Ed); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToOGV_Resize_Args() { var container = new ArgumentContainer @@ -408,7 +408,7 @@ public void Video_ToOGV_Resize_Args() Convert(VideoType.Ogv, container); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToOGV_Resize_Args_Pipe() { var container = new ArgumentContainer @@ -419,13 +419,13 @@ public void Video_ToOGV_Resize_Args_Pipe() ConvertFromPipe(VideoType.Ogv, container, PixelFormat.Format48bppRgb); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Resize() { Convert(VideoType.Mp4, true, VideoSize.Ed); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Resize_Args() { var container = new ArgumentContainer @@ -436,7 +436,7 @@ public void Video_ToMP4_Resize_Args() Convert(VideoType.Mp4, container); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_Resize_Args_Pipe() { var container = new ArgumentContainer @@ -452,25 +452,25 @@ public void Video_ToOGV() Convert(VideoType.Ogv); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToMP4_MultiThread() { Convert(VideoType.Mp4, true); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToTS_MultiThread() { Convert(VideoType.Ts, true); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_ToOGV_MultiThread() { Convert(VideoType.Ogv, true); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_Snapshot() { var output = Input.OutputLocation(ImageType.Png); @@ -491,7 +491,7 @@ public void Video_Snapshot() } } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_Snapshot_PersistSnapshot() { var output = Input.OutputLocation(ImageType.Png); @@ -512,7 +512,7 @@ public void Video_Snapshot_PersistSnapshot() } } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_Join() { var output = Input.OutputLocation(VideoType.Mp4); @@ -544,7 +544,7 @@ public void Video_Join() } } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_Join_Image_Sequence() { try @@ -580,7 +580,7 @@ public void Video_Join_Image_Sequence() } } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_With_Only_Audio_Should_Extract_Metadata() { var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideoAudioOnly); @@ -590,7 +590,7 @@ public void Video_With_Only_Audio_Should_Extract_Metadata() Assert.AreEqual(1.25, video.Size); } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_Duration() { var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo); @@ -622,7 +622,7 @@ public void Video_Duration() } } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_UpdatesProgress() { var output = Input.OutputLocation(VideoType.Mp4); @@ -653,7 +653,7 @@ public void Video_UpdatesProgress() } } - [TestMethod, Timeout(15000)] + [TestMethod] public void Video_TranscodeInMemory() { using (var resStream = new MemoryStream()) From 5d8dfc8f7ddb2da0d70e913263104844587dd234 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sat, 9 May 2020 20:52:44 +0200 Subject: [PATCH 09/13] Make close safe Former-commit-id: 372e53aa616ee6b3f037e0d01e615a2dc09594e8 --- FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs b/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs index 3cbe30d..d862b26 100644 --- a/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs +++ b/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs @@ -84,10 +84,8 @@ public Task During(CancellationToken cancellationToken) public void Close() { - if (!File.Exists(PipePath)) - throw new IOException($"Could not find pipe to close"); - - File.Delete(PipePath); + if (File.Exists(PipePath)) + File.Delete(PipePath); } public System.IO.Stream GetStream() From 364406fa2af136fe816ebebda09b4ae4fd6f9d5e Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sun, 10 May 2020 11:41:53 +0200 Subject: [PATCH 10/13] Reverted experiment Former-commit-id: 542000601a09a8404c59945ef0240d9417e8d44f --- FFMpegCore.Test/FFProbeTests.cs | 1 + FFMpegCore.Test/VideoTest.cs | 18 ++- .../Argument/Atoms/InputPipeArgument.cs | 6 +- .../Argument/Atoms/OutputPipeArgument.cs | 6 +- .../FFMPEG/Argument/Atoms/PipeArgument.cs | 22 ++-- .../FFMPEG/Argument/Atoms/UnixNamedPipe.cs | 103 ------------------ FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs | 16 +++ FFMpegCore/FFMpegCore.csproj | 1 - 8 files changed, 48 insertions(+), 125 deletions(-) delete mode 100644 FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs create mode 100644 FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index c931e9d..5e877ff 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -52,6 +52,7 @@ public void Probe_Success_FromStream_Async() using (var stream = File.OpenRead(VideoLibrary.LocalVideo.FullName)) { var info = output.ParseVideoInfoAsync(stream).WaitForResult(); + Assert.AreEqual(13, info.Duration.Seconds); } } diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 53024ed..0f4fc7f 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -219,6 +219,13 @@ public void Convert(VideoType type, ArgumentContainer container) } } + public void ConvertFromPipe(VideoType type, ArgumentContainer container) + { + ConvertFromPipe(type, container, PixelFormat.Format24bppRgb); + ConvertFromPipe(type, container, PixelFormat.Format32bppArgb); + ConvertFromPipe(type, container, PixelFormat.Format48bppRgb); + } + public void ConvertFromPipe(VideoType type, ArgumentContainer container, PixelFormat fmt) { var output = Input.OutputLocation(type); @@ -287,7 +294,7 @@ public void Video_ToMP4_Args() public void Video_ToMP4_Args_Pipe() { var container = new ArgumentContainer { new VideoCodecArgument(VideoCodec.LibX264) }; - ConvertFromPipe(VideoType.Mp4, container, PixelFormat.Format24bppRgb); + ConvertFromPipe(VideoType.Mp4, container); } [TestMethod] @@ -388,7 +395,7 @@ public void Video_ToTS_Args_Pipe() { new ForceFormatArgument(VideoCodec.MpegTs) }; - ConvertFromPipe(VideoType.Ts, container, PixelFormat.Format32bppArgb); + ConvertFromPipe(VideoType.Ts, container); } [TestMethod] @@ -416,7 +423,7 @@ public void Video_ToOGV_Resize_Args_Pipe() new ScaleArgument(VideoSize.Ed), new VideoCodecArgument(VideoCodec.LibTheora) }; - ConvertFromPipe(VideoType.Ogv, container, PixelFormat.Format48bppRgb); + ConvertFromPipe(VideoType.Ogv, container); } [TestMethod] @@ -441,12 +448,13 @@ public void Video_ToMP4_Resize_Args_Pipe() { var container = new ArgumentContainer { + new ScaleArgument(VideoSize.Ld), new VideoCodecArgument(VideoCodec.LibX264) }; - ConvertFromPipe(VideoType.Mp4, container, PixelFormat.Format24bppRgb); + ConvertFromPipe(VideoType.Mp4, container); } - [TestMethod, Timeout(30000)] + [TestMethod] public void Video_ToOGV() { Convert(VideoType.Ogv); diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/InputPipeArgument.cs b/FFMpegCore/FFMPEG/Argument/Atoms/InputPipeArgument.cs index 4bd2357..6197a23 100644 --- a/FFMpegCore/FFMPEG/Argument/Atoms/InputPipeArgument.cs +++ b/FFMpegCore/FFMPEG/Argument/Atoms/InputPipeArgument.cs @@ -30,8 +30,10 @@ public override string GetStringValue() public override async Task ProcessDataAsync(CancellationToken token) { - await Pipe.During(token).ConfigureAwait(false); - await Writer.WriteDataAsync(Pipe.GetStream()).ConfigureAwait(false); + await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); + if (!Pipe.IsConnected) + throw new TaskCanceledException(); + await Writer.WriteDataAsync(Pipe).ConfigureAwait(false); } } } diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/OutputPipeArgument.cs b/FFMpegCore/FFMPEG/Argument/Atoms/OutputPipeArgument.cs index 389e204..fd02df2 100644 --- a/FFMpegCore/FFMPEG/Argument/Atoms/OutputPipeArgument.cs +++ b/FFMpegCore/FFMPEG/Argument/Atoms/OutputPipeArgument.cs @@ -24,8 +24,10 @@ public override string GetStringValue() public override async Task ProcessDataAsync(CancellationToken token) { - await Pipe.During(token).ConfigureAwait(false); - await Reader.ReadDataAsync(Pipe.GetStream()).ConfigureAwait(false); + await Pipe.WaitForConnectionAsync(token).ConfigureAwait(false); + if (!Pipe.IsConnected) + throw new TaskCanceledException(); + await Reader.ReadDataAsync(Pipe).ConfigureAwait(false); } } } diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs b/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs index 3ca3efe..81fb872 100644 --- a/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs +++ b/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs @@ -2,40 +2,38 @@ using System; using System.Collections.Generic; using System.IO.Pipes; -using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; -using Mono.Unix; namespace FFMpegCore.FFMPEG.Argument { public abstract class PipeArgument : Argument { - public string PipePath => Pipe.PipePath; + public string PipeName { get; private set; } + public string PipePath => PipeHelpers.GetPipePath(PipeName); - protected INamedPipe Pipe { get; private set; } + protected NamedPipeServerStream Pipe { get; private set; } private PipeDirection direction; protected PipeArgument(PipeDirection direction) { - var pipeName = "FFMpegCore_Pipe_" + Guid.NewGuid(); - Pipe = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) switch - { - true => new WindowsNamedPipe(pipeName), - false => new UnixNamedPipe(pipeName) - }; + PipeName = PipeHelpers.GetUnqiuePipeName(); this.direction = direction; } public void OpenPipe() { - Pipe.Open(direction); + if (Pipe != null) + throw new InvalidOperationException("Pipe already has been opened"); + + Pipe = new NamedPipeServerStream(PipeName, direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); } public void ClosePipe() { - Pipe.Close(); + Pipe?.Dispose(); + Pipe = null; } public Task ProcessDataAsync() { diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs b/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs deleted file mode 100644 index d862b26..0000000 --- a/FFMpegCore/FFMPEG/Argument/Atoms/UnixNamedPipe.cs +++ /dev/null @@ -1,103 +0,0 @@ -using System; -using System.IO; -using System.IO.Pipes; -using System.Threading; -using System.Threading.Tasks; -using Instances; - -namespace FFMpegCore.FFMPEG.Argument -{ - - public interface INamedPipe - { - public void Open(PipeDirection direction); - public Task During(CancellationToken cancellationToken); - public void Close(); - System.IO.Stream GetStream(); - string PipePath { get; } - } - - public class WindowsNamedPipe : INamedPipe - { - private readonly string _pipeName; - - public WindowsNamedPipe(string pipeName) - { - _pipeName = pipeName; - } - public void Open(PipeDirection direction) - { - if (Pipe != null) - throw new InvalidOperationException("Pipe already has been opened"); - - Pipe = new NamedPipeServerStream(_pipeName, direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); - } - - public async Task During(CancellationToken cancellationToken) - { - await Pipe.WaitForConnectionAsync(cancellationToken).ConfigureAwait(false); - if (!Pipe.IsConnected) - throw new TaskCanceledException(); - } - - public System.IO.Stream GetStream() - { - return Pipe; - } - - public NamedPipeServerStream Pipe { get; set; } - - public void Close() - { - Pipe?.Dispose(); - Pipe = null; - } - public string PipePath => $@"\\.\pipe\{_pipeName}"; - } - public class UnixNamedPipe : INamedPipe - { - private readonly string _pipeName; - private PipeDirection _direction; - - public UnixNamedPipe(string pipeName) - { - _pipeName = pipeName; - } - - public void Open(PipeDirection direction) - { - if (direction == PipeDirection.InOut) - throw new NotImplementedException(); - _direction = direction; - - if (File.Exists(PipePath)) - throw new IOException($"Pipe name is already in use ({PipePath})"); - - var (exitCode, _) = Instance.Finish("mkfifo", PipePath); - if (exitCode != 0) - throw new IOException($"Could not create FIFO file. (mkfifo failed with argument '{PipePath}')"); - } - public Task During(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - - public void Close() - { - if (File.Exists(PipePath)) - File.Delete(PipePath); - } - - public System.IO.Stream GetStream() - { - return _direction switch - { - PipeDirection.In => File.OpenRead(PipePath), - PipeDirection.Out => File.OpenWrite(PipePath), - _ => throw new NotImplementedException() - }; - } - - public string PipePath => $"/tmp/CoreFxPipe_FIFO_{_pipeName}"; - } -} \ No newline at end of file diff --git a/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs new file mode 100644 index 0000000..6717dac --- /dev/null +++ b/FFMpegCore/FFMPEG/Pipes/PipeHelpers.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace FFMpegCore.FFMPEG.Pipes +{ + static class PipeHelpers + { + public static string GetUnqiuePipeName() => "FFMpegCore_Pipe_" + Guid.NewGuid(); + + public static string GetPipePath(string pipeName) + { + return $@"\\.\pipe\{pipeName}"; + } + } +} diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index 7308d0e..f400dc0 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -32,7 +32,6 @@ Thanks to max619 and WeihanLi - From d2852e7e568fae00cbf89f9501dbc118b7799ee7 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sun, 10 May 2020 11:46:33 +0200 Subject: [PATCH 11/13] Fix probe tests and add timeouts Former-commit-id: dc30010725deb94f98819182089e865d36aaa9b0 --- FFMpegCore.Test/FFProbeTests.cs | 8 ++++---- FFMpegCore.Test/VideoTest.cs | 4 ++-- FFMpegCore/FFMPEG/FFProbe.cs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 5e877ff..e9b01aa 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -37,10 +37,10 @@ public void Probe_Success_FromStream() { var output = new FFProbe(); - using (var stream = File.OpenRead(VideoLibrary.LocalVideo.FullName)) + using (var stream = File.OpenRead(VideoLibrary.LocalVideoWebm.FullName)) { var info = output.ParseVideoInfo(stream); - Assert.AreEqual(13, info.Duration.Seconds); + Assert.AreEqual(10, info.Duration.Seconds); } } @@ -49,11 +49,11 @@ public void Probe_Success_FromStream_Async() { var output = new FFProbe(); - using (var stream = File.OpenRead(VideoLibrary.LocalVideo.FullName)) + using (var stream = File.OpenRead(VideoLibrary.LocalVideoWebm.FullName)) { var info = output.ParseVideoInfoAsync(stream).WaitForResult(); - Assert.AreEqual(13, info.Duration.Seconds); + Assert.AreEqual(10, info.Duration.Seconds); } } } diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 0f4fc7f..22bdfb6 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -304,7 +304,7 @@ public void Video_ToMP4_Args_StreamPipe() ConvertFromStreamPipe(VideoType.Mp4, container); } - [TestMethod] + [TestMethod, Timeout(45000)] public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() { Assert.ThrowsException(() => @@ -326,7 +326,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() }); } - [TestMethod] + [TestMethod, Timeout(45000)] public void Video_ToMP4_Args_StreamOutputPipe_Failure() { Assert.ThrowsException(() => diff --git a/FFMpegCore/FFMPEG/FFProbe.cs b/FFMpegCore/FFMPEG/FFProbe.cs index 5f54303..d73a8f5 100644 --- a/FFMpegCore/FFMPEG/FFProbe.cs +++ b/FFMpegCore/FFMPEG/FFProbe.cs @@ -121,7 +121,7 @@ public async Task ParseVideoInfoAsync(System.IO.Stream stream) var task = instance.FinishedRunning(); try { - await pipeArgument.ProcessDataAsync().ConfigureAwait(false); + await pipeArgument.ProcessDataAsync(); pipeArgument.ClosePipe(); } catch (IOException) From 6d55faf3f559132a29dc2b326115cd0f5518b8e0 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sun, 10 May 2020 12:07:28 +0200 Subject: [PATCH 12/13] Add timeouts Former-commit-id: d923dace6cdb93ada19ff3c5bf852027c5210c5c --- FFMpegCore.Test/FFProbeTests.cs | 4 ++-- FFMpegCore.Test/VideoTest.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index e9b01aa..bddef38 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -32,7 +32,7 @@ public void Probe_Success() Assert.AreEqual(13, info.Duration.Seconds); } - [TestMethod] + [TestMethod, Timeout(10000)] public void Probe_Success_FromStream() { var output = new FFProbe(); @@ -44,7 +44,7 @@ public void Probe_Success_FromStream() } } - [TestMethod] + [TestMethod, Timeout(10000)] public void Probe_Success_FromStream_Async() { var output = new FFProbe(); diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 22bdfb6..1c9085d 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -314,7 +314,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() var pipeSource = new StreamPipeDataReader(ms); var container = new ArgumentContainer { - new InputArgument(VideoLibrary.LocalVideo), + new InputArgument(VideoLibrary.LocalVideoWebm), new VideoCodecArgument(VideoCodec.LibX264), new ForceFormatArgument("mkv"), new OutputPipeArgument(pipeSource) From 4c1f49b6ac827c6186308d1b7185234a2bfde941 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sun, 10 May 2020 12:17:30 +0200 Subject: [PATCH 13/13] Update PipeArgument.cs Former-commit-id: a355f7416f1138eb9a3d01a2e4e8b7fb1b84d292 --- FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs b/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs index 81fb872..5f843ff 100644 --- a/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs +++ b/FFMpegCore/FFMPEG/Argument/Atoms/PipeArgument.cs @@ -35,9 +35,9 @@ public void ClosePipe() Pipe?.Dispose(); Pipe = null; } - public Task ProcessDataAsync() + public async Task ProcessDataAsync() { - return ProcessDataAsync(CancellationToken.None); + await ProcessDataAsync(CancellationToken.None).ConfigureAwait(false); } public abstract Task ProcessDataAsync(CancellationToken token);