Former-commit-id: 8d74a3e0d7
This commit is contained in:
Malte Rosenbjerg 2020-05-10 11:31:26 +02:00
parent c3b5cd997e
commit 06539f7b39
5 changed files with 23 additions and 37 deletions

View file

@ -2,6 +2,7 @@
using System; using System;
using FFMpegCore.Arguments; using FFMpegCore.Arguments;
using FFMpegCore.Enums; using FFMpegCore.Enums;
using FFMpegCore.Exceptions;
namespace FFMpegCore.Test namespace FFMpegCore.Test
{ {
@ -106,8 +107,7 @@ public void Builder_BuildString_DisableChannel_Video()
[TestMethod] [TestMethod]
public void Builder_BuildString_DisableChannel_Both() public void Builder_BuildString_DisableChannel_Both()
{ {
var str = FFMpegArguments.FromInputFiles(true, "input.mp4").DisableChannel(Channel.Both).OutputToFile("output.mp4").Arguments; Assert.ThrowsException<FFMpegException>(() => FFMpegArguments.FromInputFiles(true, "input.mp4").DisableChannel(Channel.Both));
Assert.AreEqual("-i \"input.mp4\" \"output.mp4\"", str);
} }
[TestMethod] [TestMethod]

View file

@ -53,17 +53,17 @@ public async Task Probe_Async_Success()
[TestMethod] [TestMethod]
public void Probe_Success_FromStream() 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); var info = FFProbe.Analyse(stream);
Assert.AreEqual(13, info.Duration.Seconds); Assert.AreEqual(10, info.Duration.Seconds);
} }
[TestMethod] [TestMethod]
public async Task Probe_Success_FromStream_Async() 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); var info = await FFProbe.AnalyseAsync(stream);
Assert.AreEqual(13, info.Duration.Seconds); Assert.AreEqual(10, info.Duration.Seconds);
} }
} }
} }

View file

@ -287,7 +287,7 @@ public void Video_ToMP4_Args_StreamPipe()
ConvertFromStreamPipe(VideoType.Mp4, new VideoCodecArgument(VideoCodec.LibX264)); ConvertFromStreamPipe(VideoType.Mp4, new VideoCodecArgument(VideoCodec.LibX264));
} }
[TestMethod] [TestMethod, Timeout(45000)]
public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure() public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure()
{ {
Assert.ThrowsException<FFMpegException>(() => Assert.ThrowsException<FFMpegException>(() =>
@ -300,11 +300,10 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async_Failure()
.OutputToPipe(pipeSource) .OutputToPipe(pipeSource)
.ProcessAsynchronously() .ProcessAsynchronously()
.WaitForResult(); .WaitForResult();
FFProbe.Analyse(ms);
}); });
} }
[TestMethod] [TestMethod, Timeout(45000)]
public void Video_ToMP4_Args_StreamOutputPipe_Failure() public void Video_ToMP4_Args_StreamOutputPipe_Failure()
{ {
Assert.ThrowsException<FFMpegException>(() => Assert.ThrowsException<FFMpegException>(() =>
@ -317,8 +316,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Failure()
[TestMethod] [TestMethod]
public void Video_ToMP4_Args_StreamOutputPipe_Async() public void Video_ToMP4_Args_StreamOutputPipe_Async()
{ {
using (var ms = new MemoryStream()) using var ms = new MemoryStream();
{
var pipeSource = new StreamPipeDataReader(ms); var pipeSource = new StreamPipeDataReader(ms);
FFMpegArguments FFMpegArguments
.FromInputFiles(VideoLibrary.LocalVideo) .FromInputFiles(VideoLibrary.LocalVideo)
@ -328,7 +326,6 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async()
.ProcessAsynchronously() .ProcessAsynchronously()
.WaitForResult(); .WaitForResult();
} }
}
[TestMethod] [TestMethod]
public void Video_ToMP4_Args_StreamOutputPipe() public void Video_ToMP4_Args_StreamOutputPipe()

View file

@ -36,13 +36,8 @@ public void Post()
public async Task During(CancellationToken? cancellationToken = null) public async Task During(CancellationToken? cancellationToken = null)
{ {
await ProcessDataAsync(cancellationToken ?? CancellationToken.None) await ProcessDataAsync(cancellationToken ?? CancellationToken.None).ConfigureAwait(false);
.ContinueWith(task =>
{
Post(); Post();
if (task.Exception != null)
throw task.Exception;
}).ConfigureAwait(false);
} }
public abstract Task ProcessDataAsync(CancellationToken token); public abstract Task ProcessDataAsync(CancellationToken token);

View file

@ -30,20 +30,14 @@ public static MediaAnalysis Analyse(System.IO.Stream stream, int outputCapacity
{ {
pipeArgument.During().ConfigureAwait(false).GetAwaiter().GetResult(); pipeArgument.During().ConfigureAwait(false).GetAwaiter().GetResult();
} }
catch (IOException) catch (IOException) { }
{
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally finally
{ {
pipeArgument.Post(); pipeArgument.Post();
} }
var exitCode = task.ConfigureAwait(false).GetAwaiter().GetResult(); var exitCode = task.ConfigureAwait(false).GetAwaiter().GetResult();
if (exitCode != 0) 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); return ParseOutput(pipeArgument.PipePath, instance);
} }
@ -74,7 +68,7 @@ public static async Task<MediaAnalysis> AnalyseAsync(System.IO.Stream stream, in
} }
var exitCode = await task; var exitCode = await task;
if (exitCode != 0) 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(); pipeArgument.Post();
return ParseOutput(pipeArgument.PipePath, instance); return ParseOutput(pipeArgument.PipePath, instance);
@ -94,7 +88,7 @@ private static Instance PrepareInstance(string filePath, int outputCapacity)
{ {
FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory); FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
var ffprobe = FFMpegOptions.Options.FFProbeBinary; 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}; var instance = new Instance(ffprobe, arguments) {DataBufferCapacity = outputCapacity};
return instance; return instance;
} }