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.
This commit is contained in:
Stefano Pigozzi
2019-09-21 20:11:18 +02:00
parent 0f938b197a
commit cb32ad68f3
8 changed files with 140 additions and 7 deletions

View File

@@ -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,