mirror of
https://github.com/mpv-player/mpv
synced 2025-01-04 14:12:10 +00:00
command: add estimated-frame-count & estimated-frame-number properties
Signed-off-by: wm4 <wm4@nowhere>
This commit is contained in:
parent
960f0ccfa1
commit
1cb15316b0
@ -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.
|
||||
|
||||
|
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user