From 61387fa5be2a9b234aad0149c992565a168475f8 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Sun, 25 Oct 2020 17:12:16 +0100 Subject: [PATCH] Check for existence before analysing with ffprobe --- FFMpegCore/FFProbe/FFProbe.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/FFMpegCore/FFProbe/FFProbe.cs b/FFMpegCore/FFProbe/FFProbe.cs index 069aacc..f650371 100644 --- a/FFMpegCore/FFProbe/FFProbe.cs +++ b/FFMpegCore/FFProbe/FFProbe.cs @@ -14,6 +14,9 @@ public static class FFProbe { public static IMediaAnalysis Analyse(string filePath, int outputCapacity = int.MaxValue) { + if (!File.Exists(filePath)) + throw new FFMpegException(FFMpegExceptionType.File, $"No file found at '{filePath}'"); + using var instance = PrepareInstance(filePath, outputCapacity); instance.BlockUntilFinished(); return ParseOutput(filePath, instance); @@ -24,7 +27,7 @@ public static IMediaAnalysis Analyse(Uri uri, int outputCapacity = int.MaxValue) instance.BlockUntilFinished(); return ParseOutput(uri.AbsoluteUri, instance); } - public static IMediaAnalysis Analyse(System.IO.Stream stream, int outputCapacity = int.MaxValue) + public static IMediaAnalysis Analyse(Stream stream, int outputCapacity = int.MaxValue) { var streamPipeSource = new StreamPipeSource(stream); var pipeArgument = new InputPipeArgument(streamPipeSource); @@ -49,6 +52,9 @@ public static IMediaAnalysis Analyse(System.IO.Stream stream, int outputCapacity } public static async Task AnalyseAsync(string filePath, int outputCapacity = int.MaxValue) { + if (!File.Exists(filePath)) + throw new FFMpegException(FFMpegExceptionType.File, $"No file found at '{filePath}'"); + using var instance = PrepareInstance(filePath, outputCapacity); await instance.FinishedRunning(); return ParseOutput(filePath, instance);