From 9230472056ea92a54a3f47bcb10142310ae0200e Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Sat, 10 Feb 2024 16:57:10 +0100 Subject: [PATCH] Fix file extension based on container --- Jellyfin.Api/Controllers/VideosController.cs | 4 +--- Jellyfin.Api/Helpers/StreamingHelpers.cs | 21 ++++++++++++++++++- .../MediaEncoding/EncodingHelper.cs | 3 ++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Jellyfin.Api/Controllers/VideosController.cs b/Jellyfin.Api/Controllers/VideosController.cs index 83f04d5bef..b3029d6fa8 100644 --- a/Jellyfin.Api/Controllers/VideosController.cs +++ b/Jellyfin.Api/Controllers/VideosController.cs @@ -458,8 +458,6 @@ public class VideosController : BaseJellyfinApiController return BadRequest($"Input protocol {state.InputProtocol} cannot be streamed statically"); } - var outputPath = state.OutputFilePath; - // Static stream if (@static.HasValue && @static.Value && !(state.MediaSource.VideoType == VideoType.BluRay || state.MediaSource.VideoType == VideoType.Dvd)) { @@ -478,7 +476,7 @@ public class VideosController : BaseJellyfinApiController // Need to start ffmpeg (because media can't be returned directly) var encodingOptions = _serverConfigurationManager.GetEncodingOptions(); - var ffmpegCommandLineArguments = _encodingHelper.GetProgressiveVideoFullCommandLine(state, encodingOptions, outputPath, "superfast"); + var ffmpegCommandLineArguments = _encodingHelper.GetProgressiveVideoFullCommandLine(state, encodingOptions, "superfast"); return await FileStreamResponseHelpers.GetTranscodedFile( state, isHeadRequest, diff --git a/Jellyfin.Api/Helpers/StreamingHelpers.cs b/Jellyfin.Api/Helpers/StreamingHelpers.cs index 7a3842a9f7..bfe71fd87b 100644 --- a/Jellyfin.Api/Helpers/StreamingHelpers.cs +++ b/Jellyfin.Api/Helpers/StreamingHelpers.cs @@ -225,7 +225,7 @@ public static class StreamingHelpers var ext = string.IsNullOrWhiteSpace(state.OutputContainer) ? GetOutputFileExtension(state, mediaSource) - : ("." + state.OutputContainer); + : ("." + GetContainerFileExtension(state.OutputContainer)); state.OutputFilePath = GetOutputFilePath(state, ext, serverConfigurationManager, streamingRequest.DeviceId, streamingRequest.PlaySessionId); @@ -559,4 +559,23 @@ public static class StreamingHelpers } } } + + /// + /// Parses the container into its file extension. + /// + /// The container. + private static string? GetContainerFileExtension(string? container) + { + if (string.Equals(container, "mpegts", StringComparison.OrdinalIgnoreCase)) + { + return "ts"; + } + + if (string.Equals(container, "matroska", StringComparison.OrdinalIgnoreCase)) + { + return "mkv"; + } + + return container; + } } diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index 1c95192f18..bb867aba30 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -6541,13 +6541,14 @@ namespace MediaBrowser.Controller.MediaEncoding return " -codec:s:0 " + codec + " -disposition:s:0 default"; } - public string GetProgressiveVideoFullCommandLine(EncodingJobInfo state, EncodingOptions encodingOptions, string outputPath, string defaultPreset) + public string GetProgressiveVideoFullCommandLine(EncodingJobInfo state, EncodingOptions encodingOptions, string defaultPreset) { // Get the output codec name var videoCodec = GetVideoEncoder(state, encodingOptions); var format = string.Empty; var keyFrame = string.Empty; + var outputPath = state.OutputFilePath; if (Path.GetExtension(outputPath.AsSpan()).Equals(".mp4", StringComparison.OrdinalIgnoreCase) && state.BaseRequest.Context == EncodingContext.Streaming)