summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorRipose <ripose@protonmail.com>2023-11-22 20:13:57 -0700
committersfan5 <sfan5@live.de>2023-11-26 23:22:05 +0100
commitdea512ea38605b6e203e98c1684f819e4aa465f1 (patch)
treebd9f62b46f2a976debdf41b9c9f9e937f38be892 /player/command.c
parenta3f505d4cb2ca70071bbe849d9cf5859802ff608 (diff)
downloadmpv-dea512ea38605b6e203e98c1684f819e4aa465f1.tar.bz2
mpv-dea512ea38605b6e203e98c1684f819e4aa465f1.tar.xz
options: add secondary-sub-delay
Add --secondary-sub-delay option and decouple --sub-delay from secondary subtitles. This produces desirable behavior in most cases as secondary and primary subtitles tracks tend to be timed independently of one another. This feature is implemented by turning the sub_delay field in mp_subtitle_opts into an array of 2 floats. From here the track index is either passed around or derived when sub_delay is needed. There are some cases in dec_sub.c where it is possible for dec_sub.order (equivalent to track index) to be -1. In these cases, sub_delay is inferred as 0.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/player/command.c b/player/command.c
index 84cda39adb..4ec0b5277d 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2874,9 +2874,10 @@ static int mp_property_sub_delay(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
struct MPOpts *opts = mpctx->opts;
+ int track_ind = *(int *)prop->priv;
switch (action) {
case M_PROPERTY_PRINT:
- *(char **)arg = format_delay(opts->subs_rend->sub_delay);
+ *(char **)arg = format_delay(opts->subs_rend->sub_delay[track_ind]);
return M_PROPERTY_OK;
}
return mp_property_generic_option(mpctx, prop, action, arg);
@@ -3929,7 +3930,9 @@ static const struct m_property mp_properties_base[] = {
{"sid", property_switch_track, .priv = (void *)(const int[]){0, STREAM_SUB}},
{"secondary-sid", property_switch_track,
.priv = (void *)(const int[]){1, STREAM_SUB}},
- {"sub-delay", mp_property_sub_delay},
+ {"sub-delay", mp_property_sub_delay, .priv = (void *)&(const int){0}},
+ {"secondary-sub-delay", mp_property_sub_delay,
+ .priv = (void *)&(const int){1}},
{"sub-speed", mp_property_sub_speed},
{"sub-pos", mp_property_sub_pos},
{"sub-ass-extradata", mp_property_sub_ass_extradata},
@@ -4246,6 +4249,7 @@ static const struct property_osd_display {
{"secondary-sid", "Secondary subtitles"},
{"sub-pos", "Sub position"},
{"sub-delay", "Sub delay"},
+ {"secondary-sub-delay", "Secondary sub delay"},
{"sub-speed", "Sub speed"},
{"sub-visibility",
.msg = "Subtitles ${!sub-visibility==yes:hidden}"
@@ -5380,10 +5384,13 @@ static void cmd_sub_step_seek(void *p)
a[1] = cmd->args[0].v.i;
if (sub_control(sub, SD_CTRL_SUB_STEP, a) > 0) {
if (step) {
- mpctx->opts->subs_rend->sub_delay -= a[0] - refpts;
+ mpctx->opts->subs_rend->sub_delay[track_ind] -= a[0] - refpts;
m_config_notify_change_opt_ptr_notify(mpctx->mconfig,
- &mpctx->opts->subs_rend->sub_delay);
- show_property_osd(mpctx, "sub-delay", cmd->on_osd);
+ &mpctx->opts->subs_rend->sub_delay[track_ind]);
+ show_property_osd(
+ mpctx,
+ track_ind == 0 ? "sub-delay" : "secondary-sub-delay",
+ cmd->on_osd);
} else {
// We can easily seek/step to the wrong subtitle line (because
// video frame PTS and sub PTS rarely match exactly). Add an