From 1cb15316b09fa9091d25f06603570475f5b18921 Mon Sep 17 00:00:00 2001 From: Andrey Morozov Date: Tue, 19 Aug 2014 23:19:38 +0400 Subject: command: add estimated-frame-count & estimated-frame-number properties Signed-off-by: wm4 --- player/command.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'player/command.c') diff --git a/player/command.c b/player/command.c index 6dcfc8597f..761aba8fd6 100644 --- a/player/command.c +++ b/player/command.c @@ -2011,6 +2011,42 @@ static int mp_property_border(void *ctx, struct m_property *prop, &mpctx->opts->vo.border, mpctx); } +static int get_frame_count(struct MPContext *mpctx) +{ + struct demuxer *demuxer = mpctx->demuxer; + if (!demuxer) + return 0; + if (!mpctx->d_video) + return 0; + + int frame_count = (int)(get_time_length(mpctx) * mpctx->d_video->fps); + + return frame_count; +} + +static int mp_property_frame_number(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + if (!mpctx->d_video) + return M_PROPERTY_UNAVAILABLE; + + int frame_number = ROUND(get_current_pos_ratio(mpctx, false) * + (double)get_frame_count(mpctx)); + return m_property_int_ro(action, arg, frame_number); +} + +static int mp_property_frame_count(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + + if (!mpctx->d_video) + return M_PROPERTY_UNAVAILABLE; + + return m_property_int_ro(action, arg, get_frame_count(mpctx)); +} + static int mp_property_framedrop(void *ctx, struct m_property *prop, int action, void *arg) { @@ -2790,6 +2826,9 @@ static const struct m_property mp_properties[] = { {"program", mp_property_program}, {"hwdec", mp_property_hwdec}, + {"estimated-frame-count", mp_property_frame_count}, + {"estimated-frame-number", mp_property_frame_number}, + {"osd-width", mp_property_osd_w}, {"osd-height", mp_property_osd_h}, {"osd-par", mp_property_osd_par}, -- cgit v1.2.3