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. --- player/command.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'player/command.c') diff --git a/player/command.c b/player/command.c index 6239a3fa95..7db7c44ae8 100644 --- a/player/command.c +++ b/player/command.c @@ -2845,6 +2845,38 @@ static int mp_property_sub_text(void *ctx, struct m_property *prop, return m_property_strdup_ro(action, arg, text); } +static struct sd_times get_times(void *ctx, struct m_property *prop, + int action, void *arg) +{ + struct sd_times res = { .start = MP_NOPTS_VALUE, .end = MP_NOPTS_VALUE }; + MPContext *mpctx = ctx; + struct track *track = mpctx->current_track[0][STREAM_SUB]; + struct dec_sub *sub = track ? track->d_sub : NULL; + double pts = mpctx->playback_pts; + if (!sub || pts == MP_NOPTS_VALUE) + return res; + return sub_get_times(sub, pts); +} + +static int mp_property_sub_start(void *ctx, struct m_property *prop, + int action, void *arg) +{ + double start = get_times(ctx, prop, action, arg).start; + if (start == MP_NOPTS_VALUE) + return M_PROPERTY_UNAVAILABLE; + return m_property_double_ro(action, arg, start); +} + + +static int mp_property_sub_end(void *ctx, struct m_property *prop, + int action, void *arg) +{ + double end = get_times(ctx, prop, action, arg).end; + if (end == MP_NOPTS_VALUE) + return M_PROPERTY_UNAVAILABLE; + return m_property_double_ro(action, arg, end); +} + static int mp_property_cursor_autohide(void *ctx, struct m_property *prop, int action, void *arg) { @@ -3548,6 +3580,8 @@ static const struct m_property mp_properties_base[] = { {"sub-speed", mp_property_sub_speed}, {"sub-pos", mp_property_sub_pos}, {"sub-text", mp_property_sub_text}, + {"sub-start", mp_property_sub_start}, + {"sub-end", mp_property_sub_end}, {"vf", mp_property_vf}, {"af", mp_property_af}, -- cgit v1.2.3