From 6ea08be59ac503f7309a19a50d5e664426e8c9f3 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Thu, 10 Aug 2023 15:51:44 -0500 Subject: [PATCH] player: make sub-pos a float value 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. --- DOCS/interface-changes.rst | 1 + options/options.c | 2 +- options/options.h | 2 +- player/command.c | 2 +- sub/sd_ass.c | 4 ++-- sub/sd_lavc.c | 4 ++-- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst index f0f10a4421..95740f98e5 100644 --- a/DOCS/interface-changes.rst +++ b/DOCS/interface-changes.rst @@ -35,6 +35,7 @@ Interface changes - include `--hdr-peak-percentile` in the `gpu-hq` profile - change `--audiotrack-pcm-float` default from `no` to `yes` - add video-params/aspect-name + - change type of `--sub-pos` to float --- mpv 0.36.0 --- - add `--target-contrast` - Target luminance value is now also applied when ICC profile is used. diff --git a/options/options.c b/options/options.c index 7dc5d091f5..d8b68cb448 100644 --- a/options/options.c +++ b/options/options.c @@ -267,7 +267,7 @@ const struct m_sub_options mp_subtitle_sub_opts = { {"stretch-image-subs-to-screen", OPT_BOOL(stretch_image_subs)}, {"image-subs-video-resolution", OPT_BOOL(image_subs_video_res)}, {"sub-fix-timing", OPT_BOOL(sub_fix_timing)}, - {"sub-pos", OPT_INT(sub_pos), M_RANGE(0, 150)}, + {"sub-pos", OPT_FLOAT(sub_pos), M_RANGE(0.0, 150.0)}, {"sub-gauss", OPT_FLOAT(sub_gauss), M_RANGE(0.0, 3.0)}, {"sub-gray", OPT_BOOL(sub_gray)}, {"sub-ass", OPT_BOOL(ass_enabled), .flags = UPDATE_SUB_HARD}, diff --git a/options/options.h b/options/options.h index 0224e5609d..36764ea84e 100644 --- a/options/options.h +++ b/options/options.h @@ -78,7 +78,7 @@ typedef struct mp_vo_opts { struct mp_subtitle_opts { bool sub_visibility; bool sec_sub_visibility; - int sub_pos; + float sub_pos; float sub_delay; float sub_fps; float sub_speed; diff --git a/player/command.c b/player/command.c index f84c33cec6..28c97f0d6f 100644 --- a/player/command.c +++ b/player/command.c @@ -2909,7 +2909,7 @@ static int mp_property_sub_pos(void *ctx, struct m_property *prop, MPContext *mpctx = ctx; struct MPOpts *opts = mpctx->opts; if (action == M_PROPERTY_PRINT) { - *(char **)arg = talloc_asprintf(NULL, "%d/100", opts->subs_rend->sub_pos); + *(char **)arg = talloc_asprintf(NULL, "%4.2f%%/100", opts->subs_rend->sub_pos); return M_PROPERTY_OK; } return mp_property_generic_option(mpctx, prop, action, arg); diff --git a/sub/sd_ass.c b/sub/sd_ass.c index e4e5652875..a4df24e0ae 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -388,7 +388,7 @@ static void configure_ass(struct sd *sd, struct mp_osd_res *dim, ass_set_margins(priv, dim->mt, dim->mb, dim->ml, dim->mr); bool set_use_margins = false; - int set_sub_pos = 0; + float set_sub_pos = 0.0f; float set_line_spacing = 0; float set_font_scale = 1; int set_hinting = 0; @@ -406,7 +406,7 @@ static void configure_ass(struct sd *sd, struct mp_osd_res *dim, set_use_margins = opts->ass_use_margins; } if (converted || opts->ass_style_override) { - set_sub_pos = 100 - opts->sub_pos; + set_sub_pos = 100.0f - opts->sub_pos; set_line_spacing = opts->ass_line_spacing; set_hinting = opts->ass_hinting; set_font_scale = opts->sub_scale; diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index ce20ddba2c..f4b85e0784 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -462,8 +462,8 @@ static struct sub_bitmaps *get_bitmaps(struct sd *sd, struct mp_osd_res d, h = MPMAX(priv->video_params.h, current->src_h); } - if (opts->sub_pos != 100 && opts->ass_style_override) { - int offset = (100 - opts->sub_pos) / 100.0 * h; + if (opts->sub_pos != 100.0f && opts->ass_style_override) { + float offset = (100.0f - opts->sub_pos) / 100.0f * h; for (int n = 0; n < res->num_parts; n++) { struct sub_bitmap *sub = &res->parts[n];