LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-31-2014, 10:45 AM   #1
nokangaroo
Member
 
Registered: Nov 2009
Posts: 141

Rep: Reputation: 25
[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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Chapter 6.10 Adjust toolchain gives incorrect output for SEARCH_DIR anupamsr Linux From Scratch 7 06-13-2013 11:48 AM
want to fix the bug kpadhy90 Linux - Newbie 3 09-01-2011 02:15 AM
please fix the bug lipun4u Programming 3 02-21-2011 03:49 PM
Bug#314905 bug fix for Ubuntu and gcc is 4.4.1 bostan Linux - General 1 12-11-2010 01:35 PM
Bug Fix Ctp. Obvious Linux - Newbie 5 08-02-2004 07:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration