Track selection cleanup#17280
Conversation
|
I'm currently compiling a list of some edge cases where the behavior changes. I will post it here when I finish. |
|
Those changes break
You can update the tests with all corner cases you wish to be fixed. The tests is somehow our documentation how exactly track selection should work. |
|
Does it? That might just be that weird race condition that sometimes happens in the CI. Doesn't make sense that the other msys2 all pass fine. The first two commits are most likely just fine. The next two not so sure. |
|
I have finished creating test cases for the behavior changes. Likely bugsI believe these to be bugs in the current implementation:
Please correct me if some of this behavior is intended. Test casesThe media files used by the test cases can be generated with this script: prepare_test_cases.sh (requires The test cases assume default config and OS language set to English. You can use run_test_cases.sh to run all of them at once. I will figure out how to add them to the test suite later if this is desired. A list of test cases, with comparison of behavior before/after changes
|
Only clang64 is built with ASAN, which triggers the issue. There is uninitialized variable, you can repro this also with |
For test cases, please use directly our meson testing, it will be easier to track changes. Files are generated here: Lines 20 to 22 in 468d34c And tested in libmpv_test_track_selection.c |
Use track->forced_select instead. The value would be assigned there anyway after the track is selected and the field is not used for any other purpose.
This brings compare_track closer to implementing a consistent linear order and fixes many broken edge cases.
This fixes the problem that a subtitle track that normally wouldn't be selected if it were the only track available could end up being selected after a different candidate track was selected first.
When autoload-files=no, external files are never selected. Simplify the logic by excluding them up front instead of removing them afterwards. This doesn't change the outcome of track selection, apart from edge cases that are already broken because compare_track is not transitive.
The new test case exercises --subs-fallback-forced=always and verifies that default+forced is preferred over forced.
This is a copy of the existing locale test, but with forced flag added to all tracks. The forced flag should not affect language selection in this case.
7e88dcd to
9d07e0e
Compare
|
I rebased the PR, updated commit descriptions (all commits now have an informative description) and added some tests. Please note that the tests I added to the test suite do not yet cover all test cases in the comment above. |
Please, let us know when you consider this ready for review, we can merge all the improvements in one go once they are ready. |
I won't change the existing commits, so they are technically ready for review already, although I can understand if you want to review everything at once. For one of the test cases, I need a file with multiple programs and subtitles. Unfortunately, the only container supporting multiple programs that I know of is MPEG-TS, and it only supports image subtitles. I couldn't find an easy way of generating image subtitles, so I instead used a file from ffmpeg test suite: https://fate-suite.ffmpeg.org/sub/dvbsubtest_filter.ts The script in my previous comment fetches the file from that URL, but I don't think doing that is acceptable in the test suite - there are no guarantees the file won't be taken down. For reference, this is the command used to generate the test file with multiple programs: ffmpeg \
-f lavfi -i color=white:2x2:d=0.1 \
-i https://fate-suite.ffmpeg.org/sub/dvbsubtest_filter.ts \
-map 0:v -map 1:s \
-map 0:v -map 1:s \
-c:v libx264 -c:s dvbsub \
-map_metadata -1 \
-program program_num=1:st=0:st=1 \
-program program_num=2:st=2:st=3 \
-metadata:s:1 language=eng \
-metadata:s:3 language=cze \
-f mpegts multiprogram.ts |
|
You can add a sample bitmap subtitle file to https://github.com/mpv-player/mpv/tree/master/test/samples as we already have srt files there. I would avoid adding full .ts sample there, as generating them gives us flexibility to generate various mpegts with this single input file. Subtitle Edit can export vobsub, which you can later use to mux into mpegts as dvbsub. |
The purpose of this test is mostly to verify that matching the OS language is not wrongly prioritized over other things (like the forced flag, matching the audio language, etc).
cd8544a to
986d07d
Compare
|
I have added all the tests now. Unfortunately, CI is failing because it has a ffmpeg build without a |
|
Also, the pre-commit hooks are complaining about the subtitle index... Maybe it would be easier to include a matroska file with just dvb subtitles, and then just remux that to mpegts. |
You can include dvbsub itself. |
|
My ffmpeg doesn't have raw dvbsub muxer (only demuxer) and I think SubtitleEdit doesn't support dvb subtitles either (or maybe it does and I just didn't find it) |
let's fix CI image then. |
It's typo in comment, I suggest fixing it manually, or even removing all comments from this file, they are not needed and will save on filesize. |
986d07d to
df08c40
Compare
|
dvbsub isn't available on the linux ci for now, I'll add it but it'll take a few days to make it into the image |
|
Thanks for all the hard work on this and building all the tests. I'll try to double check on my end later this week but I highly suspect you are correct in everything. And since the tests are all passing (old and new ones), that's a good sign. |
test/libmpv_test_track_selection.c
Outdated
| check_string("track-list/3/selected", "no"); | ||
|
|
||
| // because subs-fallback=default, the jpn track cannot be chosen | ||
| // so we choose the eng track despite it having the wrong program ID |
There was a problem hiding this comment.
despite it having the wrong program ID
Is this really what we expect to happen?
There was a problem hiding this comment.
I don't know, I have just attempted to mostly preserve the existing behavior while removing inconsistencies, but I agree this behavior doesn't make much sense.
To better understand the issue, I think it is helpful to consider a simpler case where subs-fallback doesn't play a role. Consider a file with the following tracks:
- video, program ID = 1
- video, program ID = 2
- subs, default, program ID = 2
When the first video is selected, should the subtitles with wrong program ID be used, or is it better to have no subtitles at all? Currently, mpv prefers wrong program to no track at all, but maybe that isn't right. And what if instead of subtitles it was an audio track?
There was a problem hiding this comment.
I think selecting track (audio or subtitle) from wrong PID is wrong and should instead select none in this case. (regardless of any fallback options)
There was a problem hiding this comment.
Also, on that note, selecting video track from different PID, imho, should reselect other tracks. So the multi program files are usable in mpv. I know it's outside the scope of this PR, but I wanted to point this out. Generally we don't have menu for program selection, it could be plugged into edition selection same as dvd/bluray titles are. Serves the same purpose. And the displayed/selected tracks should consist only of matching PID.
Sorry for offtopic. I just had this though, because I think it's low hanging fruit to greatly improve multiprogram support...
There was a problem hiding this comment.
I've changed the selection logic to never choose a track with the wrong PID, as this was simple enough to do. Further improvements will be left for future PRs.
(On the topic of improving multiprogram support, I also want to note down one more problem with the current implementation: I think it doesn't work on files with no video. Edition selection really seems like a much better fit for this than autoselect.)
Dudemanguy
left a comment
There was a problem hiding this comment.
The program id stuff can for another day if we want to iron out that should work (niche within a niche really). But that's unrelated and this PR is indeed a nice cleanup. I'll merge once dvbsub makes its way into our CI image.
|
Could you change multiprogram test file to mpeg2 (or anything else)? Apparently our CI image doesn't have a h264 decoder, so the test fails. |
| '-disposition:s:0', 'default', '-disposition:s:1', 'forced', '-disposition:s:3', 'default', | ||
| '@OUTPUT@'], | ||
| 'multiprogram.ts': | ||
| [ffmpeg, '-v', 'error', '-y', '-i', video, '-f', 'vobsub', '-i', img_sub, |
There was a problem hiding this comment.
Why not with audio? It can influence the selection too.
There was a problem hiding this comment.
Mostly because I didn't care enough about multiprogram files to put effort into making comprehensive tests, but also, currently only the video determines preferred program ID:
int preferred_program = (type != STREAM_VIDEO && mpctx->current_track[0][STREAM_VIDEO]) ?
mpctx->current_track[0][STREAM_VIDEO]->program_id : -1;
I'm pretty sure the multiprogram file uses the same video codec as the others, because it is created with |
The problem was that ffmpeg chose I have changed |
|
Should be OK I think. |
Currently, we prefer selecting a track that matches the video program ID, but can fall back on a track with a different program ID when there is no such track or when no such track matches subs-fallback criteria. Change this to instead select no track when only tracks with wrong PID are available. Program ID will now act as a filter, not as a preference, and only files with either matching or unset PID will be considered for autoselect. Also, ignore the program ID of external tracks, as it doesn't make much sense to compare PIDs from different files.
In CI, ffmpeg chooses vp9 by default, which cannot be muxed into mpegts.
47ead65 to
9f7a3c3
Compare
|
So my first attempt at limiting track selection to matching PID actually broke
|
kasper93
left a comment
There was a problem hiding this comment.
LGTM, thanks!
We can iterate on remaining issues in future changes.
This is a cleanup of track selection code with the aim to:
The changes are separated into multiple commits so that each commit can be reviewed individually. I ran the test suite (
meson test) after each commit.