nokangaroo |
07-31-2014 09:45 AM |
[SOLVED] How to fix the mpv-0.4.2 chapter seeking bug
The current (0.4.2) version of the mpv media player has an off-by one bug
when switching chapters. I fixed it (at least for DVD chapters; I don't use
handbrake, iTunes etc) by patching the source as follows:
Code:
cd mpv-0.4.2
patch -p1 < command.c.diff
patch -p1 < playloop.c.diff
command.c.diff:
Code:
--- mpv-0.4.2/player/command.c 2014-07-26 12:12:40.000000000 +0200
+++ mpv-0.4.2/player/command.c 2014-07-31 14:07:38.879251864 +0200
@@ -539,8 +539,8 @@
int action, void *arg)
{
MPContext *mpctx = ctx;
- int chapter = get_current_chapter(mpctx);
- if (chapter < -1)
+ int chapter = get_current_chapter(mpctx) + 1;
+ if (chapter < 0)
return M_PROPERTY_UNAVAILABLE;
switch (action) {
@@ -551,8 +551,8 @@
*(struct m_option *)arg = (struct m_option){
.type = CONF_TYPE_INT,
.flags = M_OPT_MIN | M_OPT_MAX,
- .min = -1,
- .max = get_chapter_count(mpctx) - 1,
+ .min = 0,
+ .max = get_chapter_count(mpctx),
};
return M_PROPERTY_OK;
case M_PROPERTY_PRINT: {
@@ -569,7 +569,7 @@
// Check threshold for relative backward seeks
if (mpctx->opts->chapter_seek_threshold >= 0 && step_all < 0) {
double current_chapter_start =
- chapter_start_time(mpctx, chapter);
+ chapter_start_time(mpctx, chapter - 1);
// If we are far enough into a chapter, seek back to the
// beginning of current chapter instead of previous one
if (current_chapter_start != MP_NOPTS_VALUE &&
@@ -580,12 +580,12 @@
} else // Absolute set
step_all = *(int *)arg - chapter;
chapter += step_all;
- if (chapter < -1)
- chapter = -1;
+ if (chapter < 0)
+ chapter = 0;
if (chapter >= get_chapter_count(mpctx) && step_all > 0) {
mpctx->stop_play = PT_NEXT_ENTRY;
} else {
- mp_seek_chapter(mpctx, chapter);
+ mp_seek_chapter(mpctx, chapter - 1);
}
return M_PROPERTY_OK;
}
playloop.c.diff:
Code:
--- mpv-0.4.2/player/playloop.c 2014-07-26 12:12:40.000000000 +0200
+++ mpv-0.4.2/player/playloop.c 2014-07-31 13:03:35.687570409 +0200
@@ -476,11 +476,11 @@
// -2 is no chapters, -1 is before first chapter
int get_current_chapter(struct MPContext *mpctx)
{
+double current_pts = get_current_time(mpctx);
if (!mpctx->num_chapters)
return -2;
- double current_pts = get_current_time(mpctx);
- int i;
- for (i = 1; i < mpctx->num_chapters; i++)
+ int i;
+ for (i = 0; i < mpctx->num_chapters; i++)
if (current_pts < mpctx->chapters[i].start)
break;
return MPMAX(mpctx->last_chapter_seek, i - 1);
The chapters start with 0, are displayed as such, and
Code:
echo set chapter 0 > .mpv/fifo
will seek to the beginning of the title, as it should.
|