1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 07:12:39 +00:00

mplayer: prefer -sub/-subfile subs over auto-loaded subs

Before this commit, it was more or less random which subtitle was
preferred if there was both an auto-loaded external subtitle, and a
subtitle loaded via -sub or -subfile. -sub subtitles happened to be
preferred over auto-loaded subs, while -subfile didn't. Fix the -subfile
case, and make the behavior consistent by making the selection behavior
explicit.
This commit is contained in:
wm4 2013-04-20 23:48:26 +02:00
parent 963c9aa3d5
commit c768a00dfe
2 changed files with 9 additions and 2 deletions

View File

@ -95,6 +95,7 @@ struct track {
// If this track is from an external file (e.g. subtitle file).
bool is_external;
char *external_filename;
bool auto_loaded;
// If the track's stream changes with the timeline (ordered chapters).
bool under_timeline;

View File

@ -3593,6 +3593,7 @@ static int match_lang(char **langs, char *lang)
* Sort tracks based on the following criteria, and pick the first:
* 0) track matches tid (always wins)
* 1) track is external
* 1b) track was passed explicitly (is not an auto-loaded subtitle)
* 2) earlier match in lang list
* 3) track is marked default
* 4) lower track number
@ -3605,6 +3606,8 @@ static bool compare_track(struct track *t1, struct track *t2, char **langs)
{
if (t1->is_external != t2->is_external)
return t1->is_external;
if (t1->auto_loaded != t2->auto_loaded)
return !t1->auto_loaded;
int l1 = match_lang(langs, t1->lang), l2 = match_lang(langs, t2->lang);
if (l1 != l2)
return l1 > l2;
@ -3687,8 +3690,11 @@ static void open_subtitles_from_options(struct MPContext *mpctx)
if (mpctx->opts.sub_auto) { // auto load sub file ...
char **tmp = find_text_subtitles(&mpctx->opts, mpctx->filename);
int nsub = MP_TALLOC_ELEMS(tmp);
for (int i = 0; i < nsub; i++)
mp_add_subtitles(mpctx, tmp[i], sub_fps, 1);
for (int i = 0; i < nsub; i++) {
struct track *track = mp_add_subtitles(mpctx, tmp[i], sub_fps, 1);
if (track)
track->auto_loaded = true;
}
talloc_free(tmp);
}
}