Skip to content

Commit

Permalink
vo: add --video-recenter
Browse files Browse the repository at this point in the history
This resets ``--video-align-x`` and ``--video-align-y`` to 0 when the
video becomes smaller than the OSD in the respective direction, e.g. by
zooming out.

Unlike doing this by observing osd-dimensions in a script, this is done
before rerendering, so you don't see the image being rendered not
centered for an instant after zooming out before being rerendered
centered.

Defaults to yes.
  • Loading branch information
guidocella committed Nov 16, 2024
1 parent 1c3f092 commit d2662c3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions DOCS/interface-changes/video-recenter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `--video-recenter` option
26 changes: 20 additions & 6 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1652,17 +1652,31 @@ Video
``--keepaspect=no`` is used.

``--video-align-x=<-1-1>``, ``--video-align-y=<-1-1>``
Moves the video rectangle within the black borders, which are usually added
to pad the video to screen if video and screen aspect ratios are different.
``--video-align-y=-1`` would move the video to the top of the screen
(leaving a border only on the bottom), a value of ``0`` centers it
(default), and a value of ``1`` would put the video at the bottom of the
screen.
When the video is bigger than the OSD, these move the displayed rectangle to
show different parts of the video. ``--video-align-y=-1`` would display the
top of the video, ``0`` would display around the center (default), and ``1``
would display the bottom.

When the video is smaller than the OSD and ``--video-recenter`` is disabled,
these move the video rectangle within the black borders, which are usually
added to pad the video to screen if video and screen aspect ratios are
different. ``--video-align-y=-1`` would move the video to the top of the
screen (leaving a border only on the bottom), ``0`` would center it, and
``1`` would put the video at the bottom of the screen.

If video and screen aspect match perfectly, these options do nothing.

Unlike ``--video-pan-x`` and ``--video-pan-y``, these don't go beyond the
video's boundaries or make the displayed rectangle drift off after zooming.

This option is disabled if ``--keepaspect=no`` is used.

``--video-recenter=<yes|no>``
Whether to reset ``--video-align-x`` and ``--video-align-y`` to 0 when the
video becomes smaller than the OSD in the respective direction

Default: yes.

``--video-margin-ratio-left=<val>``, ``--video-margin-ratio-right=<val>``, ``--video-margin-ratio-top=<val>``, ``--video-margin-ratio-bottom=<val>``
Set extra video margins on each border (default: 0). Each value is a ratio
of the window size, using a range 0.0-1.0. For example, setting the option
Expand Down
2 changes: 2 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ static const m_option_t mp_vo_opt_list[] = {
{"video-crop", OPT_RECT(video_crop), .flags = UPDATE_IMGPAR},
{"video-unscaled", OPT_CHOICE(unscaled,
{"no", 0}, {"yes", 1}, {"downscale-big", 2})},
{"video-recenter", OPT_BOOL(recenter)},
{"wid", OPT_INT64(WinID)},
{"screen", OPT_CHOICE(screen_id, {"default", -1}), M_RANGE(0, 32)},
{"screen-name", OPT_STRING(screen_name)},
Expand Down Expand Up @@ -250,6 +251,7 @@ const struct m_sub_options vo_sub_opts = {
.scale_x = 1.0f,
.scale_y = 1.0f,
.auto_window_resize = true,
.recenter = true,
.keepaspect = true,
.keepaspect_window = true,
.native_fs = true,
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef struct mp_vo_opts {
double window_scale;

bool auto_window_resize;
bool recenter;
bool keepaspect;
bool keepaspect_window;
bool hidpi_window_scale;
Expand Down
24 changes: 24 additions & 0 deletions video/out/vo.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,34 @@ static void read_opts(struct vo *vo)
mp_mutex_unlock(&in->lock);
}

static void recenter(struct vo* vo)
{
if (!vo->params || !vo->opts->recenter)
return;

struct mp_rect src, dst;
struct mp_osd_res dims = osd_get_vo_res(vo->osd);
mp_get_src_dst_rects(vo->log, vo->opts, vo->driver->caps, vo->params,
dims.w, dims.h, vo->monitor_par, &src, &dst,
&dims);

if (dims.ml + dims.mr > 0) {
vo->opts->align_x = 0;
m_config_cache_write_opt(vo->opts_cache, &vo->opts->align_x);
}
if (dims.mt + dims.mb > 0) {
vo->opts->align_y = 0;
m_config_cache_write_opt(vo->opts_cache, &vo->opts->align_y);
}
}

static void update_opts(void *p)
{
struct vo *vo = p;

if (m_config_cache_update(vo->opts_cache)) {
read_opts(vo);
recenter(vo);
if (vo->driver->control) {
vo->driver->control(vo, VOCTRL_VO_OPTS_CHANGED, NULL);
// "Legacy" update of video position related options.
Expand Down Expand Up @@ -599,6 +621,8 @@ static void run_reconfig(void *p)
vo->params = talloc_dup(vo, params);
mp_mutex_unlock(&vo->params_mutex);

recenter(vo);

if (vo->driver->reconfig2) {
*ret = vo->driver->reconfig2(vo, img);
} else {
Expand Down

0 comments on commit d2662c3

Please sign in to comment.