summaryrefslogtreecommitdiffstats
path: root/sub
Commit message (Collapse)AuthorAgeFilesLines
* all: add missing repr assignmentsKacper Michajłow2024-01-262-0/+5
| | | | Fixes: 66e451f4
* csputils: replace more primitives with pl_Kacper Michajłow2024-01-221-4/+4
| | | | | We can go deeper, but need to stop somewhere to not reimplement vo_gpu using libplacebo...
* csputils: replace mp_chroma_location with pl_chroma_locationKacper Michajłow2024-01-221-1/+1
|
* csputils: replace mp_alpha_type with pl_alpha_modeKacper Michajłow2024-01-222-7/+7
|
* csputils: replace mp_colorspace with pl_color_spaceKacper Michajłow2024-01-222-35/+35
|
* sub: add `--sub-lavc-o` optionMohammad AlSaleh2024-01-211-0/+3
| | | | | | | We have `--vd-lavc-o` and `--ad-lavc-o`, but no equivalent option for subtitles. Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
* sub: fix sub-seek and sub-step -1 with unknown duration subsGuido Cella2024-01-201-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | f9cefbfec4 made it so mp_ass_flush_old_events() is continously called on subtitles with unknown duration, without explaining why, breaking sub-seek/step -1 with a VO (the issue does not occur when showing subtitles in the terminal because get_bitmaps() is not called). I don't experience any issue after removing the call, so delete it to fix these commands. After removing that, you can sub-seek -1 once after regular playback, but not after seeking and thus not multiple times in a row. This is caused by a714f8e928 which fixed subtitles with unknown duration being duplicated when seeking with a VO (it does not happen in the terminal) by clearing old lines on seeks, which broke sub-seek -1 and sub-step -1 in a second way after any seek. The proper fix is to remove the line ctx->num_seen_packets = 0 for subtitles with unknown duration instead, which lets decode() return early when a line has already been shown. Having removed these 2 lines, I also removed sd->preload_ok = false, and thus the whole conditional, since according to sub/sd.h preload_ok only needs to be set to false when old subtitles are discarded, and they are no longer discarded, The bug can be reproduced with mpv --sub-file=<(curl 'https://music.xianqiao.wang/neteaseapiv2/lyric?id=1399616170' | jq -r .lrc.lyric) 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
* filter_sdh: optimize get_char_bytesDudemanguy2024-01-151-5/+5
| | | | | | | strlen is only relevant if the length is less than [1, 4], so this can be replaced with strnlen instead which will only traverse characters upto the maxlen insted of the entire string length. It also makes MPMIN unneeded. Also fix a comment.
* filter_sdh: fix incorrect placement of null terminatorDudemanguy2024-01-121-1/+1
| | | | | | | The +1 here is not correct. For a 4-byte unicode character, this would throw a runtime error because the +1 would try to assign the null terminator past the actual bound of our array. Just remove it since it should be exactly equal to whatever we have for bytes.
* filter_sdh: sanitize get_char_bytes heuristic to avoid overflowDudemanguy2024-01-121-4/+4
| | | | | | | | | | | There's a simple check in filter_sdh that gets the bytes of the first character in a string in order to do pointer arthimetic to filter the string. The problem is that it is possible for the amount of bytes to be greater than the actual length of the string for certain unicode characters. This can't be worked with so enforce the strlen as the absolute minimum here to avoid overflow situations. Fixes #13237.
* options: add --secondary-sub-ass-overridedyphire2023-12-184-23/+28
| | | | Default: strip. preserve the old behavior
* sd_ass: remove unneeded ontop variableDudemanguy2023-12-161-6/+1
| | | | | | | Missed in 3250f6e4473b6c0ba1be03af3c80f3141b485721. Note that the hardcoded ass alignment value is not used anymore as of that commit, but we should ideally be moving towards secondary subs actually being customizable via ASS anyways.
* player: refactor secondary subtitle options and propertiesDudemanguy2023-12-164-8/+17
| | | | | | | | | | | | Over the years, we've accumulated several secondary subtitle related options and properties, but the implementation was not really consistent and it wasn't clear what the right process for adding more should be. So to make things nicer, let's refactor all of the subtitle options with secondary variants (sub-delay, sub-pos, and sub-visibility) and split them off to a new, separate struct. All of the underlying values are stored in an array instead for simplicity. Additionally, the implementation of some secondary-sub-* properties were slightly changed so there would be less redundancy.
* options: add --secondary-sub-poskarelrooted2023-12-135-13/+8
| | | | The default value is 0 (on the top of the screen)
* filter_sdh: add full width parentheses to the enclosures stringDudemanguy2023-12-081-5/+7
| | | | | Since these are technically parentheses, we'll treat them the same way as normal parenthesis. Fixes #11155.
* filter_sdh: add --sub-filter-sdh-enclosures optionDudemanguy2023-12-081-10/+62
| | | | | | | | | | | This filter is a bit complicated, but one of the essential parts of it is removing text enclosed by particular set of characters (e.g. text inbetween []). This was previously hardcoded to only take into account parenthesis and brackets, but people may want to filter more things so make this customizable. The option only takes "left hand characters" so the right pair is mapped internally if applicable. If not, then we just use the same character. Fixes #8268 since the unicode character in question can just be passed to this option.
* filter_sdh: combine skip_bracketed and skip_parenthesizedDudemanguy2023-12-081-67/+28
| | | | | | | | | | These two functions are almost exactly the same. The parenthesis variant is essentially just a special case with more conditions to not remove text. These can easily be combined together into one generic skip_enclosed function to handle both cases. We also use char * instead of char for the character comparison here since not everything is neccesarily 1 byte and can fit into a char. This will be useful for the following commits where we extend this logic further.
* options: add --osd-bar-border-sizeGuido Cella2023-11-271-6/+1
| | | | | Closes #1484. The default size is smaller than the previous --osd-border-size default value of 3 with the default --osd-bar-h.
* options: add secondary-sub-delayRipose2023-11-261-3/+6
| | | | | | | | | | | | | Add --secondary-sub-delay option and decouple --sub-delay from secondary subtitles. This produces desirable behavior in most cases as secondary and primary subtitles tracks tend to be timed independently of one another. This feature is implemented by turning the sub_delay field in mp_subtitle_opts into an array of 2 floats. From here the track index is either passed around or derived when sub_delay is needed. There are some cases in dec_sub.c where it is possible for dec_sub.order (equivalent to track index) to be -1. In these cases, sub_delay is inferred as 0.
* various: replace some OOM handlingsfan52023-11-241-1/+2
| | | | | | We prefer to fail fast rather than degrade in unpredictable ways. The example in sub/ is particularly egregious because the code just skips the work it's meant to do when an allocation fails.
* sub: add --sub-stretch-durations optionMohammad AlSaleh2023-11-071-1/+2
| | | | | | | | | Stretch a subtitle duration so it ends when the next one starts. Should help with subtitles which erroneously have zero durations. I found such a subrip substitles stream in the wild. Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
* sub: adjust offsets when sub seeking/steppingDudemanguy2023-11-062-1/+4
| | | | | | | | | | | | | | | | | | | | | In the sub seek code path, there was an arbitrary small offset added to the pts before the seek. However when seeking backwards, the offset was an additional subtraction. de6eace6e984be3cd2515e9be6362a0cf04b7457 added this logic 10 years ago and perhaps it made sense then, but the additional subtraction when seeking backwards causes the subtitle seek to go too far to the previous subtitle if the durations overlap. This should always be an addition to work correctly. Additionally, the sub stepping code path also could use this offset for the same reason (duration overlaps). However, it is only applicable to sd_ass not sd_lavc. sd_lavc has step_sub support but on a sample it didn't even work anyway. Perhaps it only works for certain kinds of subtitles (patches welcome). Anyways instead of keeping this offset as a magic number, we can define it in sd.h which is handy for this. For sd_ass, we add the offset when sub stepping, and the offset is always added for sub seeking like it was before. Update the comment to be a little more relevant to what actually happens today. Fixes #11445.
* dec_sub: always copy packet for new segmentsDudemanguy2023-11-061-1/+1
| | | | | | | | | | | Since 062104d16e34f348ffd9324ca4c997b6b0f487d4, we started saving cached packets for subtitles. However, these can point to the same address as what is stored in sub->new_segment. When a segment is updated, the packet is potentially freed. Later during decoding, this can lead to a double free since the cached packets will naturally try to free itself and update. Fix this by simply always making sub->new_segment a full copy of the packet so its lifetime doesn't have to be tied to the cached packet stuff.
* ALL: use new mp_thread abstractionKacper Michajłow2023-11-054-62/+61
|
* sub: redecode cached packets on UPDATE_SUB_HARD or UPDATE_SUB_FILTDudemanguy2023-11-053-5/+27
| | | | | | | | | | | | | | | | UPDATE_SUB_HARD causes all of the ass objects to reset in order to apply the new style. UPDATE_SUB_FILT doesn't actually reset the sd, but it should in order to update the actual filters so that was added here. Doing this causes the current subtitle to be dropped. In the paused cause, this concidentally works because command.c forces a video refresh which then reloads the subtitle essentially. But while playing, the subtitle will be dropped and you won't get anything until the next one appears. Instead of using video refreshes, what we can do is just always save the last two subtitle packets in a cache and redecode them if needed. This is much easier and also allows us to get rid of all the video refresh logic in command.c. Fixes #12386.
* options: rename --sub-ass-force-style to --sub-ass-style-overridesDudemanguy2023-10-251-4/+4
| | | | | | | This option has exactly the same semantics are other mpv options that override a particular thing with something from the user. So instead of the "force-style" name, use "-overrides" which is more consistent. The plural form is used since it's a list option.
* various: sort some standard headersNRK2023-10-201-1/+1
| | | | | | | | | | | | since i was going to fix the include order of stdatomic, might as well sort the surrouding includes in accordance with the project's coding style. some headers can sometime require specific include order. standard library headers usually don't. but mpv might "hack into" the standard headers (e.g pthreads) so that complicates things a bit more. hopefully nothing breaks. if it does, the style guide is to blame.
* various: remove ATOMIC_VAR_INITNRK2023-10-201-1/+1
| | | | | | | | | | | the fallback needed it due to the struct wrapper. but the fallback is now removed so it's no longer needed. as for standard atomics, it was never really needed either, was useless and then made obsolete in C17 and removed in C23. ref: https://gustedt.wordpress.com/2018/08/06/c17-obsoletes-atomic_var_init/ ref: https://en.cppreference.com/w/c/atomic/ATOMIC_VAR_INIT
* osdep: remove atomic.hNRK2023-10-201-2/+2
| | | | | | | replace it with <stdatomic.h> and replace the mp_atomic_* typedefs with explicit _Atomic qualified types. also add missing config.h includes on some files.
* sd_ass: enable sub-start and sub-end with unknown duration subsGuido Cella2023-10-061-1/+1
| | | | | | | The function called to get sub-start and sub-end returns early when the subtitle's duration is unknown, but by just removing this check the properties work fine. The final sub line has a very large sub-end, but that is much better than not having the properties work at all.
* Revert "demux: improve stream selection state"Dudemanguy2023-09-302-3/+3
| | | | | | | | The stream selection state wasn't improved. I didn't realize this messed with caches. All in all, just not a good idea. Back to drawing board I guess. This reverts commit f40bbfec4fcd2d9a787a4d98ec7698a646e5607e.
* demux: improve stream selection stateDudemanguy2023-09-272-3/+3
| | | | | | | | | | | | | | | | | | | | | | | This replaces the previous commit and makes more sense. The internal demux marked tracks as eager depending on their type and for subtitles it would always lazily read them unless there happened to be no available av stream. However, we want the sub stream to be eager if the player is paused. The existing subtitle is still preserved on the screen, but if the user changes tracks that's when the problem occurs. So to handle this case, propagate the mpctx->paused down to the stream selection logic. This modifies both demuxer_refresh_track and demuxer_select_track to take that boolean value. A few other parts of the player use this, but we can just assume false there (no change in behavior from before) since they should never be related to subtitles. The core player code is aware of its own state naturally, and can always pass the appropriate value so go ahead and do so. When we change the pause state, a refresh seek is done on all existing subtitle tracks to make sure their eager state is the appropriate value (i.e. so it's not still set to eager after a pause and a track switch). Slightly invasive change, but it works with the existing logic instead of going around it so ultimately it should be a better approach. We can additionally remove the old force boolean from sub_read_packets since it is no longer needed.
* Revert "demux: eagerly read subtitle streams when switching tracks while paused"Dudemanguy2023-09-271-1/+1
| | | | | | | Actually, I thought of a better way of handling this shortly after merging this. Revert it and redo it in the next commit. This reverts commit c2c157ebeca3d072d4f48ff36228d01ebe888699.
* demux: eagerly read subtitle streams when switching tracks while pausedDudemanguy2023-09-271-1/+1
| | | | | | | | | | | | | | | | | a323dfae426e43451f4d3e08a9a63cb7d1c1ace9 almost fixed subtitle tracks disappearing when paused but it actually missed one part: the behavior of demux_read_packet_async_until. It's a bit unintuitive, but for subtitle streams, that function would only return the very first packet regardless of whatever pts you pass to it. So the previous commit worked on the very first subtitle, but not actually any of the others (oops). This is because subtitle streams never marked as eager and thus never actually read farther ahead. While the video is playing, this is OK, but if we're paused and switching subtitle tracks then the stream should be eagerly read. Luckily, the logic is already there in the function for this. All we have to do add an extra argument to demux_read_packet_async_until to force the stream to be read eagerly and then it just works. Be sure to unset the eager flag when we're done. Actually fixes the bug for real this time.
* sub/ass_mp: filters/f_lavfi: forward declare mp_logllyyr2023-09-211-0/+1
|
* sd_ass: use directive instead of writing magic constantsllyyr2023-09-212-7/+9
| | | | Also improve comment about the assumed PlayResX and PlayResY
* sd_lavc: fix subtitle presentation timeKacper Michajłow2023-09-111-13/+1
| | | | | | | | Packet duration is not necessarily related to the display time of the subtitle. Use start/end_display_time fields as source of the timing. Fixes subtitles with infinite duration that should be on screen until next sub is displayed.
* Revert "sub: add auto option to --sub-fix-timing"Kacper Michajłow2023-09-111-1/+1
| | | | This reverts commit b47a58516af2c36e66c3987748b5b4a1275ed9e7.
* sd_lavc: account for floating point inaccuracyKacper Michajłow2023-09-091-1/+1
| | | | | | | | Timestamps are converted from microsecond resolution timestamp, we don't have more precision, so we have to account for that when comparing the floating point values as them will slightly be off. Fixes: #12327
* sub: add auto option to --sub-fix-timingDudemanguy2023-09-071-1/+1
| | | | | | | | | Third try is the charm? I stupidly missed that this option already existed in my previous commits. Instead, add an auto value to it and enable it by default for sd_lavc but not sd_ass. On my limited samples, it seems to fix the gaps issue that can occur but without regressing some duration timings for sub_lavc subtitles. Well hopefully anyway. Fixes #12327.
* Revert "sd_lavc: use SUB_GAP_THRESHOLD for overlaps/gaps"Dudemanguy2023-09-071-2/+2
| | | | | | | | | Yet another bad idea. It turns out that there's already a sub-fix-timing option which logic for this exact thing (overlaps/gaps) fixing. Also it works better than this since it doesn't appear to artifically increase sub duration either. Fixes #12327. This reverts commit 725b631ec3bdd5016072b5a6aa6a218fb87ffd11.
* player: rename --sub-forced-only to --sub-forced-events-onlyDudemanguy2023-08-292-2/+2
| | | | | | | | The old name is pretty bad and users mistakenly think it has something to do with selecting forced subtitles (that would be --subs-fallback-forced). Instead of giving it such a generic name, make it clearer that this has to do specifically with forced sub events which is only relevant for a small minority of subtitles.
* player: remove auto choice from sub-forced-onlyDudemanguy2023-08-294-9/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | First of all, this never worked. Or if it ever did, it was in some select few scenarios. c9474dc9ed6172a5f17f66f4b7d367da6b077909 is what originally added support for the auto choice. However, that commit worked by propagating a value to a fake option used internally. This shouldn't have ever worked because the underlying m_config_cache was never updated so the value shouldn't have been preserved when accessed in sd_lavc. And indeed with some testing, the value there is always 0 unsurprisingly. This was later rewritten in ba7cc071068f4f57ae354e77f64552712fda6855 along with a lot of other sub changes, but with that, it was still mostly broken. The reason is because one of the key parts of having to hit this logic (prefer_forced) required `--no-subs-with-matching-audio` to be set. If the audio language matches the subtitle language (the requirement also excludes forced subs), the option makes no subtitle selection in the first place so pick->forced_only_def is not set to true and nothing even happens. Another way around this would be to attempt to change your OS language (like with the LANG environment variable) so that the subtitle track gets selected but then audio_matches mistakenly becomes false because it compares the OS language to the audio language which then make preferred_forced 0, so nothing happens. I don't think there's a scenario where pick->forced_only_def is actually set to true (thus meaning `auto` is useless), but maybe someone could contrive something very strange. Regardless, it's definitely not something even remotely common. fbe8f9919428a7ed24a61899bfd85bbb7680e389 changed track selection again but didn't consider this particular case. The net result is that DVD/PGS subs become equivalent to --sub-forced-only being yes, so this a change in behavior and probably not a good one. Note that I wasn't able to actually observe any difference in a PGS sample. It still displayed subtitles fine but that sample probably didn't have the right flags to hit the sub-forced-only logic. Anyways, the auto feature is extremely questionable at best and in my view, not actually worth it. It is meant to be used with `--no-subs-with-matching-audio` to display forced pictures in subtitle tracks that are not marked as forced, but that contradicts that particular option's purpose and description in the manual (secretly selecting a track under certain conditions even though it says not to). Instead of trying to shove all this logic into select_default_track which is already insanely complicated as it is, recognize that this is a trivial lua script. If you absolutely want to turn --sub-forced-only on under these certain conditions (DVD/PGS subtitles, matching audio and subtitle languages, etc.), just look at the current-tracks property and do your thing. The very, very niche behavior that this option tried to accomplish basically never worked, no user even knows what this option does, and well it's just not worth supporting in core mpv code. Drop all this code for sanity's sake and change --sub-forced-only back to a bool.
* command: add `sub-ass-extradata` propertyllyyr2023-08-272-0/+10
|
* sub/osd: signal osd_changed on resizellyyr2023-08-251-0/+1
| | | | | We should update the osd when the window is resized, previously we weren't signalling for an update.
* sd_lavc: use SUB_GAP_THRESHOLD for overlaps/gapsDudemanguy2023-08-191-2/+2
| | | | | | | It turns out this already exists for sd_ass and is being used there. We can make use of this arbitrary threshold instead for overlapping subtitle durations to avoid the weird flashing behavior with some pgs subtitles.
* Revert "sub/sd_lavc: don't check endpts when getting subs"Dudemanguy2023-08-191-1/+2
| | | | | | This reverts commit 02a80f850b5403da89fefed7b32b3f3dfb82f647. Bad idea. This causes subs to stay on the screen too long in some cases. Let's try something else to fix the problem.
* player: make sub-pos a float valueDudemanguy2023-08-132-4/+4
| | | | | | | | mpv makes this option an integer, but the underlying ass API actually accepts doubles. From some testing, there is no meaningful precision difference between float or double (it seems to go in roughly 0.05 steps), so just make it a float. sd_lavc also can handle non-integer values here. Closes #11583.
* sub/sd_lavc: don't check endpts when getting subsDudemanguy2023-08-111-2/+1
| | | | | | | | | | | | | | | | When getting subtitles, sd_lavc checks if the current pts plus a small offset (1e-6) is greater than the sub->pts as well as checking if the pts is less than the sub->endpts. The problem with the endpts check is that there are subtitles out there (pgs ones) that have overlapping durations and thus you'll get a case where pts is greater than endpts because a new subtitle shows up. However, the old subtitle is still meant to be on the screen. This results in a flickering effect where the subtitle flashes and then appears the next frame. The easy enough fix is to just loosen the condition and remove the endpts check altogether. That ensures that the subtitle remains selected for the entire duration. Unsure if this possibly could regress some other kind of subtitle out that that uses sd_lavc, but this does appear to fix a real issue with pgs subtitles. Fixes #8202 and #10051.
* sub: fix switching tracks while pausedDudemanguy2023-08-112-3/+3
| | | | | | | | Internal subtitles were not shown when switching between tracks while mpv was paused. The reason for this is simply because the demuxer data isn't available yet when the track switch happens. Fixing it is basically just retrying until the packet is actually available when the player is paused. Fixes #8311.
* build: remove outdated generated directoryDudemanguy2023-07-312-1/+7
| | | | | | | | | | | | | | | | This only existed as essentially a workaround for meson's behavior and to maintain compatibility with the waf build. Since waf put everything in a generated subdirectory, we had to put make a subdirectory called "generated" in the source for meson so stuff could go to the right place. Well now we don't need to do that anymore. Move the meson.build files around so they go in the appropriate place in the subdirectory of the source tree and change the paths of the headers accordingly. A couple of important things to note. 1. mpv.com now gets made in build/player/mpv.com (necessary because of a meson limitation) 2. The macos icon generation path is shortened to TOOLS/osxbundle/icon.icns.inc.
* draw_bmp: fix overflowing coordinates in mark_rcsDudemanguy2023-07-301-1/+2
| | | | | | | | | | | | | | | | This is yet another unfortunate side effect of the width % SLICE_W == 0 special case. While looping throu