mpv-player / mpv-player/mpv

Proposal: a more reasonable order in compare_track

Open
#6,071 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

core:file core:option-param-conf meta:feature-request
Dominant language
C
Stars
37k
Forks
3.5k
Avg merge
1d 10h
Merged PRs (30d)
22

Description

There have been very few discussions about what is the best default for track auto-selection mechanism, and previous issues such as #3777, #5127 and #5433 usually result in no change. One big reason I think is, most people will not encounter external files or multiple tracks. The other reason I guess is, most of the core devs are already comfortable with the current behavior or didn't find any cases that current auto-selection mechanism might make trouble, so they decided nothing should be changed.

Here is the current order of comparison:
https://github.com/mpv-player/mpv/blob/d5cad856255cb0e74461f9d6613f561c6f347a0f/player/loadfile.c#L315-L332

compare_track was introduced in 0f155921b046c9e6cfed3fe601aa891c2d2a8b16. The external file auto-load and selection was a feature.

Couldn't trace back further to see why "external" precedes "lang" (this is the point that most conflicts arise), but I do see the intentions in the design:

  1. External subtitle files usually come with no language code. With language code competition it will not necessarily win.
  2. The video has an internal 'eng' sub track, and the user places an external 'eng' sub file in the same directory, it must be the case that the user wants the external subtitle but not the internal one.

But it will also lead to unexpected behavior when:

  • The video has an internal 'eng' sub track, while this video file is provided along with sub files in other languages. It is rare, but it happens. The user is not willing to move/delete those files because the file integrity of the entire folder must be kept.

So I think the track auto-selection should not always pick up external tracks blindly. It also happens that users may want the tracks loaded and change the track being played during the playback time. Commit 34cf655ddd99a67af0d1899499c14c4617236352 supports the idea. (Otherwise what is --external-files for?)

I propose:

0a) track matches ff-index (always wins) 
0b) track matches tid (almost always wins) 
0c) track is not from --external-file
1) track was passed explicitly (is not an auto-loaded subtitle) 
2) track is external (no_default cancels this) **and (has match in lang list or (filename is exact match && lang is unknown))**
3) earlier match in lang list 
4) **track is external (no_default cancels this) and !(conditions in 2)**
5a) track is marked forced 
5b) track is marked default 
6) attached picture, HLS bitrate 
7) lower track number 

In this case, most of the users won't get affected. People who care about this issue, can name their subtitle/audio files to explicitly include language codes, so that they get external files auto-loaded and get the desired auto-selected track simultaneously.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in player/loadfile.c around compare_track, using the linked current comparison order and the proposed ordering as the specification. Review the referenced issues and commits to understand the existing external-file and track-selection behavior. Done means the auto-selection order reflects the proposal without changing the behavior of users who do not encounter these cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.