From 405d987557b2638afc89edf3dff20360e39cb09a Mon Sep 17 00:00:00 2001 From: Piotr Niełacny Date: Tue, 24 Mar 2026 14:26:25 +0100 Subject: Normalize VobSub .sub to .idx for embedding, add EncodingHelper tests Move the .sub to .idx path normalization outside the burn-in check so it applies to subtitle embedding as well. ffmpeg requires the .idx file to read VobSub subtitles. Add unit tests for GetMapArgs and GetInputArgument covering internal subs, external SRT, multi-file SRT, multi-stream MKS containers, and VobSub .sub/.idx path normalization. --- .../MediaEncoding/EncodingHelperTests.cs | 47 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'tests/Jellyfin.Controller.Tests/MediaEncoding/EncodingHelperTests.cs') diff --git a/tests/Jellyfin.Controller.Tests/MediaEncoding/EncodingHelperTests.cs b/tests/Jellyfin.Controller.Tests/MediaEncoding/EncodingHelperTests.cs index e6276f0e9e..6563dd63ab 100644 --- a/tests/Jellyfin.Controller.Tests/MediaEncoding/EncodingHelperTests.cs +++ b/tests/Jellyfin.Controller.Tests/MediaEncoding/EncodingHelperTests.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; +using System.IO; using Jellyfin.Data.Enums; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.Streaming; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; @@ -71,6 +73,8 @@ namespace Jellyfin.Controller.Tests.MediaEncoding [Fact] public void GetMapArgs_SecondExternalSrt_StillMaps1Colon0() { + // Two separate .srt files — selecting the second one still maps 1:0 + // because Jellyfin feeds only the selected file as ffmpeg input 1. var ext1 = new MediaStream { Index = 2, @@ -92,7 +96,6 @@ namespace Jellyfin.Controller.Tests.MediaEncoding var state = BuildState(ext2, SubtitleDeliveryMethod.Embed, additionalStreams: [ext1, ext2]); var args = CreateHelper().GetMapArgs(state); - // Different file from ext1, so in-file index is 0 Assert.Contains("-map 1:0", args, StringComparison.Ordinal); } @@ -156,10 +159,50 @@ namespace Jellyfin.Controller.Tests.MediaEncoding var state = BuildState(mks1, SubtitleDeliveryMethod.Embed, additionalStreams: [mks0, mks1, mks2]); var args = CreateHelper().GetMapArgs(state); - // Second track in the same .mks file → in-file index 1 Assert.Contains("-map 1:1", args, StringComparison.Ordinal); } + [Theory] + [InlineData(SubtitleDeliveryMethod.Embed, true, "movie.idx")] + [InlineData(SubtitleDeliveryMethod.Encode, true, "movie.idx")] + [InlineData(SubtitleDeliveryMethod.Embed, false, "movie.sub")] + [InlineData(SubtitleDeliveryMethod.Encode, false, "movie.sub")] + public void GetInputArgument_VobSub_UsesCorrectPath( + SubtitleDeliveryMethod deliveryMethod, + bool createIdxFile, + string expectedFilename) + { + var tempDir = Directory.CreateTempSubdirectory("jellyfin-test-"); + try + { + var subFile = Path.Combine(tempDir.FullName, "movie.sub"); + File.WriteAllText(subFile, "dummy"); + + if (createIdxFile) + { + File.WriteAllText(Path.Combine(tempDir.FullName, "movie.idx"), "dummy"); + } + + var sub = new MediaStream + { + Index = 2, + Type = MediaStreamType.Subtitle, + Codec = "dvdsub", + IsExternal = true, + SupportsExternalStream = true, + Path = subFile + }; + var state = BuildState(sub, deliveryMethod); + var inputArgs = CreateHelper().GetInputArgument(state, new EncodingOptions(), null); + + Assert.Contains(expectedFilename, inputArgs, StringComparison.Ordinal); + } + finally + { + tempDir.Delete(true); + } + } + private static EncodingJobInfo BuildState( MediaStream? subtitle, SubtitleDeliveryMethod? deliveryMethod, -- cgit v1.2.3