Change default paths

Former-commit-id: 708189b837
This commit is contained in:
Malte Rosenbjerg 2020-05-12 21:37:10 +02:00
parent d7a705e9ae
commit 5e1aef9adc
5 changed files with 25 additions and 19 deletions

View file

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

View file

@ -8,9 +8,9 @@ namespace FFMpegCore
{ {
public class FFMpegOptions public class FFMpegOptions
{ {
private static readonly string ConfigFile = Path.Combine(".", "ffmpeg.config.json"); private static readonly string ConfigFile = "ffmpeg.config.json";
private static readonly string DefaultRoot = Path.Combine(".", "FFMPEG", "bin"); private static readonly string DefaultRoot = "";
private static readonly string DefaultTemp = Path.Combine(Path.GetTempPath(), "FFMpegCore"); private static readonly string DefaultTemp = Path.GetTempPath();
private static readonly Dictionary<string, string> DefaultExtensionsOverrides = new Dictionary<string, string> private static readonly Dictionary<string, string> DefaultExtensionsOverrides = new Dictionary<string, string>
{ {
{ "mpegts", ".ts" }, { "mpegts", ".ts" },
@ -33,8 +33,8 @@ static FFMpegOptions()
if (File.Exists(ConfigFile)) if (File.Exists(ConfigFile))
{ {
Options = JsonSerializer.Deserialize<FFMpegOptions>(File.ReadAllText(ConfigFile)); Options = JsonSerializer.Deserialize<FFMpegOptions>(File.ReadAllText(ConfigFile));
foreach (var kv in DefaultExtensionsOverrides) foreach (var (key, value) in DefaultExtensionsOverrides)
if (!Options.ExtensionOverrides.ContainsKey(kv.Key)) Options.ExtensionOverrides.Add(kv.Key, kv.Value); if (!Options.ExtensionOverrides.ContainsKey(key)) Options.ExtensionOverrides.Add(key, value);
} }
} }

View file

@ -6,10 +6,10 @@ namespace FFMpegCore
public class FFProbeAnalysis public class FFProbeAnalysis
{ {
[JsonPropertyName("streams")] [JsonPropertyName("streams")]
public List<Stream> Streams { get; set; } = null!; public List<FFProbeStream> Streams { get; set; } = null!;
} }
public class Stream public class FFProbeStream
{ {
[JsonPropertyName("index")] [JsonPropertyName("index")]
public int Index { get; set; } public int Index { get; set; }
@ -70,5 +70,8 @@ public class Tags
{ {
[JsonPropertyName("DURATION")] [JsonPropertyName("DURATION")]
public string Duration { get; set; } = null!; public string Duration { get; set; } = null!;
[JsonPropertyName("language")]
public string Language { get; set; } = null!;
} }
} }

View file

@ -29,7 +29,7 @@ internal MediaAnalysis(string path, FFProbeAnalysis analysis)
public List<VideoStream> VideoStreams { get; } public List<VideoStream> VideoStreams { get; }
public List<AudioStream> AudioStreams { get; } public List<AudioStream> AudioStreams { get; }
private VideoStream ParseVideoStream(Stream stream) private VideoStream ParseVideoStream(FFProbeStream stream)
{ {
return new VideoStream return new VideoStream
{ {
@ -42,21 +42,22 @@ private VideoStream ParseVideoStream(Stream stream)
DisplayAspectRatio = ParseRatioInt(stream.DisplayAspectRatio, ':'), DisplayAspectRatio = ParseRatioInt(stream.DisplayAspectRatio, ':'),
Duration = ParseDuration(stream), Duration = ParseDuration(stream),
FrameRate = DivideRatio(ParseRatioDouble(stream.FrameRate, '/')), FrameRate = DivideRatio(ParseRatioDouble(stream.FrameRate, '/')),
Height = stream.Height!.Value, Height = stream.Height ?? 0,
Width = stream.Width!.Value, Width = stream.Width ?? 0,
Profile = stream.Profile, Profile = stream.Profile,
PixelFormat = stream.PixelFormat PixelFormat = stream.PixelFormat,
Language = stream.Tags?.Language
}; };
} }
private static TimeSpan ParseDuration(Stream stream) private static TimeSpan ParseDuration(FFProbeStream ffProbeStream)
{ {
return stream.Duration != null return ffProbeStream.Duration != null
? TimeSpan.FromSeconds(ParseDoubleInvariant(stream.Duration)) ? TimeSpan.FromSeconds(ParseDoubleInvariant(ffProbeStream.Duration))
: TimeSpan.Parse(stream.Tags.Duration ?? "0"); : TimeSpan.Parse(ffProbeStream.Tags?.Duration ?? "0");
} }
private AudioStream ParseAudioStream(Stream stream) private AudioStream ParseAudioStream(FFProbeStream stream)
{ {
return new AudioStream return new AudioStream
{ {
@ -67,7 +68,8 @@ private AudioStream ParseAudioStream(Stream stream)
Channels = stream.Channels ?? default, Channels = stream.Channels ?? default,
ChannelLayout = stream.ChannelLayout, ChannelLayout = stream.ChannelLayout,
Duration = TimeSpan.FromSeconds(ParseDoubleInvariant(stream.Duration ?? stream.Tags.Duration ?? "0")), Duration = TimeSpan.FromSeconds(ParseDoubleInvariant(stream.Duration ?? stream.Tags.Duration ?? "0")),
SampleRateHz = !string.IsNullOrEmpty(stream.SampleRate) ? ParseIntInvariant(stream.SampleRate) : default SampleRateHz = !string.IsNullOrEmpty(stream.SampleRate) ? ParseIntInvariant(stream.SampleRate) : default,
Language = stream.Tags?.Language
}; };
} }

View file

@ -10,6 +10,7 @@ public class MediaStream
public string CodecLongName { get; internal set; } = null!; public string CodecLongName { get; internal set; } = null!;
public int BitRate { get; internal set; } public int BitRate { get; internal set; }
public TimeSpan Duration { get; internal set; } public TimeSpan Duration { get; internal set; }
public string? Language { get; internal set; }
public Codec GetCodecInfo() => FFMpeg.GetCodec(CodecName); public Codec GetCodecInfo() => FFMpeg.GetCodec(CodecName);
} }