diff options
author | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2019-09-21 20:11:18 +0200 |
---|---|---|
committer | Stefano Pigozzi <stefano.pigozzi@gmail.com> | 2019-09-22 09:19:45 +0200 |
commit | cb32ad68f31de784a13ca5a2847143c4c37738ce (patch) | |
tree | 9d9d5497c9a58d54ae5ef7cb226e81dd5fb14cb7 /player | |
parent | 0f938b197a79c09b01a9dcf39f02e95d9d7fb4a2 (diff) | |
download | mpv-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 'player')
-rw-r--r-- | player/command.c | 34 |
1 files changed, 34 insertions, 0 deletions
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}, |