@@ -117,11 +117,15 @@ private async Task ProcessOneItem(Video item, CancellationToken cancellationToke
117117 // truehd isn't supported by many consumer MP4 decoders even though ffmpeg can do it.
118118 // it's found on a lot of DoVi media (cough particularly hybrid remuxes cough),
119119 // but media like Bluray is required to have an AAC/AC3/whatever fallback stream for compatibility
120- var audioStream = streams . FirstOrDefault ( s => s . Type == MediaBrowser . Model . Entities . MediaStreamType . Audio
121- && s . Codec != "truehd"
122- && s . Language == "eng" )
120+ var audioStreams = streams . Where ( s => s . Type == MediaBrowser . Model . Entities . MediaStreamType . Audio
121+ && s . Codec != "truehd" )
122+ . Select ( ( audioStream , i ) => new { audioStream . Index , OutputIndex = i , audioStream . Language } )
123+ . ToList ( ) ;
124+ if ( audioStreams . Count == 0 )
125+ {
123126 // TODO: transcode it instead
124- ?? throw new Exception ( "Couldn't find an appropriate audio stream to copy" ) ;
127+ throw new Exception ( "Couldn't find an appropriate audio stream to copy" ) ;
128+ }
125129
126130 // PGS subtitles aren't supported by mp4. Technically we can use the copy codec
127131 // and most decoders will know how to use subrip subtitles, but mov_text is standard
@@ -148,13 +152,14 @@ private async Task ProcessOneItem(Video item, CancellationToken cancellationToke
148152
149153 string cli = "-analyzeduration 200M -probesize 1G -fflags +genpts " ;
150154 cli += $ "-i \" { inputPath } \" ";
151- cli += $ "-map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 -map 0:{ audioStream . Index } ";
155+ cli += $ "-map_metadata -1 -map_chapters -1 -threads 0 -map 0:0 ";
156+ cli += string . Concat ( audioStreams . Select ( a => $ "-map 0:{ a . Index } ") ) ;
152157 cli += string . Concat ( subtitles . Select ( s => $ "-map 0:{ s . Index } ") ) ;
153158 cli += "-codec:v:0 copy -tag:v:0 dvh1 -strict experimental -bsf:v hevc_mp4toannexb -start_at_zero " ;
159+ cli += string . Concat ( audioStreams . Select ( a => $ "-codec:a:{ a . OutputIndex } copy ") ) ;
154160 cli += string . Concat ( subtitles . Select ( s => $ "-codec:s:{ s . OutputIndex } { s . Codec } ") ) ;
155- cli += "-codec:a:0 copy " ;
161+ cli += string . Concat ( audioStreams . Select ( a => $ "-metadata:s:a: { a . OutputIndex } language= \" { a . Language } \" " ) ) ;
156162 cli += string . Concat ( subtitles . Select ( s => $ "-metadata:s:s:{ s . OutputIndex } language=\" { s . Lang } \" ") ) ;
157- cli += $ "-metadata:s:a:0 language=\" eng\" ";
158163 cli += "-copyts -avoid_negative_ts disabled -max_muxing_queue_size 2048 " ;
159164 cli += $ "\" { outputPath } \" ";
160165
0 commit comments