Commit Graph

845 Commits

Author SHA1 Message Date
norinoriko 68d9ed2572 sub/osd: adjust osd margins 2024-11-21 16:14:07 +01:00
nanahi 354ad7f27d sub/osd_libass: simplify osd bar variable names 2024-11-18 17:22:02 +01:00
nanahi 8612f802dd options: move OSD bar opts to a separate struct
Move them to a suboption so the suboption prefix can be
used.
2024-11-18 17:22:02 +01:00
nanahi e056ad374f options: move mp_sub_filter_opts to sd_ass.c
Also use sub-filter common prefix.
2024-11-18 17:22:02 +01:00
Kacper Michajłow a0d7265ce9 sub/osd/console/stats: use the same 1.65 outline size 2024-11-18 09:50:22 +01:00
Kacper Michajłow 8c3a7da619 sub/osd/console: adjust font sizes
The current OSD font size is excessively large, causing most
messages—except for very short ones to overflow horizontally.

I conducted testing across multiple devices of varying screen sizes and
under different scenarios. The adjusted font size strikes a good balance
for readability on non-high-DPI displays, while high-DPI displays should
utilize DPI scaling as needed.

Additionally, I compared the font sizes of subtitles and UI elements
across various VOD platforms, which generally use smaller font in most
cases.

The current sub font size was significantly larger than even PGS
subtitles, which are quite large on their own. Now, they are comparable.

The subtitle font size was chosen based on recommendations from the BBC
Subtitle Guidelines. It is set to 8% of the video height with a
recommended scaling factor of 0.67. Therefore, at 720p (the reference
size for mpv font scaling), the calculation is 8% * 0.67 * 720 = 38.592,
rounded down to 38. This value falls within the recommended scaling
range of x0.5–x1 for desktop PCs/Laptops and TVs (32"–42"). For more
information, see
https://www.bbc.co.uk/accessibility/forproducts/guides/subtitles/#Presentation-font-size.

OSD font size is smaller than font as those elements shouldn't be
distractful and only noticable when the user wants to look at them.

Outline size is set to 5.5% of font size.
2024-11-18 09:50:22 +01:00
Guido Cella d66ed2d8be sub/osd_libass: don't blur the osd-bar
High --osd-blur values break the osd-bar by not drawing the filled
portion, and even low values just make it look worse, so don't apply
--osd-blur to the osd-bar.
2024-11-09 12:44:05 +01:00
llyyr 22116734e7 sd_ass: introduce sub-ass-prune-delay
Disabled by default because it breaks sub-seek and playback in cases
where the user changes play-dir from + to - during runtime and past
"seen" events need to be re-rendered.

Available since dcc9eb722e
2024-11-03 05:23:41 +01:00
llyyr 9bf0c53763 sub/sd_ass: set ASS_OVERRIDE_BIT_BLUR if available
4df64d060a

Fixes: https://github.com/mpv-player/mpv/issues/14852
2024-11-03 05:12:34 +01:00
nanahi c6883c4a56 options: add option to control OSD bar marker style
This adds --osd-bar-marker-style option which can be used to
customize OSD bar marker style. In addition to the existing triangle
style, a new style option is added to draw markers as lines.
2024-10-26 20:02:04 +02:00
nanahi ea8ac49f11 options: add options to control OSD bar marker size
This adds --osd-bar-marker-scale and --osd-bar-marker-min-size
options which can be used to customize OSD bar marker size.
2024-10-26 20:02:04 +02:00
nanahi 085a816c80 osd_libass: rename marker size variable
The size won't be dent anymore once other marker styles are
added.
2024-10-26 20:02:04 +02:00
Guido Cella 4e4d6a16d8 osd_libass: fix integer overflow in osd_get_text_size()
If show-text ${playlist} is used with --osd-scale-by-window=no while
printing to the terminal or while mpv is starting, the out_screen_h
assignment in osd_get_text_size() causes runtime error: signed integer
overflow: 288 - -2147483648 cannot be represented in type 'int'. Fix
this by not making prepare_osd_ass() use an infinite playresy.

This prevents printing show-text ${playlist} without a line limit to the
terminal with --osd-scale-by-window=no, which makes only the last
playlist entries be printed, and the selected one is not printed if it
isn't among them. A later commit will make the line calculation
accurate.
2024-10-16 15:10:23 +02:00
Dudemanguy 77239b87f1 sub/sd_ass: handle subs with unknown durations on a per packet basis
A packet with an unknown duration flagged the entire context and then
this was saved forever throughout the entire lifetime of the object.
This inherently doesn't work with the redecoding sub logic which will go
through all the packets again. So the second time around, packets with
known durations get treated as if they were unknown and things go awry.
Rework this so it is per packet like it should be and not a global
state. Note that f9cefbfec4 originally
added this for specifically eia-608 subtitles but their packets are all
detected as unknown anyway due to the durations so this is not needed
anymore and interferes with other things.
2024-10-16 02:26:06 +00:00
Kacper Michajłow bf025cd289 msg: allow to truncate the message to terminal width 2024-10-11 15:16:33 +02:00
Kacper Michajłow 7202406fe8 various: remove global.h inclusion where not needed 2024-10-01 12:23:44 +02:00
Kacper Michajłow 71f2220991 meson: use relative file paths for file2string
This fixes "Generated from" comments to not include local source path in
generated files.
2024-09-21 23:39:10 +02:00
llyyr d02f03bc2b sub/sd_ass: don't override event attributes to mpv defaults
ASS_OVERRIDE_BIT_STYLE includes ASS_OVERRIDE_BIT_ATTRIBUTES, which we
don't want.

This prevents --sub-ass-override=force from overriding attributes such
as bold, italics, underline or strikeout to mpv defaults.
2024-09-15 20:10:51 +02:00
Kacper Michajłow ef19a4a09d sub/osd: add log if osd rendering takes too long time
Ideally it should be fast, it is on VO thread and steals precious frame
time budget. Looks like this is one of the main reasons why
display-resample on higher refresh rate displays is too slow.
2024-09-14 20:23:22 +02:00
Oneric 5357d18fe6 sub: add ass-video-aspect-override option
It is unclear whether there actually is any usecase for this option
which isn't better served by sub-ass-use-video-data and/or LayoutRes
overrides, but prior to the introduction of sub-ass-use-video-data
it was possible to pass along storage resolution while faking an
aspect ratio of 1:1.
sub-ass-video-aspect-override=1 combined with sub-ass-use-video-data=all
now makes this possible again.

The uper limit of a 10:1 aspect matches
the general video-aspect-override option.
2024-09-13 23:24:08 +02:00
Oneric 207b1a2c91 sub: merge vsfilter-aspect and vsfilter-blur-compat options
The naming for "blur-compat" was misleading since the setting
actually affects more than just blur affects. Additionally
forwarding storage resolution but forcing an aspect ratio
of 1.0 for the video is likely to result in odd rendering
and there’s no known usecase for it.

Both options control which video properties are exposed to libass
so to fix the aforementioned issues merge these settings into one
tri-state sub-ass-use-video-data.

The default V keybind now cycles through all states of
use-video-data instead of toggling vsfilter-aspect-compat.

Resolves: https://github.com/mpv-player/mpv/issues/10680
2024-09-13 23:24:08 +02:00
llyyr a0ebfc3462 sub: remove dead code 2024-09-03 18:31:38 +02:00
nanahi 07acdf09b3 sd_ass: fix margin y scale with font size
--sub-margin-y is documented to scale with font size, which is scaled
"by" or "with" window depending on the options. However, when using
ass_set_font_scale to change font size, the y margin isn't scaled, so it is
still scaled to video size. This causes the y margin size becoming smaller
when the video becomes smaller, even when the font size isn't changing.

Fix this by also scale the MarginV with the font scale. Also use lrint
instead of round.
2024-07-18 23:03:02 +02:00
nanahi 42e9f302df sd_ass: fix sub scale with window when use_margins is enabled
By default, libass scales subtitle with video size.
When --sub-scale-with-window is enabled, mpv attempts to undo this scale
and use window size instead. However, the current bahavior is incorrect
when use_margins is enabled, because in this case libass uses the size
of video as if it's "fit" to the window, instead of the displayed size.
As a result, subtitle scale is broken when video-zoom is used in this case:
when zooming out video, the subtitle is scaled up.

Fix this by using the correct factor when use_margins is enabled.
2024-07-18 23:03:02 +02:00
Misaki Kasumi f2e7146cb1 sub: add (sub/osd)-border-style; renaming sub options 2024-07-12 20:17:38 +00:00
Kacper Michajłow 7fb7e1dd73 various: add more format specifiers checks 2024-06-25 05:29:46 +02:00
Kacper Michajłow 687eb4c875 various: remove no longer needed availability checks
image_writer: remove jpegxl availability check

meson: remove check for lavu vulkan support

image_writer: remove avif availability check

ad_spdif: remove no longer needed definitions

demux_lavf: remove side data extraction compatibility code

demux/packet: remove ITU T.35 availability check

filters/f_lavfi: remove avfilter_filter_pad_count availability check

image_writer: remove PNG cICP support check

mp_image: remove AV_FRAME_DATA_DOVI_METADATA availability check

mp_image: remove AV_FRAME_FLAG_INTERLACED availability check

vd_lavc: remove ctx->pic->duration availability check

sws_utils: remove av_chroma_location_enum_to_pos availability check

vd_lavc: remove AV_CODEC_EXPORT_DATA_FILM_GRAIN availability check

demux_lavf: always use io_close2
2024-06-22 16:12:14 +02:00
Kacper Michajłow 94859997b8 sub: update codec info 2024-06-08 23:06:22 +02:00
Kacper Michajłow b0aa088bc4 sub/sd_ass: rewrite is_animated()
Using strchr should be faster as it is optimized for the job. Also
ensure that tags are not escaped and are within {} correctly. This also
is important for performance as it allows to scan only needed areas of
the string.

Co-authored-by: Avi Halachmi (:avih) <avihpit@yahoo.com>
Co-authored-by: rcombs <rcombs@rcombs.me>
2024-06-05 19:13:41 +02:00
Dudemanguy fa89082f2e sub: avoid unneeded calls to is_animated
4e5d996c3a added this as part of a series
of patches written to avoid wasteful sub redraws when playing a still
image with subs. The is_animated special case was specifically for ASS
subtitles that have animations/effects and would need repeated redraws
in the still image case. This check was done unconditionally for all ASS
subtitles, but for very big ASS subtitles, this text parsing can get a
bit expensive.

Because this function call is only ever needed for the weird edge case
of ASS subtitles over a still image, some additional logic can be added
to avoid calling is_animated in the vast majority of cases. The animated
field in demux_packet can be changed to a tristate instead where -1
indicates "unknown" (the default state). In update_subtitle, we can look
at the current state of the video tracks and decide whether or not it is
neccesary to perform is_animated and pass that knowledge to sd_ass
before any subtitle packets are decoded and thus save us from doing this
potentially expensive call.
2024-06-04 12:29:13 +00:00
llyyr f37691a156 options: move sub-ass-override 'scale' above 'force'
Also make it an enum for clarity

This is the right order in terms of both destructiveness and also the
total number of --sub-* options applied.
2024-05-29 17:48:50 +00:00
llyyr af7ab6f603 sd_ass: only set sub-scale for 'scale', 'force' or 'strip'
Currently we also set it for sub-ass-override=yes which is unintended
2024-05-29 17:48:50 +00:00
Guido Cella 646f31f196 sd_ass: don't log if subtitles have unknown duration
Users shouldn't have to care if subtitles' duration is unknown because
the only difference is that decode() sets a duration to packets without
one, if any.

The main difference was code intentionally breaking sub-seek, sub-step,
sub-start and sub-end for unknown duration subtitles for some reason,
but I removed it in 0f2370476b and 185fa9ffc6.

LRC subtitles always have unknown duration so if you use them having
this logged on every song is annoying, so only log it in verbose mode.
2024-05-05 13:59:41 +02:00
Matthias Hunstock 2414051d76 osd: show left arrow when playing backwards
If playback direction is backwards, display a triangle
pointing to the left as status symbol of OSD.
2024-05-05 13:47:20 +02:00
Matthias Hunstock 5631d83b5f tools: add narrow left arrow glyph for OSD
Add rotated arrow glyph on unused codepoint U+E00D.
2024-05-05 13:47:20 +02:00
nanahi dec73f503f sub/osd: fix rounding when rescaling bitmap subtitle rects
With multiple rects touching each other without any gaps, the current
scale method can cause gaps or overlaps between rects. To make sure that
this does not happen, scale on the edges of the rects instead, and then
calculate the width and height from the results.

NB: while this is better than the status quo, it does not fix all
scaling artifacts because of the following:

- When two rects share a vertical edge but have different heights,
  misalignment will occur: after rounding rect heights to pixels,
  the height scale factor for the two rects will be slightly different.
  As a result, there will be misalignment between the scaled images.
- With a GPU renderer, different bitmap subtitle parts are rendered as
  different textures. This means that the pixel contents of the parts have
  different boundary conditions from the whole combined image. As a result,
  there will still be small gaps when the subtitle is scaled up.

The only way to properly address these points is to make sure that the
parts are combined to a single image at the native resolution before
being scaled. This can be partly achieved with --blend-subtitles=video.
2024-05-03 16:16:53 +02:00
nanahi 91bb2f2543 sd_lavc: reduce unnecessary error log on probing nonexistent codecs 2024-05-03 16:13:07 +02:00
nanahi fc741dab1a sd_lavc: fix null dereference on error
If sub decoder does not exist, priv remains NULL.

Fixes: 1394e5a111
2024-05-03 16:13:07 +02:00
rcombs 99f1b2b7b4 player/command: add sub-text/ass-full sub-property
This is like sub-text/ass, but it returns a full ASS line, making it suitable for some more advanced scripting use-cases.
2024-04-27 01:19:56 +02:00
rcombs aa0a9ce2ec sd_ass: allow get_text to return more than 500 bytes 2024-04-27 01:19:56 +02:00
Kacper Michajłow f55d19e846 sub/lavc_conv: don't override style of converted teletext pages
This fixes teletext pages rendering, while keeping the same default
style for subtitles and other converted formats.
2024-04-27 01:14:23 +02:00
Kacper Michajłow d8378dc226 sub/lavc_conv: don't strip ASS style header
This fixes converted subtitles that are styled.

This reverts commit 5e2c211a4e.

Most of the subtitle decoders in libavcodec sets meaningful style
values. For the rest we can conditionally strip style.
2024-04-27 01:14:23 +02:00
Kacper Michajłow afae94cfbd dec_sub: fix locking for sub_ass_get_extradata
Fixes: 715feea8d8
2024-04-24 15:52:17 +02:00
llyyr 805577c792 sd_ass: add `sub-vsfilter-bidi-compat` to enable vsfilter bidi compat
Enable ASS_FEATURE_{WHOLE_TEXT_LAYOUT, BIDI_BRACKETS} and auto base
detection by default, and add an option to disable this if needed.

This is strictly an improvement for webvtt files as they always use
auto base detection. This _fixes_ right-to-left text rendering for
webvtt files which correctly mark rtl/ltr. Webvtt files obtained from
sources which sideload the RTL information through css also see an
improvement due to the auto detection.

Generally SRT files also want this, but some are also written to
workaround VSFilter quirks.

See also: https://github.com/mpv-player/mpv/pull/12985#issuecomment-1839565138
2024-04-18 00:14:44 +02:00
llyyr f862d3b6cd sd_ass: fix margins for all styles when overriding PlayResX
Also save old playresx and use it instead of assuming values of things
we know.
2024-04-18 00:14:44 +02:00
llyyr d2efa1c1be sd_ass: replace ifdef with explicit version check 2024-04-18 00:14:44 +02:00
nanahi 715feea8d8 dec_sub: fix locking for sub_ass_get_extradata
sub->sd can be destroyed and recreated when update_segment is called
inside a lock.

Fixes: f9918b5390
2024-04-17 23:42:35 +02:00
nanahi b7ad0968ad dec_sub: don't use recursive mutex
92a9f11a0b added locking for dec_sub.
At that time, because the lock was exposed to the outside world,
a recursive mutex was used. However, this is no longer true after
e9e883e3b2, when the public locking
functions were removed. This means that the lock is now private.

Unlike input.c, dec_sub already enforces said call hierarchy, so
combined with the aforementioned change, the lock is only ever
called once and never recursively. Thus the lock can be converted to
a normal mutex.
2024-04-17 23:42:35 +02:00
nanahi e731972163 dec_sub: fix locking for sub_is_{primary,secondary}_visible
These public functions should use locks to keep its usage
consistent with input.c.

Fixes: 024e0cd4c1
2024-04-17 23:42:35 +02:00
Kacper Michajłow 1394e5a111 sub/sd_lavc: check decoder output type for dvb and arib
Depending on the options:
For AV_CODEC_ID_ARIB_CAPTION this allows using bitmap output.
For AV_CODEC_ID_DVB_TELETEXT this allows using text output.

Fixes: #13471
2024-04-17 23:41:30 +02:00