summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-11-17 01:07:47 +0100
committerwm4 <wm4@nowhere>2019-11-17 02:11:45 +0100
commitc7487cebd15749bac23fc0a994479723fa2809e9 (patch)
tree57826212f0a99eecb818318e8ef54b361f7e4333
parentf942071524936a2c911d5462893809fd10efcbe2 (diff)
downloadmpv-c7487cebd15749bac23fc0a994479723fa2809e9.tar.bz2
mpv-c7487cebd15749bac23fc0a994479723fa2809e9.tar.xz
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).
-rw-r--r--demux/demux_mf.c14
1 files 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 <http://www.gnu.org/licenses/>.
*/
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
@@ -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,