mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
Fix duration parsing of .mkv and .webm files
This commit is contained in:
parent
09f1d6e655
commit
a4c7d87e62
2 changed files with 24 additions and 3 deletions
|
@ -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")]
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue