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:
Joshua Hatzenbuehler 2019-05-02 10:11:00 -05:00
parent c3206e218d
commit 61d455b831
10 changed files with 60 additions and 31 deletions

View file

@ -17,7 +17,7 @@ public void Options_Initialized()
[TestMethod]
public void Options_Defaults_Configured()
{
Assert.AreEqual(new FFMpegOptions().RootDirectory, ".\\FFMPEG\\bin");
Assert.AreEqual(new FFMpegOptions().RootDirectory, $".{Path.DirectorySeparatorChar}FFMPEG{Path.DirectorySeparatorChar}bin");
}
[TestMethod]
@ -25,7 +25,7 @@ public void Options_Loaded_From_File()
{
Assert.AreEqual(
FFMpegOptions.Options.RootDirectory,
JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText(".\\ffmpeg.config.json")).RootDirectory
JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText($".{Path.DirectorySeparatorChar}ffmpeg.config.json")).RootDirectory
);
}

View file

@ -16,13 +16,13 @@ public enum ImageType
public static class VideoLibrary
{
public static readonly FileInfo LocalVideo = new FileInfo(".\\Resources\\input.mp4");
public static readonly FileInfo LocalVideoAudioOnly = new FileInfo(".\\Resources\\audio_only.mp4");
public static readonly FileInfo LocalVideoNoAudio = new FileInfo(".\\Resources\\mute.mp4");
public static readonly FileInfo LocalAudio = new FileInfo(".\\Resources\\audio.mp3");
public static readonly FileInfo LocalCover = new FileInfo(".\\Resources\\cover.png");
public static readonly FileInfo ImageDirectory = new FileInfo(".\\Resources\\images");
public static readonly FileInfo ImageJoinOutput = new FileInfo(".\\Resources\\images\\output.mp4");
public static readonly FileInfo LocalVideo = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}input.mp4");
public static readonly FileInfo LocalVideoAudioOnly = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}audio_only.mp4");
public static readonly FileInfo LocalVideoNoAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}mute.mp4");
public static readonly FileInfo LocalAudio = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}audio.mp3");
public static readonly FileInfo LocalCover = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}cover.png");
public static readonly FileInfo ImageDirectory = new FileInfo($".{Path.DirectorySeparatorChar}Resources{Path.DirectorySeparatorChar}images");
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)
{
@ -44,7 +44,7 @@ public static FileInfo OutputLocation(this FileInfo file, Enum type, string keyw
string originalLocation = file.Directory.FullName,
outputFile = file.Name.Replace(file.Extension, keyword + "." + type.ToString().ToLower());
return new FileInfo($"{originalLocation}\\{outputFile}");
return new FileInfo($"{originalLocation}{Path.DirectorySeparatorChar}{outputFile}");
}
}
}

View file

@ -11,6 +11,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
@ -29,9 +30,16 @@ public FFMpeg(): base()
{
FFMpegHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
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();
}
@ -302,7 +310,7 @@ public VideoInfo JoinImageSequence(FileInfo output, double frameRate = 30, param
new FrameRateArgument(frameRate),
new SizeArgument(firstImage.Width, firstImage.Height),
new StartNumberArgument(0),
new InputArgument($"{firstImage.Directory}\\%09d.png"),
new InputArgument($"{firstImage.Directory}{Path.DirectorySeparatorChar}%09d.png"),
new FrameOutputCountArgument(images.Length),
new VideoCodecArgument(VideoCodec.LibX264),
new OutputArgument(output)

View file

@ -5,8 +5,8 @@ namespace FFMpegCore.FFMPEG
{
public class FFMpegOptions
{
private static string _ConfigFile = ".\\ffmpeg.config.json";
private static string _DefaultRoot = ".\\FFMPEG\\bin";
private static string _ConfigFile = $".{Path.DirectorySeparatorChar}ffmpeg.config.json";
private static string _DefaultRoot = $".{Path.DirectorySeparatorChar}FFMPEG{Path.DirectorySeparatorChar}bin";
public static FFMpegOptions Options { get; private set; } = new FFMpegOptions();

View file

@ -3,6 +3,8 @@
using Newtonsoft.Json;
using System;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
namespace FFMpegCore.FFMPEG
{
@ -14,9 +16,16 @@ public FFProbe(): base()
{
FFProbeHelper.RootExceptionCheck(FFMpegOptions.Options.RootDirectory);
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>

View file

@ -140,7 +140,7 @@
<ItemGroup>
<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" />
</ItemGroup>

View file

@ -1,6 +1,7 @@
using System;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using FFMpegCore.FFMPEG.Exceptions;
namespace FFMpegCore.Helpers
@ -73,9 +74,14 @@ public static void RootExceptionCheck(string root)
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";
var path = root + $"\\{target}\\ffmpeg.exe";
progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe";
}
var path = root + $"{Path.DirectorySeparatorChar}{progName}";
if (!File.Exists(path))
throw new FFMpegException(FFMpegExceptionType.Dependency,

View file

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using FFMpegCore.FFMPEG.Exceptions;
namespace FFMpegCore.Helpers
@ -23,9 +24,14 @@ public static void RootExceptionCheck(string root)
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";
var path = root + $"\\{target}\\ffprobe.exe";
progName = $"{target}{Path.DirectorySeparatorChar}{progName}.exe";
}
var path = root + $"{Path.DirectorySeparatorChar}{progName}";
if (!File.Exists(path))
throw new FFMpegException(FFMpegExceptionType.Dependency,

View file

@ -158,7 +158,7 @@ public FileStream FileOpen(FileMode mode)
/// <param name="destination"></param>
public void MoveTo(DirectoryInfo destination)
{
var newLocation = $"{destination.FullName}\\{Name}{Extension}";
var newLocation = $"{destination.FullName}{Path.DirectorySeparatorChar}{Name}{Extension}";
_file.MoveTo(newLocation);
_file = new FileInfo(newLocation);
}

View file

@ -162,7 +162,7 @@ public FileStream FileOpen(FileMode mode)
/// <param name="destination"></param>
public void MoveTo(DirectoryInfo destination)
{
var newLocation = $"{destination.FullName}\\{Name}{Extension}";
var newLocation = $"{destination.FullName}{Path.DirectorySeparatorChar}{Name}{Extension}";
_file.MoveTo(newLocation);
_file = new FileInfo(newLocation);
}