summaryrefslogtreecommitdiffstats
path: root/sub
Commit message (Collapse)AuthorAgeFilesLines
* sub: add flag if sub_bitmap should be rendered in video color spaceKacper Michajłow2024-03-025-4/+7
|
* sd_ass: fix use-after-free in ft->event_formatDudemanguy2024-02-291-1/+1
| | | | | | | | | | | | | 0b35b4c91796fb020e13d955efd450021eb5eedb originally introduced sd_filter to make a more general subtitle filter infrastructure. But when doing so, it directly sets ft->event_format to ass_track->event_format in the struct. The lifetime of ass_track and the sd_filter are not equivalent which makes it easy to trigger undefined behavior. Notably, commit cda8f1613ff307a9e0b5528743f3e941b05dcee7 introduced assobjects_destroy which can destroy ass_track anytime during runtime which means that the string in ft->event_format is actually freed and should never be used. Remedy this by simply doing a proper strdup when the filter inits with ft as the parent so we avoid this scenario altogether. Fixex #13525.
* sd_ass: don't wrongly recognize \pos as \pChristoph Heinrich2024-02-271-1/+1
| | | | | | An ass event like `{\p1\pos{1,1}}m 0 0 l -3 -7 l 11 -7 l 11 -2` ends the drawing mode started with `\p1` due to `\pos` gets confused with `\p`, and thus that line is wrongly considered to be visible text.
* osd_libass: update the OSD bar's dent and border sizeGuido Cella2024-02-261-1/+1
| | | | | Make the OSD bar markers bigger so we can default to a smaller, better-looking border size, without sacrificing markers' visibility.
* sub: fix LRC lines with multiple timestampsGuido Cella2024-02-251-8/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | LRC subtitles can have lines with multiple timestamps, e.g. [00:00.00][00:02.00]foo [00:01.00]bar Currently mpv shows only the "foo" that was decoded first, because it compares the packet file position to check if a packet was already seen, and it is the same for both occurrences of "foo". Fix this by also comparing the pts. This keeps comparing the packet position on top of the pts to not break subtitle lines with the same timestamp, like: 1 00:00:00,000 --> 00:00:01,000 foo 2 00:00:00,000 --> 00:00:01,000 bar where mpv shows both lines on top of each other. They are common in ASS subtitles. Fixes https://github.com/mpv-player/mpv/issues/13497.
* command: fix sub-seek while paused without a videoGuido Cella2024-02-231-0/+1
| | | | | | | When using sub-seek without a video track while paused, adding the 0.01 SUB_SEEK_OFFSET to the new timestamp is not enough to show the new subtitle line. Add 0.1 instead to fix it. 0.01 is already enough for sub-step.
* player/sub: attempt to detect animated subtitlesDudemanguy2024-02-152-7/+78
| | | | | | | | | | | The previous commits optimized sub redrawing on still images/terminal so mpv wouldn't redraw so much. There is a gap though. It only assumes static subtitles. Since ASS can be animated, those types of subtitles will always need redraws so we need to build in specific detection for this. We need to build a whitelist of events in ASS that are considered animations and then flag the packet. Additionally, there's a bunch of annoying bookkeeping that has to be done since packets can be dropped on seeks and so on.
* player/sub: avoid wasteful subtitle redrawsDudemanguy2024-02-154-10/+59
| | | | | | | | | | | | | | | | | This only affects two special cases: printing subtitles to the terminal and printing subtitles on a still picture. Previously, mpv was very dumb here and spammed this logic on every single loop. For terminal subtitles, this isn't as big of a deal, but for the image case this is pretty bad. The entire VO constantly redrew even when there was no need to which can be very expensive depending on user settings. Instead, let's rework sub_read_packets so that it also tells us whether or not the subtitle packets update in some way in addition to telling us whether or not to read more. Since we cache all packets thanks to the previous commit, we can leverage this information to make a guess whether or not the current subtitle packet is supposed to be visible on the screen. Because the redraw now only happens when it is needed, the mp_set_timeout_hack can be removed.
* dec_sub: expand sub packet cachingDudemanguy2024-02-151-18/+21
| | | | | | | | | | | Previously, mpv only saved a strict limit of two packets while decoding subtitles, but it is a bit incomplete. Firstly, it's certainly possible for there to be more than two subtitles visible at once. And also, it did not take into account preloading. Rework this mechanism so that it is a growable array that can store as many packets as we want. Note that in this commit, the packets are only ever discarded on reset or destroy, so in theory it could grow forever. Some discarding logic will be added in the next commit since it is inherently tied to other things.
* sub: allow setting lavc txt_page special values via teletext_pageMohammad AlSaleh2024-02-131-3/+9
| | | | | | | | * Range of accepted values for teletext_page now include 0 and -1. * 0 means "subtitle" and -1 means "*". * Make 0 the default. Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
* sd_lavc: support secondary subs properlyDudemanguy2024-02-081-3/+3
| | | | | | | | | | | | | | Before 3250f6e4473b6c0ba1be03af3c80f3141b485721, secondary subtitles didn't work properly with sd_lavc at all. They would render but be in the same position as the primary subtitles. sd_ass used SD_CTRL_SET_TOP to specifically place secondary subtitles in a different spot, but it was unused by sd_lavc. With that above mentioned commit, it became possible to distinguish between the position of primary and secondary subtitles via mpv's option system. sd_lavc was missed however because at the time we simply didn't realize this could work and was actually simple. With some subsequent refactoring that happened later, the fix is to just use the correct sd->order when accessing the shared subtitle options instead of hard coding 0. Fixes #13440.
* 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
| | | | | | | | | | | | | | | | | <