mirror of
https://github.com/mpv-player/mpv
synced 2025-04-09 11:11:52 +00:00
sub: implement "sub-seek 0"
For bitmap subs, implement it properly. For libass, you need newest git master. Fixes #2791.
This commit is contained in:
parent
6cbd7d6390
commit
155f7fac9d
@ -4588,7 +4588,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
|
|||||||
// frame which actually shows the sub first (because video
|
// frame which actually shows the sub first (because video
|
||||||
// frame PTS and sub PTS rarely match exactly). Add some
|
// frame PTS and sub PTS rarely match exactly). Add some
|
||||||
// rounding for the mess of it.
|
// rounding for the mess of it.
|
||||||
a[0] += 0.01 * (a[1] > 0 ? 1 : -1);
|
a[0] += 0.01 * (a[1] >= 0 ? 1 : -1);
|
||||||
mark_seek(mpctx);
|
mark_seek(mpctx);
|
||||||
queue_seek(mpctx, MPSEEK_RELATIVE, a[0], MPSEEK_EXACT, false);
|
queue_seek(mpctx, MPSEEK_RELATIVE, a[0], MPSEEK_EXACT, false);
|
||||||
set_osd_function(mpctx, (a[0] > 0) ? OSD_FFW : OSD_REW);
|
set_osd_function(mpctx, (a[0] > 0) ? OSD_FFW : OSD_REW);
|
||||||
|
@ -398,15 +398,15 @@ static double step_sub(struct sd *sd, double now, int movement)
|
|||||||
struct sd_lavc_priv *priv = sd->priv;
|
struct sd_lavc_priv *priv = sd->priv;
|
||||||
int best = -1;
|
int best = -1;
|
||||||
double target = now;
|
double target = now;
|
||||||
int direction = movement > 0 ? 1 : -1;
|
int direction = (movement > 0 ? 1 : -1) * !!movement;
|
||||||
|
|
||||||
if (movement == 0 || priv->num_seekpoints == 0)
|
if (priv->num_seekpoints == 0)
|
||||||
return MP_NOPTS_VALUE;
|
return MP_NOPTS_VALUE;
|
||||||
|
|
||||||
qsort(priv->seekpoints, priv->num_seekpoints, sizeof(priv->seekpoints[0]),
|
qsort(priv->seekpoints, priv->num_seekpoints, sizeof(priv->seekpoints[0]),
|
||||||
compare_seekpoint);
|
compare_seekpoint);
|
||||||
|
|
||||||
while (movement) {
|
do {
|
||||||
int closest = -1;
|
int closest = -1;
|
||||||
double closest_time = 0;
|
double closest_time = 0;
|
||||||
for (int i = 0; i < priv->num_seekpoints; i++) {
|
for (int i = 0; i < priv->num_seekpoints; i++) {
|
||||||
@ -420,13 +420,20 @@ static double step_sub(struct sd *sd, double now, int movement)
|
|||||||
closest_time = end;
|
closest_time = end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (direction > 0) {
|
||||||
if (start > target) {
|
if (start > target) {
|
||||||
if (closest < 0 || start < closest_time) {
|
if (closest < 0 || start < closest_time) {
|
||||||
closest = i;
|
closest = i;
|
||||||
closest_time = start;
|
closest_time = start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (start < target) {
|
||||||
|
if (closest < 0 || start >= closest_time) {
|
||||||
|
closest = i;
|
||||||
|
closest_time = start;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (closest < 0)
|
if (closest < 0)
|
||||||
@ -434,7 +441,7 @@ static double step_sub(struct sd *sd, double now, int movement)
|
|||||||
target = closest_time + direction;
|
target = closest_time + direction;
|
||||||
best = closest;
|
best = closest;
|
||||||
movement -= direction;
|
movement -= direction;
|
||||||
}
|
} while (movement);
|
||||||
|
|
||||||
return best < 0 ? 0 : priv->seekpoints[best].pts - now;
|
return best < 0 ? 0 : priv->seekpoints[best].pts - now;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user