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

View file

@ -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<FFMpegException>(() => FFMpegArguments.FromInputFiles(true, "input.mp4").DisableChannel(Channel.Both));
}
[TestMethod]

View file

@ -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);
}
}
}

View file

@ -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<FFMpegException>(() =>
@ -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<FFMpegException>(() =>
@ -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]

View file

@ -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);

View file

@ -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<MediaAnalysis> 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;
}