mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
FFMpegCore: use Path.DirectorySeparatorChar instead of \\, for non windows based platform dont use target, for non windows based platform dont use .exe
This commit is contained in:
parent
c3206e218d
commit
61d455b831
10 changed files with 60 additions and 31 deletions
|
@ -17,7 +17,7 @@ public void Options_Initialized()
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Options_Defaults_Configured()
|
public void Options_Defaults_Configured()
|
||||||
{
|
{
|
||||||
Assert.AreEqual(new FFMpegOptions().RootDirectory, ".\\FFMPEG\\bin");
|
Assert.AreEqual(new FFMpegOptions().RootDirectory, $".{Path.DirectorySeparatorChar}FFMPEG{Path.DirectorySeparatorChar}bin");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
@ -25,7 +25,7 @@ public void Options_Loaded_From_File()
|
||||||
{
|
{
|
||||||
Assert.AreEqual(
|
Assert.AreEqual(
|
||||||
FFMpegOptions.Options.RootDirectory,
|
FFMpegOptions.Options.RootDirectory,
|
||||||
JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText(".\\ffmpeg.config.json")).RootDirectory
|
JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText($".{Path.DirectorySeparatorChar}ffmpeg.config.json")).RootDirectory
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,13 @@ public enum ImageType
|
||||||
|
|
||||||
public static class VideoLibrary
|
public static class VideoLibrary
|
||||||
{
|
{
|
||||||
public static readonly FileInfo LocalVideo = new FileInfo(".\\Resources\\input.mp4");
|
public static readonly FileInfo LocalVideo = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}input.mp4");
|
||||||
public static readonly FileInfo LocalVideoAudioOnly = new FileInfo(".\\Resources\\audio_only.mp4");
|
public static readonly FileInfo LocalVideoAudioOnly = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}audio_only.mp4");
|
||||||
public static readonly FileInfo LocalVideoNoAudio = new FileInfo(".\\Resources\\mute.mp4");
|
public static readonly FileInfo LocalVideoNoAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}mute.mp4");
|
||||||
public static readonly FileInfo LocalAudio = new FileInfo(".\\Resources\\audio.mp3");
|
public static readonly FileInfo LocalAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}audio.mp3");
|
||||||
public static readonly FileInfo LocalCover = new FileInfo(".\\Resources\\cover.png");
|
public static readonly FileInfo LocalCover = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}cover.png");
|
||||||
public static readonly FileInfo ImageDirectory = new FileInfo(".\\Resources\\images");
|
public static readonly FileInfo ImageDirectory = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}images");
|
||||||
public static readonly FileInfo ImageJoinOutput = new FileInfo(".\\Resources\\images\\output.mp4");
|
public static readonly FileInfo ImageJoinOutput = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}output.mp4");
|
||||||
|
|
||||||
public static FileInfo OutputLocation(this FileInfo file, VideoType type)
|
public static FileInfo OutputLocation(this FileInfo file, VideoType type)
|
||||||
{
|
{
|
||||||
|
@ -44,7 +44,7 @@ public static FileInfo OutputLocation(this FileInfo file, Enum type, string keyw
|
||||||
string originalLocation = file.Directory.FullName,
|
string originalLocation = file.Directory.FullName,
|
||||||
outputFile = file.Name.Replace(file.Extension, keyword + "." + type.ToString().ToLower());
|
outputFile = file.Name.Replace(file.Extension, keyword + "." + type.ToString().ToLower());
|
||||||
|
|
||||||
return new FileInfo($"{originalLocation}\\{outputFile}");
|
return new FileInfo($"{originalLocation}{Path.DirectorySeparatorChar}{outputFile}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
@ -29,9 +30,16 @@ public FFMpeg(): base()
|
||||||
{
|
{
|
||||||
FFMpegHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
FFMpegHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
||||||
|
|
||||||
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
var progName = "ffmpeg";
|
||||||
|
if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
|
||||||
|
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
||||||
|
|
||||||
_ffmpegPath = $"{FFMpegOptions.Options.RootDirectory}\\{target}\\ffmpeg.exe";
|
progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe";
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = $"{Path.DirectorySeparatorChar}{progName}";
|
||||||
|
|
||||||
|
_ffmpegPath = $"{FFMpegOptions.Options.RootDirectory}{path}";
|
||||||
|
|
||||||
ArgumentBuilder = new FFArgumentBuilder();
|
ArgumentBuilder = new FFArgumentBuilder();
|
||||||
}
|
}
|
||||||
|
@ -302,7 +310,7 @@ public VideoInfo JoinImageSequence(FileInfo output, double frameRate = 30, param
|
||||||
new FrameRateArgument(frameRate),
|
new FrameRateArgument(frameRate),
|
||||||
new SizeArgument(firstImage.Width, firstImage.Height),
|
new SizeArgument(firstImage.Width, firstImage.Height),
|
||||||
new StartNumberArgument(0),
|
new StartNumberArgument(0),
|
||||||
new InputArgument($"{firstImage.Directory}\\%09d.png"),
|
new InputArgument($"{firstImage.Directory}{Path.DirectorySeparatorChar}%09d.png"),
|
||||||
new FrameOutputCountArgument(images.Length),
|
new FrameOutputCountArgument(images.Length),
|
||||||
new VideoCodecArgument(VideoCodec.LibX264),
|
new VideoCodecArgument(VideoCodec.LibX264),
|
||||||
new OutputArgument(output)
|
new OutputArgument(output)
|
||||||
|
@ -539,4 +547,4 @@ private void OutputData(object sender, DataReceivedEventArgs e)
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ namespace FFMpegCore.FFMPEG
|
||||||
{
|
{
|
||||||
public class FFMpegOptions
|
public class FFMpegOptions
|
||||||
{
|
{
|
||||||
private static string _ConfigFile = ".\\ffmpeg.config.json";
|
private static string _ConfigFile = $".{Path.DirectorySeparatorChar}ffmpeg.config.json";
|
||||||
private static string _DefaultRoot = ".\\FFMPEG\\bin";
|
private static string _DefaultRoot = $".{Path.DirectorySeparatorChar}FFMPEG{Path.DirectorySeparatorChar}bin";
|
||||||
|
|
||||||
public static FFMpegOptions Options { get; private set; } = new FFMpegOptions();
|
public static FFMpegOptions Options { get; private set; } = new FFMpegOptions();
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace FFMpegCore.FFMPEG
|
namespace FFMpegCore.FFMPEG
|
||||||
{
|
{
|
||||||
|
@ -14,9 +16,16 @@ public FFProbe(): base()
|
||||||
{
|
{
|
||||||
FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
|
||||||
|
|
||||||
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
var progName = "ffprobe";
|
||||||
|
if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
|
||||||
|
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
||||||
|
|
||||||
_ffprobePath = $"{FFMpegOptions.Options.RootDirectory}\\{target}\\ffprobe.exe";
|
progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe";
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = $"{Path.DirectorySeparatorChar}{progName}";
|
||||||
|
|
||||||
|
_ffprobePath = $"{FFMpegOptions.Options.RootDirectory}{path}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -122,4 +131,4 @@ private string RunProcess(string args)
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
|
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using FFMpegCore.FFMPEG.Exceptions;
|
using FFMpegCore.FFMPEG.Exceptions;
|
||||||
|
|
||||||
namespace FFMpegCore.Helpers
|
namespace FFMpegCore.Helpers
|
||||||
|
@ -73,13 +74,18 @@ public static void RootExceptionCheck(string root)
|
||||||
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
||||||
"FFMpeg root is not configured in app config. Missing key 'ffmpegRoot'.");
|
"FFMpeg root is not configured in app config. Missing key 'ffmpegRoot'.");
|
||||||
|
|
||||||
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
var progName = "ffmpeg";
|
||||||
|
if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
|
||||||
|
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
||||||
|
|
||||||
var path = root + $"\\{target}\\ffmpeg.exe";
|
progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe";
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = root + $"{Path.DirectorySeparatorChar}{progName}";
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
||||||
"FFMpeg cannot be found in the root directory!");
|
"FFMpeg cannot be found in the root directory!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using FFMpegCore.FFMPEG.Exceptions;
|
using FFMpegCore.FFMPEG.Exceptions;
|
||||||
|
|
||||||
namespace FFMpegCore.Helpers
|
namespace FFMpegCore.Helpers
|
||||||
|
@ -23,13 +24,18 @@ public static void RootExceptionCheck(string root)
|
||||||
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
||||||
"FFProbe root is not configured in app config. Missing key 'ffmpegRoot'.");
|
"FFProbe root is not configured in app config. Missing key 'ffmpegRoot'.");
|
||||||
|
|
||||||
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
var progName = "ffprobe";
|
||||||
|
if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
|
||||||
|
var target = Environment.Is64BitProcess ? "x64" : "x86";
|
||||||
|
|
||||||
var path = root + $"\\{target}\\ffprobe.exe";
|
progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe";
|
||||||
|
}
|
||||||
|
|
||||||
|
var path = root + $"{Path.DirectorySeparatorChar}{progName}";
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
throw new FFMpegException(FFMpegExceptionType.Dependency,
|
||||||
$"FFProbe cannot be found in the in {path}...");
|
$"FFProbe cannot be found in the in {path}...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,7 @@ public FileStream FileOpen(FileMode mode)
|
||||||
/// <param name="destination"></param>
|
/// <param name="destination"></param>
|
||||||
public void MoveTo(DirectoryInfo destination)
|
public void MoveTo(DirectoryInfo destination)
|
||||||
{
|
{
|
||||||
var newLocation = $"{destination.FullName}\\{Name}{Extension}";
|
var newLocation = $"{destination.FullName}{Path.DirectorySeparatorChar}{Name}{Extension}";
|
||||||
_file.MoveTo(newLocation);
|
_file.MoveTo(newLocation);
|
||||||
_file = new FileInfo(newLocation);
|
_file = new FileInfo(newLocation);
|
||||||
}
|
}
|
||||||
|
@ -180,4 +180,4 @@ public FileInfo ToFileInfo()
|
||||||
return new FileInfo(_file.FullName);
|
return new FileInfo(_file.FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ public FileStream FileOpen(FileMode mode)
|
||||||
/// <param name="destination"></param>
|
/// <param name="destination"></param>
|
||||||
public void MoveTo(DirectoryInfo destination)
|
public void MoveTo(DirectoryInfo destination)
|
||||||
{
|
{
|
||||||
var newLocation = $"{destination.FullName}\\{Name}{Extension}";
|
var newLocation = $"{destination.FullName}{Path.DirectorySeparatorChar}{Name}{Extension}";
|
||||||
_file.MoveTo(newLocation);
|
_file.MoveTo(newLocation);
|
||||||
_file = new FileInfo(newLocation);
|
_file = new FileInfo(newLocation);
|
||||||
}
|
}
|
||||||
|
@ -184,4 +184,4 @@ public FileInfo ToFileInfo()
|
||||||
return new FileInfo(_file.FullName);
|
return new FileInfo(_file.FullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue