jellyfin / jellyfin-roku

The Official Roku Client for Jellyfin
https://jellyfin.org
GNU General Public License v2.0
412 stars 129 forks source link

Roku Playing Wrong Audio Track From Multi-track MKV Files #1277

Open lakerssuperman opened 1 year ago

lakerssuperman commented 1 year ago

I have a fair number of my movies ripped with the main audio and then a secondary track for the commentary. When clicking play on one of these movies the expected behavior of playing back the main audio track does not happen. Instead, the commentary track will play, despite the main audio track being selected in the audio options. If I click on the commentary track then the main audio track will play. In some cases, I have movies with three audio tracks and only by clicking on the third track will the primary track play. The main audio is primarily a 5.1 track.

The only exception to what I describe above is one movie in my collection I found will play back the primary track correctly. This is a 2.0 track, not a 5.1 track like most of my other movies. That seems to be the only difference I can find with this file vs the others.

Expected Behavior: Selected audio track is correctly played back

Actual Behavior: A track other than primary plays even though primary is selected in audio options. It seems the last track in the list of audio tracks is played and, conversely, selecting the last audio track will result in playback of the first (and usually primary) audio track.

This behavior occurs with the latest official app across all my Roku setups. This does not occur via the web client or playing back the mkv files locally on a computer via VLC.

flrgh commented 1 year ago

I've noticed some wonkiness with audio selection lately as well. For instance, I have an .mkv file where (annoyingly) stream 1 is the commentary, and stream 2 is the regular audio. On a semi-regular basis I will select stream 2 only to have it play stream 1 instead.

I've wondered if it has something to do with direct-play vs transcoding, because it seems like I have better luck getting the desired audio track after I've taken steps to force a transcode. However after reading this, I'm wondering if maybe it's just a UI state issue? i.e. the UI is updated to show the selected track, but for $reasons the underlying playback preferences/state has not been updated, so it just reverts back to the default track.

Sorry, I know this is not a super detailed report with clear instructions on how to reproduce the problem. I'm sorta hoping that a dev familiar enough with the codebase will see this and go "ah, that sounds like a problem with XYZ--I'll take a quick look at that piece of code and double check that it's doing the right thing." If it comes down to it I can do some more testing and gather some more debug info and/or better steps for repro.

skaboy71 commented 8 months ago

I'm having the same issue. I have a copy of The Postman with the original Italian audio + the "commentary" audio track, and my Roku will not play the original no matter what I try. It works fine in a browser on my computer but will not switch to the Italian audio in the Roku client.

stephenshutters commented 5 months ago

I've noticed some wonkiness with audio selection lately as well. For instance, I have an .mkv file where (annoyingly) stream 1 is the commentary, and stream 2 is the regular audio. On a semi-regular basis I will select stream 2 only to have it play stream 1 instead.

I've wondered if it has something to do with direct-play vs transcoding, because it seems like I have better luck getting the desired audio track after I've taken steps to force a transcode. However after reading this, I'm wondering if maybe it's just a UI state issue? i.e. the UI is updated to show the selected track, but for $reasons the underlying playback preferences/state has not been updated, so it just reverts back to the default track.

I’m having this exact issue in February of 2024 with my copy of Scream (2022). The first/default audio track option is a 5.1 Russian dub, while the secondary option is the original 7.1 English track. I obviously want to listen to the English track, but no matter how many times I select it in the pre-watch movie menu, it automatically jumps back to playing the Russian default track. And this is only happening in the Roku version of Jellyfin; on the web interface, and with the iOS app, it works just as it should and plays the English track.

stephenshutters commented 5 months ago

I have even tried unchecking the Play default audio track regardless of language option in the user playback settings on the web interface and restarting the server. This has not helped. IMG_9439

nefariousphd commented 4 months ago

I was having the same problem: multiple audio tracks, but the wrong one getting played. Even if I specifically selected an audio track, the wrong one played, as though the tracks were all mis-numbered. Eventually, I could find the main audio track by selecting one of the audio commentary tracks.

However, this problem only occurred when I had SRT subtitle tracks as separate files in the MKV folder for the movie. When I removed the SRT files, the audio tracks played correctly!

Some additional testing showed the following:

lakerssuperman commented 4 months ago

I was having the same problem: multiple audio tracks, but the wrong one getting played. Even if I specifically selected an audio track, the wrong one played, as though the tracks were all mis-numbered. Eventually, I could find the main audio track by selecting one of the audio commentary tracks.

However, this problem only occurred when I had SRT subtitle tracks as separate files in the MKV folder for the movie. When I removed the SRT files, the audio tracks played correctly!

Some additional testing showed the following:

* if the number of SRT files is less than the number of audio tracks, then the number of SRT files determines how the audio tracks are shifted. For example, if there are 3 SRT files and I select audio track 2 to play, in actuality audio track 5 will play instead. This cycles, too. So if there are a total of 5 audio tracks and 3 SRT files, then if I select to play audio track 3, then audio track 1 will actually play instead.

* if the number of SRT files is greater or equal to the number of audio tracks, then ONLY audio track 1 plays, no matter which audio track I select.

Interesting. I will absolutely take a look at this. Thanks.

stephenshutters commented 3 weeks ago

I've noticed some wonkiness with audio selection lately as well. For instance, I have an .mkv file where (annoyingly) stream 1 is the commentary, and stream 2 is the regular audio. On a semi-regular basis I will select stream 2 only to have it play stream 1 instead. I've wondered if it has something to do with direct-play vs transcoding, because it seems like I have better luck getting the desired audio track after I've taken steps to force a transcode. However after reading this, I'm wondering if maybe it's just a UI state issue? i.e. the UI is updated to show the selected track, but for $reasons the underlying playback preferences/state has not been updated, so it just reverts back to the default track.

I’m having this exact issue in February of 2024 with my copy of Scream (2022). The first/default audio track option is a 5.1 Russian dub, while the secondary option is the original 7.1 English track. I obviously want to listen to the English track, but no matter how many times I select it in the pre-watch movie menu, it automatically jumps back to playing the Russian default track. And this is only happening in the Roku version of Jellyfin; on the web interface, and with the iOS app, it works just as it should and plays the English track.

I’ve noticed that my issue only occurs (and always occurs) when the audio file is of a DTS-HD MA format. It seems that Roku can’t handle it, which is frustrating as h*eck, since half of my movies are remuxes with DTS-HD MA audio tracks.

lakerssuperman commented 3 weeks ago

I was having the same problem: multiple audio tracks, but the wrong one getting played. Even if I specifically selected an audio track, the wrong one played, as though the tracks were all mis-numbered. Eventually, I could find the main audio track by selecting one of the audio commentary tracks. However, this problem only occurred when I had SRT subtitle tracks as separate files in the MKV folder for the movie. When I removed the SRT files, the audio tracks played correctly! Some additional testing showed the following:

* if the number of SRT files is less than the number of audio tracks, then the number of SRT files determines how the audio tracks are shifted. For example, if there are 3 SRT files and I select audio track 2 to play, in actuality audio track 5 will play instead. This cycles, too. So if there are a total of 5 audio tracks and 3 SRT files, then if I select to play audio track 3, then audio track 1 will actually play instead.

* if the number of SRT files is greater or equal to the number of audio tracks, then ONLY audio track 1 plays, no matter which audio track I select.

Interesting. I will absolutely take a look at this. Than

I was having the same problem: multiple audio tracks, but the wrong one getting played. Even if I specifically selected an audio track, the wrong one played, as though the tracks were all mis-numbered. Eventually, I could find the main audio track by selecting one of the audio commentary tracks.

However, this problem only occurred when I had SRT subtitle tracks as separate files in the MKV folder for the movie. When I removed the SRT files, the audio tracks played correctly!

Some additional testing showed the following:

* if the number of SRT files is less than the number of audio tracks, then the number of SRT files determines how the audio tracks are shifted. For example, if there are 3 SRT files and I select audio track 2 to play, in actuality audio track 5 will play instead. This cycles, too. So if there are a total of 5 audio tracks and 3 SRT files, then if I select to play audio track 3, then audio track 1 will actually play instead.

* if the number of SRT files is greater or equal to the number of audio tracks, then ONLY audio track 1 plays, no matter which audio track I select.

Totally forgot to come back and comment, but I can confirm that having external .srt files with multiple audio tracks triggers the issue. If the .srt file is muxed into the mkv file the tracks playback in the correct order without issue. There's obviously a bug of some kind there, but this has been a consistently reliable workaround for this issue for me.

lakerssuperman commented 3 weeks ago

I've noticed some wonkiness with audio selection lately as well. For instance, I have an .mkv file where (annoyingly) stream 1 is the commentary, and stream 2 is the regular audio. On a semi-regular basis I will select stream 2 only to have it play stream 1 instead. I've wondered if it has something to do with direct-play vs transcoding, because it seems like I have better luck getting the desired audio track after I've taken steps to force a transcode. However after reading this, I'm wondering if maybe it's just a UI state issue? i.e. the UI is updated to show the selected track, but for $reasons the underlying playback preferences/state has not been updated, so it just reverts back to the default track.

I’m having this exact issue in February of 2024 with my copy of Scream (2022). The first/default audio track option is a 5.1 Russian dub, while the secondary option is the original 7.1 English track. I obviously want to listen to the English track, but no matter how many times I select it in the pre-watch movie menu, it automatically jumps back to playing the Russian default track. And this is only happening in the Roku version of Jellyfin; on the web interface, and with the iOS app, it works just as it should and plays the English track.

I’ve noticed that my issue only occurs (and always occurs) when the audio file is of a DTS-HD MA format. It seems that Roku can’t handle it, which is frustrating as h*eck, since half of my movies are remuxes with DTS-HD MA audio tracks.

Yes, as you discovered Roku doesn't do lossless audio. Is the Roku playing back the lossy DTS core track? If so, I discovered that with files using DTS, there are certain tags that need to be present in the mkv file or stuttering results, particularly with the newest Ultra and 4K stick. Doing a quick pass with ffmpeg should create the necessary tags that allow smooth playback with DTS if, in fact, this is what's happening to you.

Otherwise, I would think the audio would get transcoded to allow for playing.

flrgh commented 3 weeks ago

there are certain tags that need to be present in the mkv file or stuttering results, particularly with the newest Ultra and 4K stick. Doing a quick pass with ffmpeg should create the necessary tags that allow smooth playback with DTS if, in fact, this is what's happening to you.

:eyes: :eyes:

@lakerssuperman think you could share some more info on this? You are describing something that sounds very familiar to me (Roku Ultra), so I'd be very keen to try out your remedy.

As for the incorrect audio track issue, I figured out a workaround that works okay enough for my needs. I wrote a script that identifies files with a non-english stream in the first offset (or having the "default" disposition) and uses ffmpeg to drop them and reorder the audio streams in the file. Happy to dump that into a gist if anyone is interested.

lakerssuperman commented 3 weeks ago

there are certain tags that need to be present in the mkv file or stuttering results, particularly with the newest Ultra and 4K stick. Doing a quick pass with ffmpeg should create the necessary tags that allow smooth playback with DTS if, in fact, this is what's happening to you.

👀 👀

@lakerssuperman think you could share some more info on this? You are describing something that sounds very familiar to me (Roku Ultra), so I'd be very keen to try out your remedy.

As for the incorrect audio track issue, I figured out a workaround that works okay enough for my needs. I wrote a script that identifies files with a non-english stream in the first offset (or having the "default" disposition) and uses ffmpeg to drop them and reorder the audio streams in the file. Happy to dump that into a gist if anyone is interested.

I stumbled upon this when I first got the new Ultra devices and found my Bluray rips on my Jellyfin server would stutter if the audio was DTS. But then I also found that not all of them would stutter and the ones that wouldn't would show more tags in the mkv file when opened in mkvToolNix. I then found, randomly, that running the file through AviDemux would output a file with the tags needed for smooth playback.

Fast forward, I believe you can just run the file through a regular ffmpeg command and get the desired tags added to the output.

I use ffmpeg -i inputfile -map 0:0 -map 0:1 -c:v copy -c:a copy outputfile, adjusting for number of audio tracks and any subtitles in the file. But either way, AviDemux will produce a usable file.

The new Rokus are extremely sensitive to the mkv file structure, whether it be tags or metadata about color information. My older gen ones had no issue with this stuff, but the new ones get very unhappy about it lol.