Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/secondary-sub-scale.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `--secondary-sub-scale` option
9 changes: 9 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,9 @@ Subtitles
``--sub-scale=<0-100>``
Factor for the text subtitle font size (default: 1).

This affects both primary and secondary subtitles by default. Use
``--secondary-sub-scale`` to override the scale for secondary subtitles.

.. note::

This affects ASS subtitles as well, and may lead to incorrect subtitle
Expand Down Expand Up @@ -2579,6 +2582,12 @@ Subtitles
Specify the position of secondary subtitles on the screen. This is similar
to ``--sub-pos`` but for secondary subtitles.

``--secondary-sub-scale=<default|0-100>``
Factor for the secondary subtitle font size. The default value
``default`` inherits the value of ``--sub-scale``. If ``add`` or
``multiply`` is used while this is ``default``, the command starts from the
inherited ``--sub-scale`` value and sets an explicit value.

``--sub-speed=<0.1-10.0>``
Multiply the subtitle event timestamps with the given value. Can be used
to fix the playback speed for frame-based subtitle formats. Affects text
Expand Down
4 changes: 4 additions & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ const struct m_sub_options mp_subtitle_shared_sub_opts = {
{"secondary-sub-delay", OPT_FLOAT(sub_delay[1])},
{"sub-pos", OPT_FLOAT(sub_pos[0]), M_RANGE(0.0, 150.0)},
{"secondary-sub-pos", OPT_FLOAT(sub_pos[1]), M_RANGE(0.0, 150.0)},
{"secondary-sub-scale", OPT_FLOAT(secondary_sub_scale),
M_RANGE(0, 100), .flags = M_OPT_DEFAULT_NAN},
{"sub-visibility", OPT_BOOL(sub_visibility[0])},
{"secondary-sub-visibility", OPT_BOOL(sub_visibility[1])},
{"sub-ass-override", OPT_CHOICE(ass_style_override[0],
Expand All @@ -408,6 +410,7 @@ const struct m_sub_options mp_subtitle_shared_sub_opts = {
.sub_visibility[0] = true,
.sub_visibility[1] = true,
.sub_pos[0] = 100,
.secondary_sub_scale = NAN,
.ass_style_override[0] = ASS_STYLE_OVERRIDE_SCALE,
.ass_style_override[1] = ASS_STYLE_OVERRIDE_STRIP,
},
Expand Down Expand Up @@ -1190,6 +1193,7 @@ static const struct MPOpts mp_default_opts = {
"secondary-sid",
"secondary-sub-delay",
"secondary-sub-pos",
"secondary-sub-scale",
"secondary-sub-ass-override",
"secondary-sub-visibility",
"ab-loop-a",
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ struct mp_subtitle_shared_opts {
float sub_pos[2];
bool sub_visibility[2];
int ass_style_override[2];
float secondary_sub_scale;
};

struct mp_osd_render_opts {
Expand Down
36 changes: 35 additions & 1 deletion player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -4957,11 +4957,44 @@ static bool is_property_set(int action, void *val)
}
}

static int handle_secondary_sub_scale_default(struct MPContext *ctx,
const char *name, int action,
void *val)
{
const char *opt_name = name;
if (strncmp(opt_name, "options/", 8) == 0)
opt_name += 8;

if (strcmp(opt_name, "secondary-sub-scale") != 0 ||
(action != M_PROPERTY_SWITCH && action != M_PROPERTY_MULTIPLY) ||
!isnan(ctx->opts->subs_shared->secondary_sub_scale))
return M_PROPERTY_NOT_IMPLEMENTED;

struct m_config_option *opt =
m_config_get_co(ctx->mconfig, bstr0(opt_name));
if (!opt)
return M_PROPERTY_UNKNOWN;

float scale = ctx->opts->subs_rend->sub_scale;
if (action == M_PROPERTY_SWITCH) {
struct m_property_switch_arg *sarg = val;
opt->opt->type->add(opt->opt, &scale, sarg->inc, sarg->wrap);
} else {
opt->opt->type->multiply(opt->opt, &scale, *(double *)val);
}

if (m_config_set_option_raw(ctx->mconfig, opt, &scale, 0) < 0)
return M_PROPERTY_ERROR;
return M_PROPERTY_OK;
}

int mp_property_do(const char *name, int action, void *val,
struct MPContext *ctx)
{
struct command_ctx *cmd = ctx->command_ctx;
int r = m_property_do(ctx->log, cmd->properties, name, action, val, ctx);
int r = handle_secondary_sub_scale_default(ctx, name, action, val);
if (r == M_PROPERTY_NOT_IMPLEMENTED)
r = m_property_do(ctx->log, cmd->properties, name, action, val, ctx);

if (mp_msg_test(ctx->log, MSGL_V) && is_property_set(action, val)) {
struct m_property *property = m_property_list_find(cmd->properties, name);
Expand Down Expand Up @@ -5097,6 +5130,7 @@ static const struct property_osd_display {
"${?secondary-sub-visibility==yes:visible${?secondary-sid==no: (but no secondary subtitles selected)}}"},
{"sub-forced-events-only", "Forced sub only"},
{"sub-scale", "Sub Scale"},
{"secondary-sub-scale", "Secondary Sub Scale"},
{"sub-ass-use-video-data", "Subtitle using video properties"},
{"sub-ass-video-aspect-override", "Subtitle aspect override"},
{"sub-ass-override", "ASS subtitle style override"},
Expand Down
6 changes: 5 additions & 1 deletion sub/sd_ass.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ static void configure_ass(struct sd *sd, struct mp_osd_res *dim,
bool set_scale_with_window = false;
bool set_scale_by_window = true;
bool total_override = false;
float sub_scale = opts->sub_scale;
if (sd->order == 1 && !isnan(shared_opts->secondary_sub_scale))
sub_scale = shared_opts->secondary_sub_scale;

// With forced overrides, apply the --sub-* specific options
if (converted || shared_opts->ass_style_override[sd->order] == ASS_STYLE_OVERRIDE_FORCE) {
set_scale_with_window = opts->sub_scale_with_window;
Expand All @@ -555,7 +559,7 @@ static void configure_ass(struct sd *sd, struct mp_osd_res *dim,
set_hinting = opts->sub_hinting;
}
if (total_override || shared_opts->ass_style_override[sd->order] == ASS_STYLE_OVERRIDE_SCALE) {
set_font_scale = opts->sub_scale;
set_font_scale = sub_scale;
}
if (set_scale_with_window) {
set_font_scale *= dim->h / MPMAX(get_libass_scale_height(dim, set_use_margins), 1);
Expand Down
8 changes: 6 additions & 2 deletions sub/sd_lavc.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,15 @@ static struct sub_bitmaps *get_bitmaps(struct sd *sd, struct mp_osd_res d,

osd_rescale_bitmaps(res, w, h, d, video_par);

if (opts->sub_scale != 1.0 && shared_opts->ass_style_override[sd->order]) {
float sub_scale = opts->sub_scale;
if (sd->order == 1 && !isnan(shared_opts->secondary_sub_scale))
sub_scale = shared_opts->secondary_sub_scale;

if (sub_scale != 1.0 && shared_opts->ass_style_override[sd->order]) {
for (int n = 0; n < res->num_parts; n++) {
struct sub_bitmap *sub = &res->parts[n];

float shit = (opts->sub_scale - 1.0f) / 2;
float shit = (sub_scale - 1.0f) / 2;

// Fortunately VO isn't supposed to give a FUCKING FUCK about
// whether the sub might e.g. go outside of the screen.
Expand Down
42 changes: 42 additions & 0 deletions test/libmpv_test_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,46 @@ static void test_options_and_properties(void)
fail("Node: expected 1 but got %d'!\n", result_node.u.flag);
}

static void test_secondary_sub_scale(void)
{
check_string("secondary-sub-scale", "default");

double sub_scale = 1.25;
set_option_or_property("sub-scale", MPV_FORMAT_DOUBLE, &sub_scale, false);

command_string("add secondary-sub-scale 0.25");
check_double("secondary-sub-scale", 1.5);

set_property_string("secondary-sub-scale", "default");
check_string("secondary-sub-scale", "default");

command_string("multiply secondary-sub-scale 2");
check_double("secondary-sub-scale", 2.5);

set_property_string("secondary-sub-scale", "default");
check_string("secondary-sub-scale", "default");

command_string("add options/secondary-sub-scale 0.25");
check_double("secondary-sub-scale", 1.5);

set_property_string("secondary-sub-scale", "default");
check_string("secondary-sub-scale", "default");

command_string("multiply options/secondary-sub-scale 2");
check_double("secondary-sub-scale", 2.5);

set_property_string("secondary-sub-scale", "default");
check_string("secondary-sub-scale", "default");

double secondary_sub_scale = 0.5;
set_option_or_property("secondary-sub-scale", MPV_FORMAT_DOUBLE,
&secondary_sub_scale, false);
check_double("secondary-sub-scale", secondary_sub_scale);

set_property_string("secondary-sub-scale", "default");
check_string("secondary-sub-scale", "default");
}

int main(int argc, char *argv[])
{
if (argc != 1)
Expand All @@ -130,6 +170,8 @@ int main(int argc, char *argv[])
const char *fmt = "================ TEST: %s ================\n";
printf(fmt, "test_options_and_properties");
test_options_and_properties();
printf(fmt, "test_secondary_sub_scale");
test_secondary_sub_scale();
printf("================ SHUTDOWN ================\n");

command_string("quit");
Expand Down
Loading