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 /sub/sd_lavc.c | |
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 'sub/sd_lavc.c')
-rw-r--r-- | sub/sd_lavc.c | 41 |
1 files changed, 34 insertions, 7 deletions
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, |