diff options
author | Andrey Morozov <morozov.andrey.vmk@gmail.com> | 2014-08-19 23:19:38 +0400 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-08-19 21:47:14 +0200 |
commit | 1cb15316b09fa9091d25f06603570475f5b18921 (patch) | |
tree | e69e12996f8d8fd9e22efdf1560e422366a8a74d | |
parent | 960f0ccfa1b714f0e129336b68739f3cbe72b2fc (diff) | |
download | mpv-1cb15316b09fa9091d25f06603570475f5b18921.tar.bz2 mpv-1cb15316b09fa9091d25f06603570475f5b18921.tar.xz |
command: add estimated-frame-count & estimated-frame-number properties
Signed-off-by: wm4 <wm4@nowhere>
-rw-r--r-- | DOCS/man/input.rst | 7 | ||||
-rw-r--r-- | player/command.c | 39 |
2 files changed, 46 insertions, 0 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index f62bbce24f..b66326c56b 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -596,6 +596,13 @@ Property list ``${stream-end}``. For ordered chapters and such, the size of the currently played segment is returned.) +``estimated-frame-count`` + Total number of frames in current file. Note: It's only an estimate. + (It's computed from two unreliable quantities: fps and stream length.) + +``estimated-frame-number`` + Number of current frame in current stream. + ``path`` Full path of the currently played file. 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}, |