The Free Software Media System - Server Backend & API
Fix file extension based on container
Shadowghost9230472056ea
diff --git a/Jellyfin.Api/Controllers/VideosController.cs b/Jellyfin.Api/Controllers/VideosController.csindex 83f04d5bef..b3029d6fa8 100644--- a/Jellyfin.Api/Controllers/VideosController.cs+++ b/Jellyfin.Api/Controllers/VideosController.cs@@ -458,8 +458,6 @@ public class VideosController : BaseJellyfinApiControllerreturn BadRequest($"Input protocol {state.InputProtocol} cannot be streamed statically");}- var outputPath = state.OutputFilePath;-// Static streamif (@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.csindex 7a3842a9f7..bfe71fd87b 100644--- a/Jellyfin.Api/Helpers/StreamingHelpers.cs+++ b/Jellyfin.Api/Helpers/StreamingHelpers.cs@@ -225,7 +225,7 @@ public static class StreamingHelpersvar 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}}}++ /// <summary>+ /// Parses the container into its file extension.+ /// </summary>+ /// <param name="container">The container.</param>+ 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.csindex 1c95192f18..bb867aba30 100644--- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs+++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs@@ -6541,13 +6541,14 @@ namespace MediaBrowser.Controller.MediaEncodingreturn " -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 namevar 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)