summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-03-06 18:20:11 +0100
committerwm4 <wm4@nowhere>2020-03-06 18:20:11 +0100
commit7a76b577d85ddc8f9e255b1a1c195ee88b76a7d8 (patch)
treecf51a99eae3a5356680480a72c6fb81dbb7d8d91 /player
parentc6822b853d7475e8bf3b2c9f6823b7d74cf86950 (diff)
downloadmpv-7a76b577d85ddc8f9e255b1a1c195ee88b76a7d8.tar.bz2
mpv-7a76b577d85ddc8f9e255b1a1c195ee88b76a7d8.tar.xz
command: extend osd-overlay command with bounds reporting
This is more or less a minimal hack to make _some_ text measurement functionality available to scripts. Since libass does not support such a thing, this simply uses the bounding box of the rendered text. This is far from ideal. Problems include: - using a bitmap bounding box - additional memory waste and/or flushing caches - dependency on window size - odd small deviations with different window sizes (run osd-test.lua and resize the window after each timer update; the bounding boxes aren't adjusted in an overly useful way) - inability to query the size _after_ actual rendering But I guess it's a start. Since I'm aware that it's crap, add a threat to the manpage that this may be changed/removed again. For now, I'm interested whether anyone will have use for it in its current form, as it's an often requested feature.
Diffstat (limited to 'player')
-rw-r--r--player/command.c17
-rw-r--r--player/lua/defaults.lua2
2 files changed, 18 insertions, 1 deletions
diff --git a/player/command.c b/player/command.c
index 2ac6add009..334a25c087 100644
--- a/player/command.c
+++ b/player/command.c
@@ -4106,6 +4106,7 @@ static void cmd_osd_overlay(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
+ double rc[4] = {0};
struct osd_external_ass ov = {
.owner = cmd->cmd->sender,
@@ -4115,9 +4116,23 @@ static void cmd_osd_overlay(void *p)
.res_x = cmd->args[3].v.i,
.res_y = cmd->args[4].v.i,
.z = cmd->args[5].v.i,
+ .hidden = cmd->args[6].v.i,
+ .out_rc = cmd->args[7].v.i ? rc : NULL,
};
osd_set_external(mpctx->osd, &ov);
+
+ struct mpv_node *res = &cmd->result;
+ node_init(res, MPV_FORMAT_NODE_MAP, NULL);
+
+ // (An empty rc uses INFINITY, avoid in JSON, just leave it unset.)
+ if (rc[0] < rc[2] && rc[1] < rc[3]) {
+ node_map_add_double(res, "x0", rc[0]);
+ node_map_add_double(res, "y0", rc[1]);
+ node_map_add_double(res, "x1", rc[2]);
+ node_map_add_double(res, "y1", rc[3]);
+ }
+
mp_wakeup_core(mpctx);
}
@@ -5927,6 +5942,8 @@ const struct mp_cmd_def mp_cmds[] = {
OPT_INT("res_x", v.i, 0, OPTDEF_INT(0)),
OPT_INT("res_y", v.i, 0, OPTDEF_INT(720)),
OPT_INT("z", v.i, 0, OPTDEF_INT(0)),
+ OPT_FLAG("hidden", v.i, 0, OPTDEF_INT(0)),
+ OPT_FLAG("compute_bounds", v.i, 0, OPTDEF_INT(0)),
},
.is_noisy = true,
},
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index 7681ca173e..395ca87e03 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -614,7 +614,7 @@ function overlay_mt.update(ov)
cmd.name = "osd-overlay"
cmd.res_x = math.floor(cmd.res_x)
cmd.res_y = math.floor(cmd.res_y)
- mp.command_native(cmd)
+ return mp.command_native(cmd)
end
function overlay_mt.remove(ov)