mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
c3b5cd997e
commit
06539f7b39
5 changed files with 23 additions and 37 deletions
|
@ -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]
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,8 +316,7 @@ public void Video_ToMP4_Args_StreamOutputPipe_Failure()
|
|||
[TestMethod]
|
||||
public void Video_ToMP4_Args_StreamOutputPipe_Async()
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using var ms = new MemoryStream();
|
||||
var pipeSource = new StreamPipeDataReader(ms);
|
||||
FFMpegArguments
|
||||
.FromInputFiles(VideoLibrary.LocalVideo)
|
||||
|
@ -328,7 +326,6 @@ public void Video_ToMP4_Args_StreamOutputPipe_Async()
|
|||
.ProcessAsynchronously()
|
||||
.WaitForResult();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Video_ToMP4_Args_StreamOutputPipe()
|
||||
|
|
|
@ -36,13 +36,8 @@ public void Post()
|
|||
|
||||
public async Task During(CancellationToken? cancellationToken = null)
|
||||
{
|
||||
await ProcessDataAsync(cancellationToken ?? CancellationToken.None)
|
||||
.ContinueWith(task =>
|
||||
{
|
||||
await ProcessDataAsync(cancellationToken ?? CancellationToken.None).ConfigureAwait(false);
|
||||
Post();
|
||||
if (task.Exception != null)
|
||||
throw task.Exception;
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public abstract Task ProcessDataAsync(CancellationToken token);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue