From b6a0fe337800f71453a60f30bda32c1a1db4ffe1 Mon Sep 17 00:00:00 2001 From: Cody Robibero Date: Mon, 13 Jun 2022 16:27:31 -0600 Subject: [PATCH] Merge pull request #7911 from cvium/fix_keyframe_transcode (cherry picked from commit 07b39655ebe2e96388ffbbecebeebb5284c26baf) Signed-off-by: crobibero --- Jellyfin.Api/Controllers/DynamicHlsController.cs | 3 ++- .../Playlist/CreateMainPlaylistRequest.cs | 9 ++++++++- .../Playlist/DynamicHlsPlaylistGenerator.cs | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Jellyfin.Api/Controllers/DynamicHlsController.cs b/Jellyfin.Api/Controllers/DynamicHlsController.cs index 9173487dd..8127193c2 100644 --- a/Jellyfin.Api/Controllers/DynamicHlsController.cs +++ b/Jellyfin.Api/Controllers/DynamicHlsController.cs @@ -1414,7 +1414,8 @@ namespace Jellyfin.Api.Controllers state.RunTimeTicks ?? 0, state.Request.SegmentContainer ?? string.Empty, "hls1/main/", - Request.QueryString.ToString()); + Request.QueryString.ToString(), + EncodingHelper.IsCopyCodec(state.OutputVideoCodec)); var playlist = _dynamicHlsPlaylistGenerator.CreateMainPlaylist(request); return new FileContentResult(Encoding.UTF8.GetBytes(playlist), MimeTypes.GetMimeType("playlist.m3u8")); diff --git a/src/Jellyfin.MediaEncoding.Hls/Playlist/CreateMainPlaylistRequest.cs b/src/Jellyfin.MediaEncoding.Hls/Playlist/CreateMainPlaylistRequest.cs index ac28ca26a..8572a5eae 100644 --- a/src/Jellyfin.MediaEncoding.Hls/Playlist/CreateMainPlaylistRequest.cs +++ b/src/Jellyfin.MediaEncoding.Hls/Playlist/CreateMainPlaylistRequest.cs @@ -14,7 +14,8 @@ public class CreateMainPlaylistRequest /// The desired segment container eg. "ts". /// The URI prefix for the relative URL in the playlist. /// The desired query string to append (must start with ?). - public CreateMainPlaylistRequest(string filePath, int desiredSegmentLengthMs, long totalRuntimeTicks, string segmentContainer, string endpointPrefix, string queryString) + /// Whether the video is being remuxed. + public CreateMainPlaylistRequest(string filePath, int desiredSegmentLengthMs, long totalRuntimeTicks, string segmentContainer, string endpointPrefix, string queryString, bool isRemuxingVideo) { FilePath = filePath; DesiredSegmentLengthMs = desiredSegmentLengthMs; @@ -22,6 +23,7 @@ public class CreateMainPlaylistRequest SegmentContainer = segmentContainer; EndpointPrefix = endpointPrefix; QueryString = queryString; + IsRemuxingVideo = isRemuxingVideo; } /// @@ -53,4 +55,9 @@ public class CreateMainPlaylistRequest /// Gets the query string. /// public string QueryString { get; } + + /// + /// Gets a value indicating whether the video is being remuxed. + /// + public bool IsRemuxingVideo { get; } } diff --git a/src/Jellyfin.MediaEncoding.Hls/Playlist/DynamicHlsPlaylistGenerator.cs b/src/Jellyfin.MediaEncoding.Hls/Playlist/DynamicHlsPlaylistGenerator.cs index 3382ba251..07a6d6050 100644 --- a/src/Jellyfin.MediaEncoding.Hls/Playlist/DynamicHlsPlaylistGenerator.cs +++ b/src/Jellyfin.MediaEncoding.Hls/Playlist/DynamicHlsPlaylistGenerator.cs @@ -34,7 +34,8 @@ public class DynamicHlsPlaylistGenerator : IDynamicHlsPlaylistGenerator public string CreateMainPlaylist(CreateMainPlaylistRequest request) { IReadOnlyList segments; - if (TryExtractKeyframes(request.FilePath, out var keyframeData)) + // For video transcodes it is sufficient with equal length segments as ffmpeg will create new keyframes + if (request.IsRemuxingVideo && TryExtractKeyframes(request.FilePath, out var keyframeData)) { segments = ComputeSegments(keyframeData, request.DesiredSegmentLengthMs); }