Skip to content

Commit

Permalink
player: add forced choice to subs-with-matching-audio
Browse files Browse the repository at this point in the history
fe87508 confused things a bit and made
--no-subs-with-matching-audio actually mean what it says: no subtitles
if the languages match. However, the option actually meant no non-forced
subtitles not no subtitles at all. This isn't really intuitive so
instead of changing the behavior back to the old way (we already have a
release since then), add a third option "forced" which is equivalent to
the old meaning of --no-subs-with-matching audio. Fixes mpv-player#13151.
  • Loading branch information
Dudemanguy committed Jan 13, 2024
1 parent 871f7a1 commit 2ad9607
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions DOCS/interface-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Interface changes
- rename key `MP_KEY_BACK` to `MP_KEY_GO_BACK`
- add `--sub-filter-sdh-enclosures` option
- added the `mp.input` scripting API to query the user for textual input
- add `forced` choice to `subs-with-matching-audio`
--- mpv 0.37.0 ---
- `--save-position-on-quit` and its associated commands now store state files
in %LOCALAPPDATA% instead of %APPDATA% directory by default on Windows.
Expand Down
12 changes: 7 additions & 5 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ Track Selection
Note that if ``--lavfi-complex`` is set before playback is started, the
referenced tracks are always selected.

``--subs-with-matching-audio=<yes|no>``
When autoselecting a subtitle track, select a full/non-forced one even if the selected
audio stream matches your preferred subtitle language (default: yes). If this option is
set to ``no``, a non-forced subtitle track that matches the audio language will never be
autoselected by mpv regardless of the value of ``--slang`` or ``--subs-fallback``.
``--subs-with-matching-audio=<yes|forced|no>``
When autoselecting a subtitle track, select it even if the selected audio
stream matches you preferred subtitle language (default: yes). If this
option is set to ``no``, then no subtitle track that matches the audio
language will ever be autoselected by mpv regardless of ``--slang`` or
``subs-fallback``. If set to ``forced``, then only forced subtitles
will be selected.

``--subs-match-os-language=<yes|no>``
When autoselecting a subtitle track, select the track that matches the language of your OS
Expand Down
5 changes: 3 additions & 2 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ static const m_option_t mp_opts[] = {
{"slang", OPT_STRINGLIST(stream_lang[STREAM_SUB])},
{"vlang", OPT_STRINGLIST(stream_lang[STREAM_VIDEO])},
{"track-auto-selection", OPT_BOOL(stream_auto_sel)},
{"subs-with-matching-audio", OPT_BOOL(subs_with_matching_audio)},
{"subs-with-matching-audio", OPT_CHOICE(subs_with_matching_audio, {"no", 0},
{"forced", 1}, {"yes", 2})},
{"subs-match-os-language", OPT_BOOL(subs_match_os_language)},
{"subs-fallback", OPT_CHOICE(subs_fallback, {"no", 0}, {"default", 1}, {"yes", 2})},
{"subs-fallback-forced", OPT_CHOICE(subs_fallback_forced, {"no", 0},
Expand Down Expand Up @@ -984,7 +985,7 @@ static const struct MPOpts mp_default_opts = {
[STREAM_VIDEO] = -2,
[STREAM_SUB] = -2, }, },
.stream_auto_sel = true,
.subs_with_matching_audio = true,
.subs_with_matching_audio = 2,
.subs_match_os_language = true,
.subs_fallback = 1,
.subs_fallback_forced = 1,
Expand Down
2 changes: 1 addition & 1 deletion options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ typedef struct MPOpts {
int stream_id[2][STREAM_TYPE_COUNT];
char **stream_lang[STREAM_TYPE_COUNT];
bool stream_auto_sel;
bool subs_with_matching_audio;
int subs_with_matching_audio;
bool subs_match_os_language;
int subs_fallback;
int subs_fallback_forced;
Expand Down
7 changes: 5 additions & 2 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,12 @@ struct track *select_default_track(struct MPContext *mpctx, int order,
if (pick && !forced_pick && sub && (!match_lang(langs, pick->lang) || os_langs) && !sub_fallback)
pick = NULL;
// Handle this after matching langs and selecting a fallback.
if (pick && sub && (!opts->subs_with_matching_audio && audio_matches))
if (pick && sub && ((!opts->subs_with_matching_audio && audio_matches) ||
(opts->subs_with_matching_audio == 1 && audio_matches && !forced_pick)))
{
pick = NULL;
// Handle edge cases if we picked a track that doesn't match the --subs-fallback-force value
}
// Handle edge cases if we picked a track that doesn't match the --subs-fallback-forced value
if (pick && sub && ((!pick->forced_track && opts->subs_fallback_forced == 2) ||
(pick->forced_track && !opts->subs_fallback_forced)))
{
Expand Down

0 comments on commit 2ad9607

Please sign in to comment.