diff options
| author | Bond-009 <bond.009@outlook.com> | 2022-09-09 13:42:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-09 13:42:02 +0200 |
| commit | eb12aaf396fbad53c9922876d863ea2ae4ddfe16 (patch) | |
| tree | e2d3030eac5f39cf39785718b39d25e0edafdc6a | |
| parent | 1cbf5431aa74274627082cb02349a3241cd8801b (diff) | |
| parent | 2251e7d603926d371e9e604142d2a5634684f5b6 (diff) | |
Merge pull request #8335 from eglia/keyframe-extract-fixes
| -rw-r--r-- | CONTRIBUTORS.md | 1 | ||||
| -rw-r--r-- | src/Jellyfin.MediaEncoding.Keyframes/FfProbe/FfProbeKeyframeExtractor.cs | 17 |
2 files changed, 12 insertions, 6 deletions
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9c08929e7..98acd4449 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -36,6 +36,7 @@ - [dmitrylyzo](https://github.com/dmitrylyzo) - [DMouse10462](https://github.com/DMouse10462) - [DrPandemic](https://github.com/DrPandemic) + - [eglia](https://github.com/eglia) - [EraYaN](https://github.com/EraYaN) - [escabe](https://github.com/escabe) - [excelite](https://github.com/excelite) diff --git a/src/Jellyfin.MediaEncoding.Keyframes/FfProbe/FfProbeKeyframeExtractor.cs b/src/Jellyfin.MediaEncoding.Keyframes/FfProbe/FfProbeKeyframeExtractor.cs index 320604e10..79aa8a354 100644 --- a/src/Jellyfin.MediaEncoding.Keyframes/FfProbe/FfProbeKeyframeExtractor.cs +++ b/src/Jellyfin.MediaEncoding.Keyframes/FfProbe/FfProbeKeyframeExtractor.cs @@ -11,7 +11,7 @@ namespace Jellyfin.MediaEncoding.Keyframes.FfProbe; /// </summary> public static class FfProbeKeyframeExtractor { - private const string DefaultArguments = "-v error -skip_frame nokey -show_entries format=duration -show_entries stream=duration -show_entries packet=pts_time,flags -select_streams v -of csv \"{0}\""; + private const string DefaultArguments = "-fflags +genpts -v error -skip_frame nokey -show_entries format=duration -show_entries stream=duration -show_entries packet=pts_time,flags -select_streams v -of csv \"{0}\""; /// <summary> /// Extracts the keyframes using the ffprobe executable at the specified path. @@ -62,12 +62,17 @@ public static class FfProbeKeyframeExtractor var rest = line[(firstComma + 1)..]; 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 ptsTime = rest[..secondComma]; + var flags = rest[(secondComma + 1)..]; + if (flags.StartsWith("K_")) { - // Trim the flags from the packet line. Example line: packet,7169.079000,K_ - var keyframe = double.Parse(rest[..^3], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture); - // 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)); + if (double.TryParse(ptsTime, 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. + keyframes.Add(Convert.ToInt64(keyframe * TimeSpan.TicksPerSecond)); + } } } else if (lineType.Equals("stream", StringComparison.OrdinalIgnoreCase)) |
