Updated FFProbe

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

View file

@ -7,6 +7,7 @@
using Instances; using Instances;
using FFMpegCore.FFMPEG.Argument; using FFMpegCore.FFMPEG.Argument;
using FFMpegCore.FFMPEG.Pipes; using FFMpegCore.FFMPEG.Pipes;
using System.IO;
namespace FFMpegCore.FFMPEG namespace FFMpegCore.FFMPEG
{ {
@ -81,18 +82,23 @@ public VideoInfo ParseVideoInfo(System.IO.Stream stream)
var instance = new Instance(_ffprobePath, BuildFFProbeArguments(pipeArgument.PipePath)) { DataBufferCapacity = _outputCapacity }; var instance = new Instance(_ffprobePath, BuildFFProbeArguments(pipeArgument.PipePath)) { DataBufferCapacity = _outputCapacity };
pipeArgument.OpenPipe(); pipeArgument.OpenPipe();
var task = instance.FinishedRunning();
try try
{ {
var task = instance.FinishedRunning(); pipeArgument.ProcessDataAsync().ConfigureAwait(false).GetAwaiter().GetResult();
pipeArgument.FlushPipe();
pipeArgument.ClosePipe(); pipeArgument.ClosePipe();
task.Wait(); }
catch(IOException)
{
} }
finally finally
{ {
pipeArgument.ClosePipe(); 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); var output = string.Join("", instance.OutputData);
return ParseVideoInfoInternal(info, output); 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 }; var instance = new Instance(_ffprobePath, BuildFFProbeArguments(pipeArgument.PipePath)) { DataBufferCapacity = _outputCapacity };
pipeArgument.OpenPipe(); pipeArgument.OpenPipe();
var task = instance.FinishedRunning();
try try
{ {
var task = instance.FinishedRunning(); await pipeArgument.ProcessDataAsync();
await pipeArgument.FlushPipeAsync();
pipeArgument.ClosePipe(); pipeArgument.ClosePipe();
await task; }
catch (IOException)
{
} }
finally finally
{ {
pipeArgument.ClosePipe(); pipeArgument.ClosePipe();
} }
var exitCode = await task;
var output = string.Join("", instance.OutputData); var output = string.Join("", instance.OutputData);
return ParseVideoInfoInternal(info, output); return ParseVideoInfoInternal(info, output);