Fix duration parsing of .mkv and .webm files

Former-commit-id: a4c7d87e62
This commit is contained in:
Cry dsch 2020-02-12 21:26:27 +01:00
parent 3ed5c7b314
commit 37fc05b26b
2 changed files with 24 additions and 3 deletions

View file

@ -31,8 +31,18 @@ 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
{ {
[JsonProperty("streams")] [JsonProperty("streams")]

View file

@ -79,8 +79,19 @@ 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;
if (sDuration != null)
{
duration = TimeSpan.FromSeconds(double.TryParse(sDuration, NumberStyles.Any, CultureInfo.InvariantCulture, out var output) ? output : 0);
}
else
{
sDuration = (video ?? audio).Tags.Duration;
TimeSpan.TryParse(sDuration.Remove(sDuration.LastIndexOf('.')), CultureInfo.InvariantCulture, out duration);
}
// Strip milliseconds and additional ticks
info.Duration = new TimeSpan(duration.Days, duration.Hours, duration.Minutes, duration.Seconds);
if (video != null) if (video != null)
{ {