mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Merge branch 'master' of https://github.com/rosenbjerg/FFMpegCore
This commit is contained in:
commit
c41b124588
3 changed files with 34 additions and 6 deletions
|
@ -260,7 +260,11 @@ public void Video_Join()
|
||||||
var result = Encoder.Join(output, input, input2);
|
var result = Encoder.Join(output, input, input2);
|
||||||
|
|
||||||
Assert.IsTrue(File.Exists(output.FullName));
|
Assert.IsTrue(File.Exists(output.FullName));
|
||||||
Assert.AreEqual(input.Duration.TotalSeconds * 2, result.Duration.TotalSeconds);
|
TimeSpan expectedDuration = input.Duration * 2;
|
||||||
|
Assert.AreEqual(expectedDuration.Days, result.Duration.Days);
|
||||||
|
Assert.AreEqual(expectedDuration.Hours, result.Duration.Hours);
|
||||||
|
Assert.AreEqual(expectedDuration.Minutes, result.Duration.Minutes);
|
||||||
|
Assert.AreEqual(expectedDuration.Seconds, result.Duration.Seconds);
|
||||||
Assert.AreEqual(input.Height, result.Height);
|
Assert.AreEqual(input.Height, result.Height);
|
||||||
Assert.AreEqual(input.Width, result.Width);
|
Assert.AreEqual(input.Width, result.Width);
|
||||||
}
|
}
|
||||||
|
@ -319,7 +323,7 @@ public void Video_With_Only_Audio_Should_Extract_Metadata()
|
||||||
Assert.AreEqual(79.5, video.Duration.TotalSeconds, 0.5);
|
Assert.AreEqual(79.5, video.Duration.TotalSeconds, 0.5);
|
||||||
Assert.AreEqual(1.25, video.Size);
|
Assert.AreEqual(1.25, video.Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Video_Duration() {
|
public void Video_Duration() {
|
||||||
var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo);
|
var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo);
|
||||||
|
@ -335,7 +339,11 @@ public void Video_Duration() {
|
||||||
|
|
||||||
Assert.IsTrue(File.Exists(output.FullName));
|
Assert.IsTrue(File.Exists(output.FullName));
|
||||||
var outputVideo = new VideoInfo(output.FullName);
|
var outputVideo = new VideoInfo(output.FullName);
|
||||||
Assert.AreEqual(video.Duration.TotalSeconds - 5, outputVideo.Duration.TotalSeconds);
|
|
||||||
|
Assert.AreEqual(video.Duration.Days, outputVideo.Duration.Days);
|
||||||
|
Assert.AreEqual(video.Duration.Hours, outputVideo.Duration.Hours);
|
||||||
|
Assert.AreEqual(video.Duration.Minutes, outputVideo.Duration.Minutes);
|
||||||
|
Assert.AreEqual(video.Duration.Seconds - 5, outputVideo.Duration.Seconds);
|
||||||
} finally {
|
} finally {
|
||||||
if (File.Exists(output.FullName))
|
if (File.Exists(output.FullName))
|
||||||
output.Delete();
|
output.Delete();
|
||||||
|
|
|
@ -31,6 +31,15 @@ internal class Stream
|
||||||
|
|
||||||
[JsonProperty("r_frame_rate")]
|
[JsonProperty("r_frame_rate")]
|
||||||
internal string FrameRate { get; set; }
|
internal string FrameRate { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("tags")]
|
||||||
|
internal Tags Tags { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class Tags
|
||||||
|
{
|
||||||
|
[JsonProperty("DURATION")]
|
||||||
|
internal string Duration { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class FFMpegStreamMetadata
|
internal class FFMpegStreamMetadata
|
||||||
|
|
|
@ -81,9 +81,20 @@ private VideoInfo ParseVideoInfoInternal(VideoInfo info, string probeOutput)
|
||||||
double videoSize = 0d;
|
double videoSize = 0d;
|
||||||
double audioSize = 0d;
|
double audioSize = 0d;
|
||||||
|
|
||||||
var duration = TimeSpan.FromSeconds(double.TryParse((video ?? audio).Duration, NumberStyles.Any, CultureInfo.InvariantCulture, out var output) ? output : 0);
|
string sDuration = (video ?? audio).Duration;
|
||||||
info.Duration = duration.Subtract(TimeSpan.FromMilliseconds(duration.Milliseconds));
|
TimeSpan duration = TimeSpan.Zero;
|
||||||
|
if (sDuration != null)
|
||||||
|
{
|
||||||
|
duration = TimeSpan.FromSeconds(double.TryParse(sDuration, NumberStyles.Any, CultureInfo.InvariantCulture, out var output) ? output : 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sDuration = (video ?? audio).Tags.Duration;
|
||||||
|
if (sDuration != null)
|
||||||
|
TimeSpan.TryParse(sDuration.Remove(sDuration.LastIndexOf('.') + 8), CultureInfo.InvariantCulture, out duration); // TimeSpan fractions only allow up to 7 digits
|
||||||
|
}
|
||||||
|
info.Duration = duration;
|
||||||
|
|
||||||
if (video != null)
|
if (video != null)
|
||||||
{
|
{
|
||||||
var bitRate = Convert.ToDouble(video.BitRate, CultureInfo.InvariantCulture);
|
var bitRate = Convert.ToDouble(video.BitRate, CultureInfo.InvariantCulture);
|
||||||
|
|
Loading…
Reference in a new issue