From c7487cebd15749bac23fc0a994479723fa2809e9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 17 Nov 2019 01:07:47 +0100 Subject: [PATCH] demux_mf: fix backward seeking behavior If SEEK_FORWARD is set, a demuxer should skip to the next frame if the timestamp does not fall on the start of a frame. If that flag is not set, it should always seek to the first frame before the target timestamp (or the first frame in the file). --- demux/demux_mf.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/demux/demux_mf.c b/demux/demux_mf.c index 7da07c793a..6698ef8c62 100644 --- a/demux/demux_mf.c +++ b/demux/demux_mf.c @@ -15,6 +15,7 @@ * License along with mpv. If not, see . */ +#include #include #include #include @@ -163,14 +164,15 @@ static mf_t *open_mf_single(void *talloc_ctx, struct mp_log *log, char *filename static void demux_seek_mf(demuxer_t *demuxer, double seek_pts, int flags) { mf_t *mf = demuxer->priv; - int newpos = seek_pts * mf->sh->codec->fps; + double newpos = seek_pts * mf->sh->codec->fps; if (flags & SEEK_FACTOR) newpos = seek_pts * (mf->nr_of_files - 1); - if (newpos < 0) - newpos = 0; - if (newpos >= mf->nr_of_files) - newpos = mf->nr_of_files; - mf->curr_frame = newpos; + if (flags & SEEK_FORWARD) { + newpos = ceil(newpos); + } else { + newpos = MPMIN(floor(newpos), mf->nr_of_files - 1); + } + mf->curr_frame = MPCLAMP((int)newpos, 0, mf->nr_of_files); } static bool demux_mf_read_packet(struct demuxer *demuxer,