summaryrefslogtreecommitdiffstats
path: root/sub/sd_ass.c
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2019-09-21 20:11:18 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2019-09-22 09:19:45 +0200
commitcb32ad68f31de784a13ca5a2847143c4c37738ce (patch)
tree9d9d5497c9a58d54ae5ef7cb226e81dd5fb14cb7 /sub/sd_ass.c
parent0f938b197a79c09b01a9dcf39f02e95d9d7fb4a2 (diff)
downloadmpv-cb32ad68f31de784a13ca5a2847143c4c37738ce.tar.bz2
mpv-cb32ad68f31de784a13ca5a2847143c4c37738ce.tar.xz
command: add sub-start & sub-end properties
These properties contain the current subtitle's start and end times. Can be useful to cut sample audio through the scripting interface.
Diffstat (limited to 'sub/sd_ass.c')
-rw-r--r--sub/sd_ass.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/sub/sd_ass.c b/sub/sd_ass.c
index 163ffb6648..18ef961e8c 100644
--- a/sub/sd_ass.c
+++ b/sub/sd_ass.c
@@ -593,6 +593,35 @@ static char *get_text(struct sd *sd, double pts)
return ctx->last_text;
}
+static struct sd_times get_times(struct sd *sd, double pts)
+{
+ struct sd_ass_priv *ctx = sd->priv;
+ ASS_Track *track = ctx->ass_track;
+ struct sd_times res = { .start = MP_NOPTS_VALUE, .end = MP_NOPTS_VALUE };
+
+ if (pts == MP_NOPTS_VALUE || ctx->duration_unknown)
+ return res;
+
+ long long ipts = find_timestamp(sd, pts);
+
+ for (int i = 0; i < track->n_events; ++i) {
+ ASS_Event *event = track->events + i;
+ if (ipts >= event->Start && ipts < event->Start + event->Duration) {
+ double start = event->Start / 1000.0;
+ double end = event->Duration == UNKNOWN_DURATION ?
+ MP_NOPTS_VALUE : (event->Start + event->Duration) / 1000.0;
+
+ if (res.start == MP_NOPTS_VALUE || res.start > start)
+ res.start = start;
+
+ if (res.end == MP_NOPTS_VALUE || res.end < end)
+ res.end = end;
+ }
+ }
+
+ return res;
+}
+
static void fill_plaintext(struct sd *sd, double pts)
{
struct sd_ass_priv *ctx = sd->priv;
@@ -687,6 +716,7 @@ const struct sd_functions sd_ass = {
.decode = decode,
.get_bitmaps = get_bitmaps,
.get_text = get_text,
+ .get_times = get_times,
.control = control,
.reset = reset,
.select = enable_output,