aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNegulici-R. Barnabas <109497789+negulici-r-barnabas@users.noreply.github.com>2022-11-13 15:29:16 +0200
committerGitHub <noreply@github.com>2022-11-13 15:29:16 +0200
commitb7aa5ed862db11bbbc0a4ea5c92a67b772bfc35d (patch)
treed8f396f581f3bdbd4be4c34d4a949df9fff72934 /src
parent1e41636e30b82518633ac6979564ff98bb40aca9 (diff)
parent6655cf4e58285f51b612efb0bb6229f036da2591 (diff)
Merge branch 'jellyfin:master' into master
Diffstat (limited to 'src')
-rw-r--r--src/Jellyfin.Extensions/EnumerableExtensions.cs73
-rw-r--r--src/Jellyfin.Extensions/SplitStringExtensions.cs2
-rw-r--r--src/Jellyfin.Extensions/StringExtensions.cs3
-rw-r--r--src/Jellyfin.MediaEncoding.Hls/Extractors/IKeyframeExtractor.cs1
-rw-r--r--src/Jellyfin.MediaEncoding.Keyframes/FfProbe/FfProbeKeyframeExtractor.cs40
-rw-r--r--src/Jellyfin.MediaEncoding.Keyframes/Jellyfin.MediaEncoding.Keyframes.csproj2
6 files changed, 75 insertions, 46 deletions
diff --git a/src/Jellyfin.Extensions/EnumerableExtensions.cs b/src/Jellyfin.Extensions/EnumerableExtensions.cs
index b5fe93357..fd46358a4 100644
--- a/src/Jellyfin.Extensions/EnumerableExtensions.cs
+++ b/src/Jellyfin.Extensions/EnumerableExtensions.cs
@@ -1,45 +1,31 @@
using System;
using System.Collections.Generic;
-namespace Jellyfin.Extensions
+namespace Jellyfin.Extensions;
+
+/// <summary>
+/// Static extensions for the <see cref="IEnumerable{T}"/> interface.
+/// </summary>
+public static class EnumerableExtensions
{
/// <summary>
- /// Static extensions for the <see cref="IEnumerable{T}"/> interface.
+ /// Determines whether the value is contained in the source collection.
/// </summary>
- public static class EnumerableExtensions
+ /// <param name="source">An instance of the <see cref="IEnumerable{String}"/> interface.</param>
+ /// <param name="value">The value to look for in the collection.</param>
+ /// <param name="stringComparison">The string comparison.</param>
+ /// <returns>A value indicating whether the value is contained in the collection.</returns>
+ /// <exception cref="ArgumentNullException">The source is null.</exception>
+ public static bool Contains(this IEnumerable<string> source, ReadOnlySpan<char> value, StringComparison stringComparison)
{
- /// <summary>
- /// Determines whether the value is contained in the source collection.
- /// </summary>
- /// <param name="source">An instance of the <see cref="IEnumerable{String}"/> interface.</param>
- /// <param name="value">The value to look for in the collection.</param>
- /// <param name="stringComparison">The string comparison.</param>
- /// <returns>A value indicating whether the value is contained in the collection.</returns>
- /// <exception cref="ArgumentNullException">The source is null.</exception>
- public static bool Contains(this IEnumerable<string> source, ReadOnlySpan<char> value, StringComparison stringComparison)
- {
- if (source == null)
- {
- throw new ArgumentNullException(nameof(source));
- }
+ ArgumentNullException.ThrowIfNull(source);
- if (source is IList<string> list)
- {
- int len = list.Count;
- for (int i = 0; i < len; i++)
- {
- if (value.Equals(list[i], stringComparison))
- {
- return true;
- }
- }
-
- return false;
- }
-
- foreach (string element in source)
+ if (source is IList<string> list)
+ {
+ int len = list.Count;
+ for (int i = 0; i < len; i++)
{
- if (value.Equals(element, stringComparison))
+ if (value.Equals(list[i], stringComparison))
{
return true;
}
@@ -47,5 +33,26 @@ namespace Jellyfin.Extensions
return false;
}
+
+ foreach (string element in source)
+ {
+ if (value.Equals(element, stringComparison))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Gets an IEnumerable from a single item.
+ /// </summary>
+ /// <param name="item">The item to return.</param>
+ /// <typeparam name="T">The type of item.</typeparam>
+ /// <returns>The IEnumerable{T}.</returns>
+ public static IEnumerable<T> SingleItemAsEnumerable<T>(this T item)
+ {
+ yield return item;
}
}
diff --git a/src/Jellyfin.Extensions/SplitStringExtensions.cs b/src/Jellyfin.Extensions/SplitStringExtensions.cs
index 1d1c377f5..a4dc9fc6b 100644
--- a/src/Jellyfin.Extensions/SplitStringExtensions.cs
+++ b/src/Jellyfin.Extensions/SplitStringExtensions.cs
@@ -55,7 +55,7 @@ namespace Jellyfin.Extensions
public static Enumerator Split(this ReadOnlySpan<char> str, char separator) => new(str, separator);
/// <summary>
- /// Provides an enumerator for the substrings seperated by the separator.
+ /// Provides an enumerator for the substrings separated by the separator.
/// </summary>
[StructLayout(LayoutKind.Auto)]
public ref struct Enumerator
diff --git a/src/Jellyfin.Extensions/StringExtensions.cs b/src/Jellyfin.Extensions/StringExtensions.cs
index dadc9f1d5..b19be071b 100644
--- a/src/Jellyfin.Extensions/StringExtensions.cs
+++ b/src/Jellyfin.Extensions/StringExtensions.cs
@@ -1,5 +1,4 @@
using System;
-using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
@@ -40,7 +39,7 @@ namespace Jellyfin.Extensions
}
/// <summary>
- /// Checks wether or not the specified string has diacritics in it.
+ /// Checks whether or not the specified string has diacritics in it.
/// </summary>
/// <param name="text">The string to check.</param>
/// <returns>True if the string has diacritics, false otherwise.</returns>
diff --git a/src/Jellyfin.MediaEncoding.Hls/Extractors/IKeyframeExtractor.cs b/src/Jellyfin.MediaEncoding.Hls/Extractors/IKeyframeExtractor.cs
index 497210f41..083e93de1 100644
--- a/src/Jellyfin.MediaEncoding.Hls/Extractors/IKeyframeExtractor.cs
+++ b/src/Jellyfin.MediaEncoding.Hls/Extractors/IKeyframeExtractor.cs
@@ -1,4 +1,3 @@
-using System;
using System.Diagnostics.CodeAnalysis;
using Jellyfin.MediaEncoding.Keyframes;
diff --git a/src/Jellyfin.MediaEncoding.Keyframes/FfProbe/FfProbeKeyframeExtractor.cs b/src/Jellyfin.MediaEncoding.Keyframes/FfProbe/FfProbeKeyframeExtractor.cs
index 320604e10..febe9516a 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.
@@ -38,9 +38,28 @@ public static class FfProbeKeyframeExtractor
EnableRaisingEvents = true
};
- process.Start();
+ try
+ {
+ process.Start();
- return ParseStream(process.StandardOutput);
+ return ParseStream(process.StandardOutput);
+ }
+ catch (Exception)
+ {
+ try
+ {
+ if (!process.HasExited)
+ {
+ process.Kill();
+ }
+ }
+ catch
+ {
+ // We do not care if this fails
+ }
+
+ throw;
+ }
}
internal static KeyframeData ParseStream(StreamReader reader)
@@ -62,12 +81,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))
diff --git a/src/Jellyfin.MediaEncoding.Keyframes/Jellyfin.MediaEncoding.Keyframes.csproj b/src/Jellyfin.MediaEncoding.Keyframes/Jellyfin.MediaEncoding.Keyframes.csproj
index 29cdf561f..8be5cd8dc 100644
--- a/src/Jellyfin.MediaEncoding.Keyframes/Jellyfin.MediaEncoding.Keyframes.csproj
+++ b/src/Jellyfin.MediaEncoding.Keyframes/Jellyfin.MediaEncoding.Keyframes.csproj
@@ -21,7 +21,7 @@
</ItemGroup>
<ItemGroup>
- <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
+ <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.3" />
</ItemGroup>
<ItemGroup>