From 06539f7b39e92a0985e09c80e56e117b8dffd607 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sun, 10 May 2020 11:31:26 +0200 Subject: [PATCH] Fixes Former-commit-id: 8d74a3e0d7b17a7ac6c3037cd1fe0d97056bffdd --- FFMpegCore.Test/ArgumentBuilderTest.cs | 4 ++-- FFMpegCore.Test/FFProbeTests.cs | 8 +++---- FFMpegCore.Test/VideoTest.cs | 25 +++++++++------------ FFMpegCore/FFMpeg/Arguments/PipeArgument.cs | 9 ++------ FFMpegCore/FFProbe/FFProbe.cs | 14 ++++-------- 5 files changed, 23 insertions(+), 37 deletions(-) diff --git a/FFMpegCore.Test/ArgumentBuilderTest.cs b/FFMpegCore.Test/ArgumentBuilderTest.cs index 97f1db3..fb170f1 100644 --- a/FFMpegCore.Test/ArgumentBuilderTest.cs +++ b/FFMpegCore.Test/ArgumentBuilderTest.cs @@ -2,6 +2,7 @@ using System; using FFMpegCore.Arguments; using FFMpegCore.Enums; +using FFMpegCore.Exceptions; namespace FFMpegCore.Test { @@ -106,8 +107,7 @@ public void Builder_BuildString_DisableChannel_Video() [TestMethod] public void Builder_BuildString_DisableChannel_Both() { - var str = FFMpegArguments.FromInputFiles(true, "input.mp4").DisableChannel(Channel.Both).OutputToFile("output.mp4").Arguments; - Assert.AreEqual("-i \"input.mp4\" \"output.mp4\"", str); + Assert.ThrowsException(() => FFMpegArguments.FromInputFiles(true, "input.mp4").DisableChannel(Channel.Both)); } [TestMethod] diff --git a/FFMpegCore.Test/FFProbeTests.cs b/FFMpegCore.Test/FFProbeTests.cs index 13cd901..4ade53b 100644 --- a/FFMpegCore.Test/FFProbeTests.cs +++ b/FFMpegCore.Test/FFProbeTests.cs @@ -53,17 +53,17 @@ public async Task Probe_Async_Success() [TestMethod] public void Probe_Success_FromStream() { - using var stream = File.OpenRead(VideoLibrary.LocalVideo.FullName); + using var stream = File.OpenRead(VideoLibrary.LocalVideoWebm.FullName); var info = FFProbe.Analyse(stream); - Assert.AreEqual(13, info.Duration.Seconds); + Assert.AreEqual(10, info.Duration.Seconds); } [TestMethod] public async Task Probe_Success_FromStream_Async() { - await using var stream = File.OpenRead(VideoLibrary.LocalVideo.FullName); + await using var stream = File.OpenRead(VideoLibrary.LocalVideoWebm.FullName); var info = await FFProbe.AnalyseAsync(stream); - Assert.AreEqual(13, info.Duration.Seconds); + Assert.AreEqual(10, info.Duration.Seconds); } } } \ No newline at end of file diff --git a/FFMpegCore.Test/VideoTest.cs b/FFMpegCore.Test/VideoTest.cs index 74f0051..8198bf3 100644 --- a/FFMpegCore.Test/VideoTest.cs +++ b/FFMpegCore.Test/VideoTest.cs @@ -287,7 +287,7 @@ public void Video_ToMP4_Args_StreamPipe() ConvertFromStreamPipe(VideoType.Mp4, new VideoCodecArgument(VideoCodec.LibX264)); } - [TestMethod] + [TestMethod, Timeout(45000)] public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() { Assert.ThrowsException(() => @@ -300,11 +300,10 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() .OutputToPipe(pipeSource) .ProcessAsynchronously() .WaitForResult(); - FFProbe.Analyse(ms); }); } - [TestMethod] + [TestMethod, Timeout(45000)] public void Video_ToMP4_Args_StreamOutputPipe_Failure() { Assert.ThrowsException(() => @@ -317,17 +316,15 @@ public void Video_ToMP4_Args_StreamOutputPipe_Failure() [TestMethod] public void Video_ToMP4_Args_StreamOutputPipe_Async() { - using (var ms = new MemoryStream()) - { - var pipeSource = new StreamPipeDataReader(ms); - FFMpegArguments - .FromInputFiles(VideoLibrary.LocalVideo) - .WithVideoCodec(VideoCodec.LibX264) - .ForceFormat("matroska") - .OutputToPipe(pipeSource) - .ProcessAsynchronously() - .WaitForResult(); - } + using var ms = new MemoryStream(); + var pipeSource = new StreamPipeDataReader(ms); + FFMpegArguments + .FromInputFiles(VideoLibrary.LocalVideo) + .WithVideoCodec(VideoCodec.LibX264) + .ForceFormat("matroska") + .OutputToPipe(pipeSource) + .ProcessAsynchronously() + .WaitForResult(); } [TestMethod] diff --git a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs index 4a4bd46..cc8ffab 100644 --- a/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/PipeArgument.cs @@ -36,13 +36,8 @@ public void Post() public async Task During(CancellationToken? cancellationToken = null) { - await ProcessDataAsync(cancellationToken ?? CancellationToken.None) - .ContinueWith(task => - { - Post(); - if (task.Exception != null) - throw task.Exception; - }).ConfigureAwait(false); + await ProcessDataAsync(cancellationToken ?? CancellationToken.None).ConfigureAwait(false); + Post(); } public abstract Task ProcessDataAsync(CancellationToken token); diff --git a/FFMpegCore/FFProbe/FFProbe.cs b/FFMpegCore/FFProbe/FFProbe.cs index 90f6bfc..bceb4ca 100644 --- a/FFMpegCore/FFProbe/FFProbe.cs +++ b/FFMpegCore/FFProbe/FFProbe.cs @@ -30,20 +30,14 @@ public static MediaAnalysis Analyse(System.IO.Stream stream, int outputCapacity { pipeArgument.During().ConfigureAwait(false).GetAwaiter().GetResult(); } - catch (IOException) - { - } - catch (Exception e) - { - Console.WriteLine(e); - } + catch (IOException) { } finally { pipeArgument.Post(); } var exitCode = task.ConfigureAwait(false).GetAwaiter().GetResult(); if (exitCode != 0) - throw new FFMpegException(FFMpegExceptionType.Process, "FFProbe process returned exit status " + exitCode); + throw new FFMpegException(FFMpegExceptionType.Process, $"FFProbe process returned exit status {exitCode}: {string.Join("\n", instance.OutputData)} {string.Join("\n", instance.ErrorData)}"); return ParseOutput(pipeArgument.PipePath, instance); } @@ -74,7 +68,7 @@ public static async Task AnalyseAsync(System.IO.Stream stream, in } var exitCode = await task; if (exitCode != 0) - throw new FFMpegException(FFMpegExceptionType.Process, "FFProbe process returned exit status " + exitCode); + throw new FFMpegException(FFMpegExceptionType.Process, $"FFProbe process returned exit status {exitCode}: {string.Join("\n", instance.OutputData)} {string.Join("\n", instance.ErrorData)}"); pipeArgument.Post(); return ParseOutput(pipeArgument.PipePath, instance); @@ -94,7 +88,7 @@ private static Instance PrepareInstance(string filePath, int outputCapacity) { FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory); var ffprobe = FFMpegOptions.Options.FFProbeBinary; - var arguments = $"-v quiet -print_format json -show_streams \"{filePath}\""; + var arguments = $"-print_format json -show_streams \"{filePath}\""; var instance = new Instance(ffprobe, arguments) {DataBufferCapacity = outputCapacity}; return instance; }