diff --git a/FFMpegCore.Test/FFMpegOptions.cs b/FFMpegCore.Test/FFMpegOptionsTests.cs similarity index 88% rename from FFMpegCore.Test/FFMpegOptions.cs rename to FFMpegCore.Test/FFMpegOptionsTests.cs index b7359a4..ba124c3 100644 --- a/FFMpegCore.Test/FFMpegOptions.cs +++ b/FFMpegCore.Test/FFMpegOptionsTests.cs @@ -16,7 +16,7 @@ public void Options_Initialized() [TestMethod] public void Options_Defaults_Configured() { - Assert.AreEqual(new FFMpegOptions().RootDirectory, $".{Path.DirectorySeparatorChar}FFMPEG{Path.DirectorySeparatorChar}bin"); + Assert.AreEqual(new FFMpegOptions().RootDirectory, $""); } [TestMethod] @@ -24,7 +24,7 @@ public void Options_Loaded_From_File() { Assert.AreEqual( FFMpegOptions.Options.RootDirectory, - JsonConvert.DeserializeObject(File.ReadAllText($".{Path.DirectorySeparatorChar}ffmpeg.config.json")).RootDirectory + JsonConvert.DeserializeObject(File.ReadAllText("ffmpeg.config.json")).RootDirectory ); } diff --git a/FFMpegCore/FFMpeg/FFMpegOptions.cs b/FFMpegCore/FFMpeg/FFMpegOptions.cs index f15e79c..426b844 100644 --- a/FFMpegCore/FFMpeg/FFMpegOptions.cs +++ b/FFMpegCore/FFMpeg/FFMpegOptions.cs @@ -8,9 +8,9 @@ namespace FFMpegCore { public class FFMpegOptions { - private static readonly string ConfigFile = Path.Combine(".", "ffmpeg.config.json"); - private static readonly string DefaultRoot = Path.Combine(".", "FFMPEG", "bin"); - private static readonly string DefaultTemp = Path.Combine(Path.GetTempPath(), "FFMpegCore"); + private static readonly string ConfigFile = "ffmpeg.config.json"; + private static readonly string DefaultRoot = ""; + private static readonly string DefaultTemp = Path.GetTempPath(); private static readonly Dictionary DefaultExtensionsOverrides = new Dictionary { { "mpegts", ".ts" }, @@ -33,8 +33,8 @@ static FFMpegOptions() if (File.Exists(ConfigFile)) { Options = JsonSerializer.Deserialize(File.ReadAllText(ConfigFile)); - foreach (var kv in DefaultExtensionsOverrides) - if (!Options.ExtensionOverrides.ContainsKey(kv.Key)) Options.ExtensionOverrides.Add(kv.Key, kv.Value); + foreach (var (key, value) in DefaultExtensionsOverrides) + if (!Options.ExtensionOverrides.ContainsKey(key)) Options.ExtensionOverrides.Add(key, value); } } diff --git a/FFMpegCore/FFProbe/FFProbeAnalysis.cs b/FFMpegCore/FFProbe/FFProbeAnalysis.cs index 2a82528..c647437 100644 --- a/FFMpegCore/FFProbe/FFProbeAnalysis.cs +++ b/FFMpegCore/FFProbe/FFProbeAnalysis.cs @@ -6,10 +6,10 @@ namespace FFMpegCore public class FFProbeAnalysis { [JsonPropertyName("streams")] - public List Streams { get; set; } = null!; + public List Streams { get; set; } = null!; } - public class Stream + public class FFProbeStream { [JsonPropertyName("index")] public int Index { get; set; } @@ -70,5 +70,8 @@ public class Tags { [JsonPropertyName("DURATION")] public string Duration { get; set; } = null!; + + [JsonPropertyName("language")] + public string Language { get; set; } = null!; } } diff --git a/FFMpegCore/FFProbe/MediaAnalysis.cs b/FFMpegCore/FFProbe/MediaAnalysis.cs index 4b638b2..68f175b 100644 --- a/FFMpegCore/FFProbe/MediaAnalysis.cs +++ b/FFMpegCore/FFProbe/MediaAnalysis.cs @@ -29,7 +29,7 @@ internal MediaAnalysis(string path, FFProbeAnalysis analysis) public List VideoStreams { get; } public List AudioStreams { get; } - private VideoStream ParseVideoStream(Stream stream) + private VideoStream ParseVideoStream(FFProbeStream stream) { return new VideoStream { @@ -42,21 +42,22 @@ private VideoStream ParseVideoStream(Stream stream) DisplayAspectRatio = ParseRatioInt(stream.DisplayAspectRatio, ':'), Duration = ParseDuration(stream), FrameRate = DivideRatio(ParseRatioDouble(stream.FrameRate, '/')), - Height = stream.Height!.Value, - Width = stream.Width!.Value, + Height = stream.Height ?? 0, + Width = stream.Width ?? 0, 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 - ? TimeSpan.FromSeconds(ParseDoubleInvariant(stream.Duration)) - : TimeSpan.Parse(stream.Tags.Duration ?? "0"); + return ffProbeStream.Duration != null + ? TimeSpan.FromSeconds(ParseDoubleInvariant(ffProbeStream.Duration)) + : TimeSpan.Parse(ffProbeStream.Tags?.Duration ?? "0"); } - private AudioStream ParseAudioStream(Stream stream) + private AudioStream ParseAudioStream(FFProbeStream stream) { return new AudioStream { @@ -67,7 +68,8 @@ private AudioStream ParseAudioStream(Stream stream) Channels = stream.Channels ?? default, ChannelLayout = stream.ChannelLayout, 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 }; } diff --git a/FFMpegCore/FFProbe/MediaStream.cs b/FFMpegCore/FFProbe/MediaStream.cs index 8532e51..61d548f 100644 --- a/FFMpegCore/FFProbe/MediaStream.cs +++ b/FFMpegCore/FFProbe/MediaStream.cs @@ -10,6 +10,7 @@ public class MediaStream public string CodecLongName { get; internal set; } = null!; public int BitRate { get; internal set; } public TimeSpan Duration { get; internal set; } + public string? Language { get; internal set; } public Codec GetCodecInfo() => FFMpeg.GetCodec(CodecName); }