mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 10:05:44 +00:00
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace FFMpegCore.FFMPEG
|
|
{
|
|
public class FFMpegOptions
|
|
{
|
|
private static readonly string ConfigFile = Path.Combine(".", "ffmpeg.config.json");
|
|
private static readonly string DefaultRoot = Path.Combine(".", "FFMPEG", "bin");
|
|
|
|
public static FFMpegOptions Options { get; private set; } = new FFMpegOptions();
|
|
|
|
public static void Configure(Action<FFMpegOptions> optionsAction)
|
|
{
|
|
optionsAction?.Invoke(Options);
|
|
}
|
|
|
|
public static void Configure(FFMpegOptions options)
|
|
{
|
|
if (null == options)
|
|
{
|
|
throw new ArgumentNullException(nameof(options));
|
|
}
|
|
Options = options;
|
|
}
|
|
|
|
static FFMpegOptions()
|
|
{
|
|
if (File.Exists(ConfigFile))
|
|
{
|
|
Options = JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText(ConfigFile));
|
|
}
|
|
}
|
|
|
|
public string RootDirectory { get; set; } = DefaultRoot;
|
|
|
|
public string FFmpegBinary => FFBinary("FFMpeg");
|
|
|
|
public string FFProbeBinary => FFBinary("FFProbe");
|
|
|
|
private static string FFBinary(string name)
|
|
{
|
|
var ffName = name.ToLowerInvariant();
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
ffName += ".exe";
|
|
|
|
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
|
if (Directory.Exists(Path.Combine(Options.RootDirectory, target)))
|
|
{
|
|
ffName = Path.Combine(target, ffName);
|
|
}
|
|
|
|
return Path.Combine(Options.RootDirectory, ffName);
|
|
}
|
|
}
|
|
}
|