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.REMOVED.git-id b/FFMpegCore/FFMPEG/bin/x64/ffmpeg.exe.REMOVED.git-id deleted file mode 100644 index 9961b1b..0000000 --- a/FFMpegCore/FFMPEG/bin/x64/ffmpeg.exe.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -cbeb93b3e549b119eb93ac5d5a120aa71ae8fd0c \ No newline at end of file diff --git a/FFMpegCore/FFMPEG/bin/x64/ffprobe.exe.REMOVED.git-id b/FFMpegCore/FFMPEG/bin/x64/ffprobe.exe.REMOVED.git-id deleted file mode 100644 index 9f55f1d..0000000 --- a/FFMpegCore/FFMPEG/bin/x64/ffprobe.exe.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -adf675e8cc71563575d18d103be11fcf9efd31cd \ No newline at end of file diff --git a/FFMpegCore/FFMPEG/bin/x86/ffmpeg.exe.REMOVED.git-id b/FFMpegCore/FFMPEG/bin/x86/ffmpeg.exe.REMOVED.git-id deleted file mode 100644 index e8e7260..0000000 --- a/FFMpegCore/FFMPEG/bin/x86/ffmpeg.exe.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -958219856504251bf1bb68ff08490fcee2448975 \ No newline at end of file diff --git a/FFMpegCore/FFMPEG/bin/x86/ffprobe.exe.REMOVED.git-id b/FFMpegCore/FFMPEG/bin/x86/ffprobe.exe.REMOVED.git-id deleted file mode 100644 index cf7e824..0000000 --- a/FFMpegCore/FFMPEG/bin/x86/ffprobe.exe.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -5a70926400475c3a0efd0ef30a60a89c49b41f2a \ No newline at end of file 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}..."); + } } } diff --git a/README.md b/README.md index 4faa420..1258071 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![NuGet Badge](https://buildstats.info/nuget/FFMpegCore)](https://www.nuget.org/packages/FFMpegCore/) [![Build Status](https://travis-ci.org/vladjerca/FFMpegCore.svg?branch=master)](https://travis-ci.org/vladjerca/FFMpegCore) -## Setup +# Setup #### NuGet: @@ -13,19 +13,46 @@ 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. -### Configuration +## Binaries -By default the `RootDirectory` is set to `"\\FFMPEG\\bin"`. +If you prefer to manually download them, visit [ffbinaries](https://ffbinaries.com/downloads). +#### Windows + +command: `choco install ffmpeg -Y` + +location: `C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin` + +#### Mac OSX + +command: `brew install ffmpeg mono-libgdiplus` + +location: `/usr/local/bin` + +#### Ubuntu + +command: `sudo apt-get install -y ffmpeg libgdiplus` + +location: `/usr/bin` + +## Path Configuration + +#### Behavior + +If you are building a client app, and you don't know the processor achitecture. + +By creating a folder `x64` and `x86` in the `root` directory, the lib will automatically try to use either `/root/{ARCH}/(ffmpeg|ffprobe).exe`. + +If these folders are not defined, it will try to find the binaries in `/root/(ffmpeg|ffprobe.exe)` #### Option 1 -The default value can be overwritten via the `FFMpegOptions` class: +The default value (`\\FFMPEG\\bin`) can be overwritten via the `FFMpegOptions` class: ```c# public Startup() { - FFMpegOptions.Configure(new FFMpegOptions { RootDirectory = "\\My_Binary\\Path" }); + FFMpegOptions.Configure(new FFMpegOptions { RootDirectory = "./bin" }); } ``` @@ -35,23 +62,16 @@ The root directory for the ffmpeg binaries can be configured via the `ffmpeg.con ```json { - "RootDirectory": ".//FFMPEG//bin" + "RootDirectory": "./bin" } ``` -The files that need to be included can be found here: https://github.com/vladjerca/FFMpegCore/tree/master/FFMpegCore/FFMPEG/bin +# Compatibility + Some versions of FFMPEG might not have the same argument schema. The lib has been tested with version `3.3` to `4.1` -I can only guarantee an expected behaviour built binaries included, other 3rd party builds could contain API changes rendering an unexpected behaviour. + # API -MacOSX -The Unit test have run on MacOSX - 10.14.4 using ffmpeg version 4.1.3. (It was installed using "brew install ffmpeg" and "brew install mono-libgdiplus"). The RootDirectory was set to "/usr/local/bin" for running unit test. - -Ubuntu 16.04 -The unit test failed on 2 test when running against default ffmpeg package of (ffmpeg version 2.8.15-0ubuntu0.16.04.1) - The two test that failed were Video_ToMP4_Args and Video_ToMP4_Resize_Args -The Unit test passed when running against ffmpeg version 4.1.3 - -### FFProbe +## FFProbe FFProbe is used to gather video information ```csharp @@ -83,7 +103,7 @@ Resolution : 1280x720 Size : 2.88 Mb ``` -### FFMpeg +## FFMpeg Convert your video files to web ready formats: ```csharp