allow additional flags after K_ for ffprobe keyframe extraction

pull/8517/head
Andreas Egli 2 years ago committed by cvium
parent 14008fd7d0
commit 9db0b275ff

@ -62,10 +62,13 @@ public static class FfProbeKeyframeExtractor
var rest = line[(firstComma + 1)..]; var rest = line[(firstComma + 1)..];
if (lineType.Equals("packet", StringComparison.OrdinalIgnoreCase)) if (lineType.Equals("packet", StringComparison.OrdinalIgnoreCase))
{ {
if (rest.EndsWith(",K_")) // Split time and flags from the packet line. Example line: packet,7169.079000,K_
var secondComma = rest.IndexOf(',');
var pts_time = rest[..secondComma];
var flags = rest[(secondComma + 1)..];
if (flags.StartsWith("K_"))
{ {
// Trim the flags from the packet line. Example line: packet,7169.079000,K_ if (double.TryParse(pts_time, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var keyframe))
if (double.TryParse(rest[..^3], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var keyframe))
{ {
// Have to manually convert to ticks to avoid rounding errors as TimeSpan is only precise down to 1 ms when converting double. // Have to manually convert to ticks to avoid rounding errors as TimeSpan is only precise down to 1 ms when converting double.
keyframes.Add(Convert.ToInt64(keyframe * TimeSpan.TicksPerSecond)); keyframes.Add(Convert.ToInt64(keyframe * TimeSpan.TicksPerSecond));

Loading…
Cancel
Save