From cb32ad68f31de784a13ca5a2847143c4c37738ce Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 21 Sep 2019 20:11:18 +0200 Subject: 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. --- sub/sd_lavc.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'sub/sd_lavc.c') diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 4620c8bd9b..72c89913e0 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -383,14 +383,8 @@ static void decode(struct sd *sd, struct demux_packet *packet) } } -static void get_bitmaps(struct sd *sd, struct mp_osd_res d, int format, - double pts, struct sub_bitmaps *res) +static struct sub *get_current(struct sd_lavc_priv *priv, double pts) { - struct sd_lavc_priv *priv = sd->priv; - struct mp_subtitle_opts *opts = sd->opts; - - priv->current_pts = pts; - struct sub *current = NULL; for (int n = 0; n < MAX_QUEUE; n++) { struct sub *sub = &priv->subs[n]; @@ -407,6 +401,19 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, int format, break; } } + return current; +} + +static void get_bitmaps(struct sd *sd, struct mp_osd_res d, int format, + double pts, struct sub_bitmaps *res) +{ + struct sd_lavc_priv *priv = sd->priv; + struct mp_subtitle_opts *opts = sd->opts; + + priv->current_pts = pts; + + struct sub *current = get_current(priv, pts); + if (!current) return; @@ -483,6 +490,25 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, int format, } +static struct sd_times get_times(struct sd *sd, double pts) +{ + struct sd_lavc_priv *priv = sd->priv; + struct sd_times res = { .start = MP_NOPTS_VALUE, .end = MP_NOPTS_VALUE }; + + if (pts == MP_NOPTS_VALUE) + return res; + + struct sub *current = get_current(priv, pts); + + if (!current) + return res; + + res.start = current->pts; + res.end = current->endpts; + + return res; +} + static bool accepts_packet(struct sd *sd, double min_pts) { struct sd_lavc_priv *priv = sd->priv; @@ -622,6 +648,7 @@ const struct sd_functions sd_lavc = { .init = init, .decode = decode, .get_bitmaps = get_bitmaps, + .get_times = get_times, .accepts_packet = accepts_packet, .control = control, .reset = reset, -- cgit v1.2.3