Lift restriction of duration to seconds

Former-commit-id: 0b35935b5d
This commit is contained in:
Crydsch 2020-02-13 17:36:49 +01:00
parent ed5fffd7a9
commit 073cfee5ea
2 changed files with 14 additions and 7 deletions

View file

@ -260,7 +260,11 @@ public void Video_Join()
var result = Encoder.Join(output, input, input2);
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.Width, result.Width);
}
@ -316,10 +320,10 @@ public void Video_With_Only_Audio_Should_Extract_Metadata()
var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideoAudioOnly);
Assert.AreEqual(video.VideoFormat, "none");
Assert.AreEqual(video.AudioFormat, "aac");
Assert.AreEqual(video.Duration.TotalSeconds, 79);
Assert.AreEqual(video.Duration.TotalSeconds, 79.451);
Assert.AreEqual(video.Size, 1.25);
}
[TestMethod]
public void Video_Duration() {
var video = VideoInfo.FromFileInfo(VideoLibrary.LocalVideo);
@ -335,7 +339,11 @@ public void Video_Duration() {
Assert.IsTrue(File.Exists(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 {
if (File.Exists(output.FullName))
output.Delete();

View file

@ -85,10 +85,9 @@ private VideoInfo ParseVideoInfoInternal(VideoInfo info, string probeOutput)
else
{
sDuration = (video ?? audio).Tags.Duration;
TimeSpan.TryParse(sDuration.Remove(sDuration.LastIndexOf('.')), CultureInfo.InvariantCulture, out duration);
TimeSpan.TryParse(sDuration.Remove(sDuration.LastIndexOf('.') + 8), CultureInfo.InvariantCulture, out duration); // TimeSpan fractions only allow up to 7 digits
}
// Strip milliseconds and additional ticks
info.Duration = new TimeSpan(duration.Days, duration.Hours, duration.Minutes, duration.Seconds);
info.Duration = duration;
if (video != null)
{