aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller
diff options
context:
space:
mode:
authorPiotr Niełacny <piotr.nielacny@gmail.com>2026-03-24 11:02:10 +0100
committerPiotr Niełacny <piotr.nielacny@gmail.com>2026-05-19 13:03:07 +0200
commita15b426e73afb46d7337b98f8279e83847e20f2d (patch)
tree3e6bcda57a84282533d56dfb4945c57fb2948831 /MediaBrowser.Controller
parent2a689f268bc88ee7ab7e25121a6d43f71c1f8a5f (diff)
Fix external subtitle stream mapping for multi-stream containers
Compute the in-file stream index for external subtitles instead of hardcoding -map 1:0. For single-stream files (SRT/ASS/VTT) the index is always 0, preserving existing behavior. For multi-stream containers like MKS, the correct track is selected by counting sibling streams that share the same Path. Add unit tests for GetMapArgs covering internal subs, external SRT, multiple external files, and multi-stream MKS containers.
Diffstat (limited to 'MediaBrowser.Controller')
-rw-r--r--MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs15
1 files changed, 13 insertions, 2 deletions
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
index 1fdb5fd4bd..40bb3913e9 100644
--- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
+++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
@@ -3104,8 +3104,19 @@ namespace MediaBrowser.Controller.MediaEncoding
{
if (state.SubtitleStream.IsExternal)
{
- // External subtitle file is added as second FFmpeg input
- args += " -map 1:0";
+ // External subtitle file is added as second FFmpeg input.
+ // For single-stream files (SRT/ASS/VTT) the in-file index is always 0.
+ // For multi-stream containers (MKS) we count how many streams from
+ // the same file appear before the selected one.
+ var inFileIndex = state.MediaSource.MediaStreams
+ .Where(s => string.Equals(s.Path, state.SubtitleStream.Path, StringComparison.Ordinal))
+ .TakeWhile(s => s.Index != state.SubtitleStream.Index)
+ .Count();
+
+ args += string.Format(
+ CultureInfo.InvariantCulture,
+ " -map 1:{0}",
+ inFileIndex);
}
else
{