A way to set the default subtitle per file
bhiltune opened this issue · comments
What you want IINA to do:
Simple: When I open up a video file, I want it to automatically use the last subtitle file I chose.
What IINA does currently:
When the video file begins to play, the active subtitle is always the first one in the subtitle panel, ignoring previous choice. This applies to .mkv files with embedded subtitles, at least. Haven't tested it with other filetypes.
(Also: My use case is not wanting to use the embedded subtitles and instead downloading and using my own subtitle file. When doing this, IINA behaves as I describe, not remembering to activate my subtitle file.)
Why you think this should be added:
It's a pretty simple convenience feature, and saves the user from having to go and manually set the subtitles to their preferred video file. Very annoying when resuming movies, for example.
I consider this a bug. The IINA setting Resume last playback position
remembers more than the playback position. One of the additional items being stored is the selected subtitle. So the subtitle that was selected should still be selected when the file is played again.
For audio/video playback and subtitle rendering support IINA is using a library from the mpv project. The Resume last playback position
setting enables the mpv
Watch Later feature. For this feature to work you must quit IINA while watching the video. If you switch to another video in the playlist, reach the end of the video or kill the IINA process then the state is not saved.
This shows me using Terminal to check what mpv
saved in the Watch Later
file:
low-batt@gag Movies$ md5 -qs '/Users/low-batt/Movies/English Video with Many Subtitles - Back up Batteries at Telecom Sites [_DRhasQu14c].mp4' | xargs -I % cat ~/Library/Application\ Support/com.colliderli.iina/watch_later/%
start=366.840000
pause=yes
mute=yes
sid=4
sub-scale=1.100000
low-batt@gag Movies$
The sid=4
refers to the mpv
sid option:
--sid=<ID|auto|no>
Display the subtitle stream specified by<ID>
. auto selects the default, no disables subtitles.
So why is this not working?
I believe the issue is that mpv
is restoring the settings from the Watch Later
file before IINA has loaded the subtitles. So when mpv
goes to select the 4th subtitle there isn't such a subtitle stream and the setting is lost.
As a workaround we configure IINA to use mpv
to load the subtitles. When mpv
loads the subtitles it is able to properly restore the saved selected subtitle setting. From the mpv
manual entry for the sub-auto option:
--sub-auto=<no|exact|fuzzy|all>
Load additional subtitle files matching the video filename. The parameter specifies how external subtitle files are matched. exact is enabled by default.
- no: Don't automatically load external subtitle files.
- exact: Load the media filename with subtitle file extension and possibly language suffixes (default).
- fuzzy: Load all subs containing the media filename.
- all: Load all subs in the current and
--sub-file-paths
directories.
To use this mpv
feature follow these instructions:
- Start IINA
- Click on
Settings…
under theIINA
menu - The settings panel appears
- On the left side of the panel click on
Subtitle
- Choose
Disabled
in theAuto load
pull-down button - On the left side of the panel click on
Advanced
- Slide the
Enable advanced settings
toggle button to be on (blue) - In the
Additional mpv options
section click on+
- A new entry appears in the table
- Double click on
name
and replace it withsub-auto
- Double click on
value
and replace it withfuzzy
- Confirm the settings panel looks like the screenshot below
- Restart IINA to activate the new settings
Great, thanks for the detailed solution!
This seems to have a different effect, however - any subtitles loaded from "outside" of IINA, like a .srt file for example, get forgotten about entirely, meaning that now you don't just have to contend with the wrong subtitle file, you now have to re-import the subtitle file every time you open up the file.
I'll play around with the settings a bit more and see if there's something that works even better, or an additional toggle.
Hopefully the bug is fixed to make this as intuitive as possible!
Edit: Okay, quick solution, should have tested out before posting:
If we set the setting value to "all" instead of "fuzzy" that works fine.
Just in case this is on my end, I'm putting all my video files and subtitle files in the same folder, with the same name, so this works best for my use case. It's best to play around with these settings, but I feel like "all" is probably good for most use-cases.
Thanks for reporting your results with the workaround.
Frequently defects are coding errors where the code does not function as intended. This is the harder kind of problem, a design problem. IINA loads subtitles "in the background" while starting to play the video. Possibly that was done to address a complaint where playback took a noticeable amount of time to start due to lots of subtitles being loaded? I'm a relatively new IINA developer so I don't know the history and why this choice was made. It has the side effect of breaking the mpv feature for remembering the subtitle that was being used.
The second problem you encountered is a problem with the mpv feature itself. As mpv only remembers the index into a list of subtitle streams it will fail if when the file is played again the list of subtitle streams is not exactly the same. If it changes then the index won't point to the correct subtitle. The more restrictive the sub-auto
setting is, the less likely it will find new subtitles to load and disrupt the index.
So the mpv feature is fragile. My guess is that mpv considers this acceptable because a design that does not have this limitation would be significantly more complex.
If I get a chance I will add the option to use mpv to find and load subtitles to IINA's settings. Using mpv's feature solves some other issues with IINA's subtitle loading.