mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-22 08:37:23 +01:00
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.
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user