mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 00:24:14 +01:00
parent
3abaf36c49
commit
7547c48927
8 changed files with 103 additions and 67 deletions
50
FFMpegCore.Test/FFMpegOptions.cs
Normal file
50
FFMpegCore.Test/FFMpegOptions.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using FFMpegCore.FFMPEG;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
|
||||
namespace FFMpegCore.Test
|
||||
{
|
||||
[TestClass]
|
||||
public class FFMpegOptionsTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void Options_Initialized()
|
||||
{
|
||||
Assert.IsNotNull(FFMpegOptions.Options);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Options_Defaults_Configured()
|
||||
{
|
||||
Assert.AreEqual(new FFMpegOptions().RootDirectory, ".\\FFMPEG\\bin");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Options_Loaded_From_File()
|
||||
{
|
||||
Assert.AreEqual(
|
||||
FFMpegOptions.Options.RootDirectory,
|
||||
JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText(".\\ffmpeg.config.json")).RootDirectory
|
||||
);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Options_Overrided()
|
||||
{
|
||||
var original = FFMpegOptions.Options;
|
||||
try
|
||||
{
|
||||
FFMpegOptions.Configure(new FFMpegOptions { RootDirectory = "Whatever" });
|
||||
Assert.AreEqual(
|
||||
FFMpegOptions.Options.RootDirectory,
|
||||
"Whatever"
|
||||
);
|
||||
}
|
||||
finally
|
||||
{
|
||||
FFMpegOptions.Configure(original);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using FFMpegCore.FFMPEG;
|
||||
using FFMpegCore.FFMPEG.Exceptions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace FFMpegCore.Test
|
||||
|
@ -16,29 +15,5 @@ public void CTOR_Default()
|
|||
Assert.IsNotNull(encoder);
|
||||
Assert.IsNotNull(probe);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CTOR_Options()
|
||||
{
|
||||
var encoder = new FFMpeg(new FFMpegOptions { RootDirectory = ".\\FFMPEG\\bin" });
|
||||
var probe = new FFProbe(new FFMpegOptions { RootDirectory = ".\\FFMPEG\\bin" });
|
||||
|
||||
Assert.IsNotNull(encoder);
|
||||
Assert.IsNotNull(probe);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(FFMpegException))]
|
||||
public void CTOR_Encoder_Options_Invalid()
|
||||
{
|
||||
var encoder = new FFMpeg(new FFMpegOptions { RootDirectory = "INVALID_DIR" });
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(FFMpegException))]
|
||||
public void CTOR_Probe_Options_Invalid()
|
||||
{
|
||||
var encoder = new FFProbe(new FFMpegOptions { RootDirectory = "INVALID_DIR" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,32 +9,10 @@ namespace FFMpegCore.FFMPEG
|
|||
{
|
||||
public abstract class FFBase : IDisposable
|
||||
{
|
||||
private static string _ConfigFile = "./ffmpeg.config.json";
|
||||
private static string _DefaultRoot = ".\\FFMPEG\\bin";
|
||||
protected string ConfiguredRoot;
|
||||
protected Process Process;
|
||||
|
||||
protected FFBase(FFMpegOptions opts = null)
|
||||
protected FFBase()
|
||||
{
|
||||
var options = opts;
|
||||
|
||||
if (
|
||||
opts == null &&
|
||||
File.Exists(_ConfigFile)
|
||||
)
|
||||
{
|
||||
options = JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText(_ConfigFile));
|
||||
}
|
||||
|
||||
if (options == null)
|
||||
{
|
||||
options = new FFMpegOptions
|
||||
{
|
||||
RootDirectory = _DefaultRoot
|
||||
};
|
||||
}
|
||||
|
||||
ConfiguredRoot = options.RootDirectory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -25,20 +25,15 @@ public class FFMpeg : FFBase
|
|||
/// <summary>
|
||||
/// Intializes the FFMPEG encoder.
|
||||
/// </summary>
|
||||
public FFMpeg(FFMpegOptions opts = null): base(opts)
|
||||
public FFMpeg(): base()
|
||||
{
|
||||
_Init();
|
||||
ArgumentBuilder = new FFArgumentBuilder();
|
||||
}
|
||||
|
||||
private void _Init()
|
||||
{
|
||||
FFMpegHelper.RootExceptionCheck(ConfiguredRoot);
|
||||
FFProbeHelper.RootExceptionCheck(ConfiguredRoot);
|
||||
FFMpegHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
||||
|
||||
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
||||
|
||||
_ffmpegPath = ConfiguredRoot + $"\\{target}\\ffmpeg.exe";
|
||||
_ffmpegPath = $"{FFMpegOptions.Options.RootDirectory}\\{target}\\ffmpeg.exe";
|
||||
|
||||
ArgumentBuilder = new FFArgumentBuilder();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,7 +1,28 @@
|
|||
namespace FFMpegCore.FFMPEG
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
|
||||
namespace FFMpegCore.FFMPEG
|
||||
{
|
||||
public class FFMpegOptions
|
||||
{
|
||||
public string RootDirectory { get; set; }
|
||||
private static string _ConfigFile = ".\\ffmpeg.config.json";
|
||||
private static string _DefaultRoot = ".\\FFMPEG\\bin";
|
||||
|
||||
public static FFMpegOptions Options { get; private set; } = new FFMpegOptions();
|
||||
|
||||
public static void Configure(FFMpegOptions options)
|
||||
{
|
||||
Options = options;
|
||||
}
|
||||
|
||||
static FFMpegOptions()
|
||||
{
|
||||
if (File.Exists(_ConfigFile))
|
||||
{
|
||||
Options = JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText(_ConfigFile));
|
||||
}
|
||||
}
|
||||
|
||||
public string RootDirectory { get; set; } = _DefaultRoot;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace FFMpegCore.FFMPEG
|
||||
{
|
||||
public sealed class FFProbe : FFBase
|
||||
{
|
||||
public FFProbe(FFMpegOptions opts = null): base(opts)
|
||||
public FFProbe(): base()
|
||||
{
|
||||
FFProbeHelper.RootExceptionCheck(ConfiguredRoot);
|
||||
FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
||||
|
||||
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
||||
|
||||
_ffprobePath = ConfiguredRoot + $"\\{target}\\ffprobe.exe";
|
||||
_ffprobePath = $"{FFMpegOptions.Options.RootDirectory}\\{target}\\ffprobe.exe";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
<PackageProjectUrl>https://github.com/vladjerca/FFMpegCore</PackageProjectUrl>
|
||||
<Copyright>Vlad Jerca</Copyright>
|
||||
<Description>A great way to use FFMpeg encoding when writing video applications, client-side and server-side. It has wrapper methods that allow conversion to all web formats: MP4, OGV, TS and methods of capturing screens from the videos.</Description>
|
||||
<Version>1.0.4</Version>
|
||||
<AssemblyVersion>1.0.4.0</AssemblyVersion>
|
||||
<FileVersion>1.0.4.0</FileVersion>
|
||||
<Version>1.0.5</Version>
|
||||
<AssemblyVersion>1.0.5.0</AssemblyVersion>
|
||||
<FileVersion>1.0.5.0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
18
README.md
18
README.md
|
@ -12,7 +12,23 @@ Install-Package FFMpegCore
|
|||
|
||||
A great way to use FFMpeg encoding when writing video applications, client-side and server-side. It has wrapper methods that allow conversion to all web formats: MP4, OGV, TS and methods of capturing screens from the videos.
|
||||
|
||||
### Configuratoin
|
||||
### Configuration
|
||||
|
||||
By default the `RootDirectory` is set to `"\\FFMPEG\\bin"`.
|
||||
|
||||
|
||||
#### Option 1
|
||||
|
||||
The default value can be overwritten via the `FFMpegOptions` class:
|
||||
|
||||
```c#
|
||||
public Startup()
|
||||
{
|
||||
FFMpegOptions.Configure(new FFMpegOptions { RootDirectory = "\\My_Binary\\Path" });
|
||||
}
|
||||
```
|
||||
|
||||
#### Option 2
|
||||
|
||||
The root directory for the ffmpeg binaries can be configured via the `ffmpeg.config.json` file.
|
||||
|
||||
|
|
Loading…
Reference in a new issue