mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
fee7d6f450
commit
af6480e1d9
4 changed files with 29 additions and 5 deletions
|
@ -126,6 +126,7 @@ await Task.WhenAll(instance.FinishedRunning().ContinueWith(t =>
|
|||
private Instance PrepareInstance(out CancellationTokenSource cancellationTokenSource)
|
||||
{
|
||||
FFMpegHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
||||
FFMpegHelper.VerifyFFMpegExists();
|
||||
var instance = new Instance(FFMpegOptions.Options.FFmpegBinary(), _ffMpegArguments.Text);
|
||||
instance.DataReceived += OutputData;
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
|
|
|
@ -87,6 +87,7 @@ private static Instance PrepareInstance(string filePath, int outputCapacity)
|
|||
{
|
||||
FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
||||
var ffprobe = FFMpegOptions.Options.FFProbeBinary();
|
||||
FFProbeHelper.VerifyFFProbeExists();
|
||||
var arguments = $"-print_format json -show_format -sexagesimal -show_streams \"{filePath}\"";
|
||||
var instance = new Instance(ffprobe, arguments) {DataBufferCapacity = outputCapacity};
|
||||
return instance;
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
using System.Drawing;
|
||||
using System.IO;
|
||||
using FFMpegCore.Exceptions;
|
||||
using Instances;
|
||||
|
||||
namespace FFMpegCore.Helpers
|
||||
{
|
||||
public static class FFMpegHelper
|
||||
{
|
||||
private static bool _ffmpegVerified;
|
||||
|
||||
public static void ConversionSizeExceptionCheck(Image image)
|
||||
{
|
||||
ConversionSizeExceptionCheck(image.Size);
|
||||
|
@ -32,11 +35,19 @@ public static void ExtensionExceptionCheck(string filename, string extension)
|
|||
$"Invalid output file. File extension should be '{extension}' required.");
|
||||
}
|
||||
|
||||
public static void RootExceptionCheck(string root)
|
||||
public static void RootExceptionCheck()
|
||||
{
|
||||
if (root == null)
|
||||
if (FFMpegOptions.Options.RootDirectory == null)
|
||||
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
||||
"FFMpeg root is not configured in app config. Missing key 'ffmpegRoot'.");
|
||||
}
|
||||
|
||||
public static void VerifyFFMpegExists()
|
||||
{
|
||||
if (_ffmpegVerified) return;
|
||||
var (exitCode, _) = Instance.Finish(FFMpegOptions.Options.FFmpegBinary(), "-version");
|
||||
_ffmpegVerified = exitCode == 0;
|
||||
if (!_ffmpegVerified) throw new FFMpegException(FFMpegExceptionType.Operation, "ffmpeg was not found on your system");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
using FFMpegCore.Exceptions;
|
||||
using Instances;
|
||||
|
||||
namespace FFMpegCore.Helpers
|
||||
{
|
||||
public class FFProbeHelper
|
||||
{
|
||||
private static bool _ffprobeVerified;
|
||||
|
||||
public static int Gcd(int first, int second)
|
||||
{
|
||||
while (first != 0 && second != 0)
|
||||
|
@ -15,12 +18,20 @@ public static int Gcd(int first, int second)
|
|||
return first == 0 ? second : first;
|
||||
}
|
||||
|
||||
public static void RootExceptionCheck(string root)
|
||||
public static void RootExceptionCheck()
|
||||
{
|
||||
if (root == null)
|
||||
if (FFMpegOptions.Options.RootDirectory == null)
|
||||
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
||||
"FFProbe root is not configured in app config. Missing key 'ffmpegRoot'.");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void VerifyFFProbeExists()
|
||||
{
|
||||
if (_ffprobeVerified) return;
|
||||
var (exitCode, _) = Instance.Finish(FFMpegOptions.Options.FFProbeBinary(), "-version");
|
||||
_ffprobeVerified = exitCode == 0;
|
||||
if (!_ffprobeVerified) throw new FFMpegException(FFMpegExceptionType.Operation, "ffprobe was not found on your system");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue