diff --git a/FFMpegCore.Test/ffmpeg.config.json b/FFMpegCore.Test/ffmpeg.config.json index 5b351c0..12322b0 100644 --- a/FFMpegCore.Test/ffmpeg.config.json +++ b/FFMpegCore.Test/ffmpeg.config.json @@ -1,3 +1,3 @@ { - "RootDirectory": "./FFMPEG/bin" + "RootDirectory": "C:\\ProgramData\\chocolatey\\lib\\ffmpeg\\tools\\ffmpeg\\bin\\" } \ No newline at end of file diff --git a/FFMpegCore/FFMPEG/FFMpeg.cs b/FFMpegCore/FFMPEG/FFMpeg.cs index 561fb65..bb83813 100644 --- a/FFMpegCore/FFMPEG/FFMpeg.cs +++ b/FFMpegCore/FFMPEG/FFMpeg.cs @@ -30,16 +30,7 @@ public FFMpeg(): base() { FFMpegHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory); - var progName = "ffmpeg"; - if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) { - var target = Environment.Is64BitProcess ? "x64" : "x86"; - - progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe"; - } - - var path = $"{Path.DirectorySeparatorChar}{progName}"; - - _ffmpegPath = $"{FFMpegOptions.Options.RootDirectory}{path}"; + _ffmpegPath = FFMpegOptions.Options.FFmpegBinary; ArgumentBuilder = new FFArgumentBuilder(); } diff --git a/FFMpegCore/FFMPEG/FFMpegOptions.cs b/FFMpegCore/FFMPEG/FFMpegOptions.cs index aa34749..a16ba60 100644 --- a/FFMpegCore/FFMPEG/FFMpegOptions.cs +++ b/FFMpegCore/FFMPEG/FFMpegOptions.cs @@ -1,5 +1,8 @@ -using Newtonsoft.Json; +using FFMpegCore.FFMPEG.Exceptions; +using Newtonsoft.Json; +using System; using System.IO; +using System.Runtime.InteropServices; namespace FFMpegCore.FFMPEG { @@ -24,5 +27,49 @@ static FFMpegOptions() } public string RootDirectory { get; set; } = _DefaultRoot; + + public string FFmpegBinary + { + get + { + var target = Environment.Is64BitProcess ? "x64" : "x86"; + var progName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "ffmpeg.exe" : "ffmpeg"; + + if (Directory.Exists($"{Options.RootDirectory}{target}")) + { + progName = $"{target}{Path.DirectorySeparatorChar}{progName}"; + } + + var path = $"{Options.RootDirectory}{Path.DirectorySeparatorChar}{progName}"; + + if (!File.Exists(path)) + throw new FFMpegException(FFMpegExceptionType.Dependency, + $"FFMpeg cannot be found @ {path}"); + + return path; + } + } + + public string FFProbeBinary + { + get + { + var target = Environment.Is64BitProcess ? "x64" : "x86"; + var progName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "ffprobe.exe" : "ffprobe"; + + if (Directory.Exists($"{Options.RootDirectory}{target}")) + { + progName = $"{target}{Path.DirectorySeparatorChar}{progName}"; + } + + var path = $"{Options.RootDirectory}{Path.DirectorySeparatorChar}{progName}"; + + if (!File.Exists(path)) + throw new FFMpegException(FFMpegExceptionType.Dependency, + $"FFProbe cannot be found @ {path}"); + + return path; + } + } } } diff --git a/FFMpegCore/FFMPEG/FFProbe.cs b/FFMpegCore/FFMPEG/FFProbe.cs index 838c271..df32c93 100644 --- a/FFMpegCore/FFMPEG/FFProbe.cs +++ b/FFMpegCore/FFMPEG/FFProbe.cs @@ -16,16 +16,7 @@ public FFProbe(): base() { FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory); - var progName = "ffprobe"; - if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) { - var target = Environment.Is64BitProcess ? "x64" : "x86"; - - progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe"; - } - - var path = $"{Path.DirectorySeparatorChar}{progName}"; - - _ffprobePath = $"{FFMpegOptions.Options.RootDirectory}{path}"; + _ffprobePath = FFMpegOptions.Options.FFProbeBinary; } /// diff --git a/FFMpegCore/FFMPEG/bin/x64/ffmpeg.exe b/FFMpegCore/FFMPEG/bin/x64/ffmpeg.exe deleted file mode 100644 index cbeb93b..0000000 Binary files a/FFMpegCore/FFMPEG/bin/x64/ffmpeg.exe and /dev/null differ diff --git a/FFMpegCore/FFMPEG/bin/x64/ffprobe.exe b/FFMpegCore/FFMPEG/bin/x64/ffprobe.exe deleted file mode 100644 index adf675e..0000000 Binary files a/FFMpegCore/FFMPEG/bin/x64/ffprobe.exe and /dev/null differ diff --git a/FFMpegCore/FFMPEG/bin/x86/ffmpeg.exe b/FFMpegCore/FFMPEG/bin/x86/ffmpeg.exe deleted file mode 100644 index 9582198..0000000 Binary files a/FFMpegCore/FFMPEG/bin/x86/ffmpeg.exe and /dev/null differ diff --git a/FFMpegCore/FFMPEG/bin/x86/ffprobe.exe b/FFMpegCore/FFMPEG/bin/x86/ffprobe.exe deleted file mode 100644 index 5a70926..0000000 Binary files a/FFMpegCore/FFMPEG/bin/x86/ffprobe.exe and /dev/null differ diff --git a/FFMpegCore/FFMpegCore.csproj b/FFMpegCore/FFMpegCore.csproj index bac20dd..ef27566 100644 --- a/FFMpegCore/FFMpegCore.csproj +++ b/FFMpegCore/FFMpegCore.csproj @@ -127,18 +127,6 @@ Always - - Always - - - Always - - - Always - - - Always - diff --git a/FFMpegCore/Helpers/FFMpegHelper.cs b/FFMpegCore/Helpers/FFMpegHelper.cs index dc574dd..f0c65c3 100644 --- a/FFMpegCore/Helpers/FFMpegHelper.cs +++ b/FFMpegCore/Helpers/FFMpegHelper.cs @@ -73,19 +73,6 @@ public static void RootExceptionCheck(string root) if (root == null) throw new FFMpegException(FFMpegExceptionType.Dependency, "FFMpeg root is not configured in app config. Missing key 'ffmpegRoot'."); - - var progName = "ffmpeg"; - if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) { - var target = Environment.Is64BitProcess ? "x64" : "x86"; - - progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe"; - } - - var path = root + $"{Path.DirectorySeparatorChar}{progName}"; - - if (!File.Exists(path)) - throw new FFMpegException(FFMpegExceptionType.Dependency, - "FFMpeg cannot be found in the root directory!"); } } } diff --git a/FFMpegCore/Helpers/FFProbeHelper.cs b/FFMpegCore/Helpers/FFProbeHelper.cs index 59bc724..3efcda9 100644 --- a/FFMpegCore/Helpers/FFProbeHelper.cs +++ b/FFMpegCore/Helpers/FFProbeHelper.cs @@ -23,19 +23,7 @@ public static void RootExceptionCheck(string root) if (root == null) throw new FFMpegException(FFMpegExceptionType.Dependency, "FFProbe root is not configured in app config. Missing key 'ffmpegRoot'."); - - var progName = "ffprobe"; - if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) { - var target = Environment.Is64BitProcess ? "x64" : "x86"; - - progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe"; - } - - var path = root + $"{Path.DirectorySeparatorChar}{progName}"; - - if (!File.Exists(path)) - throw new FFMpegException(FFMpegExceptionType.Dependency, - $"FFProbe cannot be found in the in {path}..."); + } } }