From 51abf6f503dae58428f3558e77805f2937335d8f Mon Sep 17 00:00:00 2001 From: crobibero Date: Tue, 15 Sep 2026 11:15:47 -0400 Subject: Backport pull request #17883 from jellyfin/release-12.z Fix trickplay using the wrong video stream Original-merge: 31f05331911748eeda047be92f19dfd801b9fff6 Merged-by: crobibero Backported-by: Cody Robibero --- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'MediaBrowser.MediaEncoding') diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index f64fd73763..fa43d756a4 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -922,6 +922,15 @@ namespace MediaBrowser.MediaEncoding.Encoder inputArg = "-hwaccel_flags +low_priority " + inputArg; } + // Force the video stream, otherwise ffmpeg may pick a cover image. + var streamIndex = EncodingHelper.FindIndex(mediaSource.MediaStreams, imageStream); + if (streamIndex < 0) + { + throw new InvalidOperationException($"Unable to locate requested stream {imageStream.Title}"); + } + + inputArg += " -map 0:" + streamIndex; + var filterParam = encodingHelper.GetVideoProcessingFilterParam(jobState, options, vidEncoder).Trim(); if (string.IsNullOrWhiteSpace(filterParam)) { -- cgit v1.2.3 From bc753b18ec5923ae1f3026cfe4ad51534521ab2a Mon Sep 17 00:00:00 2001 From: SimonvBez <31727669+SimonvBez@users.noreply.github.com> Date: Tue, 15 Sep 2026 11:15:54 -0400 Subject: Backport pull request #17906 from jellyfin/release-12.z Fix transcode throttling not enabling on supported systems (caused by race condition) Original-merge: b8b6e392bf9f01b691c63e8ce91fdde7a8276344 Merged-by: crobibero Backported-by: Cody Robibero --- CONTRIBUTORS.md | 1 + MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'MediaBrowser.MediaEncoding') diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a97d335170..f5f844bcbc 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -138,6 +138,7 @@ - [SegiH](https://github.com/SegiH) - [SenorSmartyPants](https://github.com/SenorSmartyPants) - [shemanaev](https://github.com/shemanaev) + - [SimonvBez](https://github.com/SimonvBez) - [skaro13](https://github.com/skaro13) - [sl1288](https://github.com/sl1288) - [Smith00101010](https://github.com/Smith00101010) diff --git a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs index 91d0c3d5a6..99c08eb9a1 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncoderValidator.cs @@ -193,8 +193,6 @@ namespace MediaBrowser.MediaEncoding.Encoder private readonly string _encoderPath; - private readonly Version _minFFmpegMultiThreadedCli = new Version(7, 0); - public EncoderValidator(ILogger logger, string encoderPath) { _logger = logger; @@ -552,9 +550,9 @@ namespace MediaBrowser.MediaEncoding.Encoder string output; try { - // With multi-threaded cli support, FFmpeg 7 is less sensitive to keyboard input - var duration = ffmpegVersion >= _minFFmpegMultiThreadedCli ? 10000 : 1000; - output = GetProcessOutput(_encoderPath, $"-hide_banner -f lavfi -i nullsrc=s=1x1:d={duration} -f null -", true, "?"); + // Start a dummy encode of 1x1@1fps. Send '?' to stdin to get the help/keybind text, followed by 'q' to stop the job immediately + // As a safeguard in case 'q' doesn't stop the job, the dummy input has a max duration of 5 (realtime) seconds + output = GetProcessOutput(_encoderPath, $"-hide_banner -re -f lavfi -i nullsrc=s=1x1:r=1:d=5 -f null -", true, "?q"); } catch (Exception ex) { -- cgit v1.2.3 From bfb7af28971c890d4108902ef1d2134de6e5a35b Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Sun, 27 Sep 2026 16:30:55 -0400 Subject: Backport pull request #18164 from jellyfin/release-12.z Fix typo when parsing codec_tag_string Original-merge: 8358c03ebf2b796b4dd50e82ab2fcb8d29dacd10 Merged-by: crobibero Backported-by: Cody Robibero --- MediaBrowser.MediaEncoding/Probing/MediaStreamInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.MediaEncoding') diff --git a/MediaBrowser.MediaEncoding/Probing/MediaStreamInfo.cs b/MediaBrowser.MediaEncoding/Probing/MediaStreamInfo.cs index f631c471f6..17ab378ef7 100644 --- a/MediaBrowser.MediaEncoding/Probing/MediaStreamInfo.cs +++ b/MediaBrowser.MediaEncoding/Probing/MediaStreamInfo.cs @@ -198,10 +198,10 @@ namespace MediaBrowser.MediaEncoding.Probing public string? CodecTag { get; set; } /// - /// Gets or sets the codec_tag_string?. + /// Gets or sets the codec_tag_string. /// - /// The codec_tag_string?. - [JsonPropertyName("codec_tag_string?")] + /// The codec_tag_string. + [JsonPropertyName("codec_tag_string")] public string? CodecTagString { get; set; } /// -- cgit v1.2.3 From 054706333d0c76b2fe676c91fbdf19b39d3d7b8b Mon Sep 17 00:00:00 2001 From: myristate Date: Tue, 13 Oct 2026 13:36:10 -0400 Subject: Backport pull request #18243 from jellyfin/release-12.z Fix crash probing streams without frame size Original-merge: 8e50df32e7ca3f7d74553b2dbb40cc3ef8e95bfc Merged-by: crobibero Backported-by: Bond_009 --- CONTRIBUTORS.md | 1 + .../Probing/ProbeResultNormalizer.cs | 6 ++ .../Probing/ProbeResultNormalizerTests.cs | 21 ++++++ .../Test Data/Probing/video_ts_no_dimensions.json | 81 +++++++++++++++++++++ .../Probing/video_ts_no_dimensions_zero_dar.json | 83 ++++++++++++++++++++++ 5 files changed, 192 insertions(+) create mode 100644 tests/Jellyfin.MediaEncoding.Tests/Test Data/Probing/video_ts_no_dimensions.json create mode 100644 tests/Jellyfin.MediaEncoding.Tests/Test Data/Probing/video_ts_no_dimensions_zero_dar.json (limited to 'MediaBrowser.MediaEncoding') diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9012e35f1d..2bd0aeba6a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -99,6 +99,7 @@ - [mitchfizz05](https://github.com/mitchfizz05) - [mohd-akram](https://github.com/mohd-akram) - [MrTimscampi](https://github.com/MrTimscampi) + - [myristate](https://github.com/myristate) - [n8225](https://github.com/n8225) - [Nalsai](https://github.com/Nalsai) - [Narfinger](https://github.com/Narfinger) diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 5533e55223..c9d618c84a 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -1110,6 +1110,12 @@ namespace MediaBrowser.MediaEncoding.Probing && width > 0 && height > 0)) { + // Live TV and other early probes can report neither a usable display aspect ratio nor the frame size + if (info.Width is not > 0 || info.Height is not > 0) + { + return original; + } + width = info.Width.Value; height = info.Height.Value; } diff --git a/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeResultNormalizerTests.cs b/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeResultNormalizerTests.cs index 52e0b19700..cf9930abe1 100644 --- a/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeResultNormalizerTests.cs +++ b/tests/Jellyfin.MediaEncoding.Tests/Probing/ProbeResultNormalizerTests.cs @@ -242,6 +242,27 @@ namespace Jellyfin.MediaEncoding.Tests.Probing Assert.False(res.MediaStreams[0].IsAVC); } + [Theory] + [InlineData("Test Data/Probing/video_ts_no_dimensions.json", null)] + [InlineData("Test Data/Probing/video_ts_no_dimensions_zero_dar.json", "0:1")] + public void GetMediaInfo_TSWithoutDimensions_Success(string path, string? expectedAspectRatio) + { + var bytes = File.ReadAllBytes(path); + var internalMediaInfoResult = JsonSerializer.Deserialize(bytes, _jsonOptions); + + MediaInfo res = _probeResultNormalizer.GetMediaInfo(internalMediaInfoResult, VideoType.VideoFile, false, "http://192.168.1.19:5004/auto/v4", MediaProtocol.Http); + + Assert.Equal(2, res.MediaStreams.Count); + + var video = res.MediaStreams[0]; + Assert.Equal(MediaStreamType.Video, video.Type); + Assert.Equal("mpeg2video", video.Codec); + Assert.Null(video.Width); + Assert.Null(video.Height); + Assert.Equal(expectedAspectRatio, video.AspectRatio); + Assert.False(video.IsAnamorphic); + } + [Fact] public void GetMediaInfo_WebM_Success() { diff --git a/tests/Jellyfin.MediaEncoding.Tests/Test Data/Probing/video_ts_no_dimensions.json b/tests/Jellyfin.MediaEncoding.Tests/Test Data/Probing/video_ts_no_dimensions.json new file mode 100644 index 0000000000..cc45b48fff --- /dev/null +++ b/tests/Jellyfin.MediaEncoding.Tests/Test Data/Probing/video_ts_no_dimensions.json @@ -0,0 +1,81 @@ +{ + "streams": [ + { + "index": 0, + "codec_name": "mpeg2video", + "codec_long_name": "MPEG-2 video", + "profile": "Main", + "codec_type": "video", + "codec_tag_string": "[2][0][0][0]", + "codec_tag": "0x0002", + "pix_fmt": "yuv420p", + "level": 8, + "id": "0x259", + "r_frame_rate": "25/1", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 6181452600, + "start_time": "68682.806667", + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0 + } + }, + { + "index": 1, + "codec_name": "mp2", + "codec_long_name": "MP2 (MPEG audio layer 2)", + "codec_type": "audio", + "codec_tag_string": "[3][0][0][0]", + "codec_tag": "0x0003", + "sample_fmt": "fltp", + "sample_rate": "48000", + "channels": 2, + "channel_layout": "stereo", + "bits_per_sample": 0, + "id": "0x25a", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 6181460000, + "start_time": "68682.888889", + "bit_rate": "256000", + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0 + }, + "tags": { + "language": "eng" + } + } + ], + "format": { + "filename": "http://192.168.1.19:5004/auto/v4", + "nb_streams": 2, + "nb_programs": 1, + "format_name": "mpegts", + "format_long_name": "MPEG-TS (MPEG-2 Transport Stream)", + "start_time": "68682.806667", + "probe_score": 50 + } +} diff --git a/tests/Jellyfin.MediaEncoding.Tests/Test Data/Probing/video_ts_no_dimensions_zero_dar.json b/tests/Jellyfin.MediaEncoding.Tests/Test Data/Probing/video_ts_no_dimensions_zero_dar.json new file mode 100644 index 0000000000..c249efda3c --- /dev/null +++ b/tests/Jellyfin.MediaEncoding.Tests/Test Data/Probing/video_ts_no_dimensions_zero_dar.json @@ -0,0 +1,83 @@ +{ + "streams": [ + { + "index": 0, + "codec_name": "mpeg2video", + "codec_long_name": "MPEG-2 video", + "profile": "Main", + "codec_type": "video", + "codec_tag_string": "[2][0][0][0]", + "codec_tag": "0x0002", + "sample_aspect_ratio": "0:1", + "display_aspect_ratio": "0:1", + "pix_fmt": "yuv420p", + "level": 8, + "id": "0x259", + "r_frame_rate": "25/1", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 6181452600, + "start_time": "68682.806667", + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0 + } + }, + { + "index": 1, + "codec_name": "mp2", + "codec_long_name": "MP2 (MPEG audio layer 2)", + "codec_type": "audio", + "codec_tag_string": "[3][0][0][0]", + "codec_tag": "0x0003", + "sample_fmt": "fltp", + "sample_rate": "48000", + "channels": 2, + "channel_layout": "stereo", + "bits_per_sample": 0, + "id": "0x25a", + "r_frame_rate": "0/0", + "avg_frame_rate": "0/0", + "time_base": "1/90000", + "start_pts": 6181460000, + "start_time": "68682.888889", + "bit_rate": "256000", + "disposition": { + "default": 0, + "dub": 0, + "original": 0, + "comment": 0, + "lyrics": 0, + "karaoke": 0, + "forced": 0, + "hearing_impaired": 0, + "visual_impaired": 0, + "clean_effects": 0, + "attached_pic": 0, + "timed_thumbnails": 0 + }, + "tags": { + "language": "eng" + } + } + ], + "format": { + "filename": "http://192.168.1.19:5004/auto/v4", + "nb_streams": 2, + "nb_programs": 1, + "format_name": "mpegts", + "format_long_name": "MPEG-TS (MPEG-2 Transport Stream)", + "start_time": "68682.806667", + "probe_score": 50 + } +} -- cgit v1.2.3 From f624cb4cc54826d4fc5c56dc2de9120a0ea632ce Mon Sep 17 00:00:00 2001 From: p27ZuH6CNAdzr <317456640+p27ZuH6CNAdzr@users.noreply.github.com> Date: Tue, 13 Oct 2026 13:36:11 -0400 Subject: Backport pull request #18309 from jellyfin/release-12.z Fix crash when a subtitle charset has no .NET encoding Original-merge: 2f5be2df9be3d9ef44af4bf787a063f4d4166629 Merged-by: Bond-009 Backported-by: Bond_009 --- CONTRIBUTORS.md | 1 + .../Subtitles/SubtitleEncoder.cs | 8 +++++ .../Subtitles/SubtitleEncoderTests.cs | 40 ++++++++++++++++++++++ 3 files changed, 49 insertions(+) (limited to 'MediaBrowser.MediaEncoding') diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 2bd0aeba6a..ac10184a09 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -250,6 +250,7 @@ - [TheDreadPirate](https://github.com/thedreaddpirate) - [Daniel Aquino](https://github.com/chino) - [klizas](https://github.com/klizas) + - [p27ZuH6CNAdzr](https://github.com/p27ZuH6CNAdzr) # Emby Contributors diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index fba644b74a..27a987fefe 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -188,6 +188,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles _logger.LogDebug("charset {CharSet} detected for {Path}", detected.EncodingName, fileInfo.Path); + // If encoding is not supported by .NET (e.g., ISO-8859-16), return stream as-is + // The charset name will be passed to ffmpeg via -sub_charenc if needed + if (detected.Encoding is null) + { + _logger.LogWarning("Encoding {Encoding} is not supported by .NET for {Path}, returning stream as-is", detected.EncodingName, fileInfo.Path); + return stream; + } + await using (stream.ConfigureAwait(false)) { using var reader = new StreamReader(stream, detected.Encoding); diff --git a/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs b/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs index 48850b2f67..13779851a9 100644 --- a/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs +++ b/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs @@ -269,6 +269,46 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests } } + [Fact] + public async Task GetSubtitleStream_UnsupportedEncoding_DoesNotThrow() + { + // Regression test for issue #2200 + // When the charset detector identifies an encoding not supported by .NET (e.g., ISO-8859-16), + // GetSubtitleStream should handle it gracefully instead of throwing ArgumentNullException + var cancellationToken = TestContext.Current.CancellationToken; + var srt = BuildGreekSrt(); + var path = Path.GetTempFileName(); + try + { + // Write as ISO-8859-7 (Greek) to create a non-UTF-8 file + await File.WriteAllTextAsync(path, srt, Encoding.GetEncoding("iso-8859-7"), cancellationToken); + + var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }); + var subtitleEncoder = fixture.Create(); + + var fileInfo = new SubtitleEncoder.SubtitleInfo + { + Path = path, + Protocol = MediaProtocol.File, + Format = "srt", + IsExternal = true + }; + + // This should not throw even if the detected encoding was unsupported + using var stream = await subtitleEncoder.GetSubtitleStream(fileInfo, cancellationToken); + Assert.NotNull(stream); + + // Verify we can read from the stream without error + using var reader = new StreamReader(stream); + var text = await reader.ReadToEndAsync(cancellationToken); + Assert.NotEmpty(text); + } + finally + { + File.Delete(path); + } + } + private static SubtitleEncoder CreateEncoder() { var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }); -- cgit v1.2.3