Updated FFProbe

This commit is contained in:
Максим Багрянцев 2020-04-28 22:39:26 +03:00
parent 06f5c319ad
commit 11edbbea2b

View file

@ -7,6 +7,7 @@
using Instances;
using FFMpegCore.FFMPEG.Argument;
using FFMpegCore.FFMPEG.Pipes;
using System.IO;
namespace FFMpegCore.FFMPEG
{
@ -81,18 +82,23 @@ public VideoInfo ParseVideoInfo(System.IO.Stream stream)
var instance = new Instance(_ffprobePath, BuildFFProbeArguments(pipeArgument.PipePath)) { DataBufferCapacity = _outputCapacity };
pipeArgument.OpenPipe();
var task = instance.FinishedRunning();
try
{
var task = instance.FinishedRunning();
pipeArgument.FlushPipe();
pipeArgument.ProcessDataAsync().ConfigureAwait(false).GetAwaiter().GetResult();
pipeArgument.ClosePipe();
task.Wait();
}
catch(IOException)
{
}
finally
{
pipeArgument.ClosePipe();
}
var exitCode = task.ConfigureAwait(false).GetAwaiter().GetResult();
if (exitCode != 0)
throw new FFMpegException(FFMpegExceptionType.Process, "FFProbe process returned exit status " + exitCode);
var output = string.Join("", instance.OutputData);
return ParseVideoInfoInternal(info, output);
}
@ -111,17 +117,20 @@ public async Task<VideoInfo> ParseVideoInfoAsync(System.IO.Stream stream)
var instance = new Instance(_ffprobePath, BuildFFProbeArguments(pipeArgument.PipePath)) { DataBufferCapacity = _outputCapacity };
pipeArgument.OpenPipe();
var task = instance.FinishedRunning();
try
{
var task = instance.FinishedRunning();
await pipeArgument.FlushPipeAsync();
await pipeArgument.ProcessDataAsync();
pipeArgument.ClosePipe();
await task;
}
catch (IOException)
{
}
finally
{
pipeArgument.ClosePipe();
}
var exitCode = await task;
var output = string.Join("", instance.OutputData);
return ParseVideoInfoInternal(info, output);