Fix duration parsing of .mkv and .webm files

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

View file

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

View file

@ -79,9 +79,20 @@ private VideoInfo ParseVideoInfoInternal(VideoInfo info, string probeOutput)
double videoSize = 0d;
double audioSize = 0d;
var duration = TimeSpan.FromSeconds(double.TryParse((video ?? audio).Duration, NumberStyles.Any, CultureInfo.InvariantCulture, out var output) ? output : 0);
info.Duration = duration.Subtract(TimeSpan.FromMilliseconds(duration.Milliseconds));
string sDuration = (video ?? audio).Duration;
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)
{
var bitRate = Convert.ToDouble(video.BitRate, CultureInfo.InvariantCulture);