mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
d7a705e9ae
commit
5e1aef9adc
5 changed files with 25 additions and 19 deletions
|
@ -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<FFMpegOptions>(File.ReadAllText($".{Path.DirectorySeparatorChar}ffmpeg.config.json")).RootDirectory
|
||||
JsonConvert.DeserializeObject<FFMpegOptions>(File.ReadAllText("ffmpeg.config.json")).RootDirectory
|
||||
);
|
||||
}
|
||||
|
|
@ -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<string, string> DefaultExtensionsOverrides = new Dictionary<string, string>
|
||||
{
|
||||
{ "mpegts", ".ts" },
|
||||
|
@ -33,8 +33,8 @@ static FFMpegOptions()
|
|||
if (File.Exists(ConfigFile))
|
||||
{
|
||||
Options = JsonSerializer.Deserialize<FFMpegOptions>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ namespace FFMpegCore
|
|||
public class FFProbeAnalysis
|
||||
{
|
||||
[JsonPropertyName("streams")]
|
||||
public List<Stream> Streams { get; set; } = null!;
|
||||
public List<FFProbeStream> 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!;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ internal MediaAnalysis(string path, FFProbeAnalysis analysis)
|
|||
public List<VideoStream> VideoStreams { get; }
|
||||
public List<AudioStream> 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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue