[MPlayer-dev-eng] [PATCH] interactive subtitle navigation

Oskar Liljeblad oskar at osk.mine.nu
Sat Nov 30 18:51:38 CET 2002


Hi

This patch makes it possible to navigate among the subtitles while
playing movies. It can be very useful when using desynched subtitles.
This is how it works:

A new command 'sub_step' is added, which takes an integer argument.
'sub_step +1' will immediately display the next subtitle, adjusting
sub_delay as if one had used the 'sub_delay' command to navigate to
the subtitle. 'sub_step -1' displays the previous subtitle and
adjusts the sub_delay. By using these two commands you can navigate
among the subtitles without having to search blindly using 'sub_delay'.

The argument to sub_step can also be more than 1 or less than -1,
but I doubt anyone would find a use for this.

I bound 'g' to 'sub_step -1' and 'y' to 'sub_step +1'. (There
weren't many free keys, but these two were.)

Let me know what you decide to do with the patch.

Oskar Liljeblad (oskar at osk.mine.nu)
-------------- next part --------------
diff -u -p ./find_sub.c.v0 find_sub.c
--- ./find_sub.c.v0	2002-08-28 18:09:31.000000000 +0200
+++ find_sub.c	2002-11-30 18:24:47.000000000 +0100
@@ -8,6 +8,7 @@
 
 #include <stdio.h>
 
+#include "mplayer.h"          // for sub_delay
 #include "libvo/video_out.h"
 #include "libvo/sub.h"
 #include "subreader.h"
@@ -18,6 +19,33 @@ static int current_sub=0;
 static int nosub_range_start=-1;
 static int nosub_range_end=-1;
 
+void step_sub(subtitle *subtitles, float pts, int movement) {
+    int key = sub_uses_time ? (100*(pts+sub_delay)) : ((pts+sub_delay)*sub_fps);
+
+    if (subtitles == NULL)
+    	return;
+
+    /* Tell the OSD subsystem that the OSD contents will change soon */
+    vo_osd_changed(OSDTYPE_SUBTITLE);
+
+    /* If we are moving forward, don't count the next (current) subtitle
+     * if we haven't displayed it yet. Same when moving other direction.
+     */
+    if (movement > 0 && key < subtitles[current_sub].start)
+    	movement--;
+    if (movement < 0 && key >= subtitles[current_sub].end)
+    	movement++;
+
+    /* Never move beyond first or last subtitle. */
+    if (current_sub+movement < 0)
+    	movement = 0-current_sub;
+    if (current_sub+movement >= sub_num)
+    	movement = sub_num-current_sub-1;
+
+    current_sub += movement;
+    sub_delay = subtitles[current_sub].start/(sub_uses_time ? 100 : sub_fps) - pts;
+}
+
 void find_sub(subtitle* subtitles,int key){
     int i,j;
     
diff -u -p ./input/input.c.v0 input/input.c
--- ./input/input.c.v0	2002-11-25 15:17:15.000000000 +0100
+++ input/input.c	2002-11-30 18:46:55.000000000 +0100
@@ -54,6 +54,7 @@ static mp_cmd_t mp_cmds[] = {
   { MP_CMD_PLAY_TREE_UP_STEP, "pt_up_step",1,  { { MP_CMD_ARG_INT,{0} }, { MP_CMD_ARG_INT ,{0}}, {-1,{0}} } },
   { MP_CMD_PLAY_ALT_SRC_STEP, "alt_src_step",1, { { MP_CMD_ARG_INT,{0} }, {-1,{0}} } },
   { MP_CMD_SUB_DELAY, "sub_delay",1,  { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+  { MP_CMD_SUB_STEP, "sub_step",1,  { { MP_CMD_ARG_INT,{0} }, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
   { MP_CMD_OSD, "osd",0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
   { MP_CMD_VOLUME, "volume", 1, { { MP_CMD_ARG_INT,{0} }, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
   { MP_CMD_MIXER_USEMASTER, "use_master", 0, { {-1,{0}} } },
@@ -222,6 +223,8 @@ static mp_cmd_bind_t def_cmd_binds[] = {
   { { 'o', 0 }, "osd" },
   { { 'z', 0 }, "sub_delay -0.1" },
   { { 'x', 0 }, "sub_delay +0.1" },
+  { { 'g', 0 }, "sub_step -1" },
+  { { 'y', 0 }, "sub_step +1" },
   { { '9', 0 }, "volume -1" },
   { { '/', 0 }, "volume -1" },
   { { '0', 0 }, "volume 1" },
diff -u ./input/input.h.v0 input/input.h
--- ./input/input.h.v0	2002-11-18 01:11:56.000000000 +0100
+++ input/input.h	2002-11-30 16:51:37.000000000 +0100
@@ -33,6 +33,7 @@
 #define MP_CMD_VOBSUB_LANG 31
 #define MP_CMD_MENU 32
 #define MP_CMD_SET_MENU 33
+#define MP_CMD_SUB_STEP 34
 
 #define MP_CMD_GUI_EVENTS       5000
 #define MP_CMD_GUI_LOADFILE     5001
diff -u -p ./mplayer.c.v0 mplayer.c
--- ./mplayer.c.v0	2002-11-30 15:58:55.000000000 +0100
+++ mplayer.c	2002-11-30 18:50:19.000000000 +0100
@@ -2038,6 +2038,11 @@ if (stream->type==STREAMTYPE_DVDNAV && d
 	sub_delay += v;
       osd_show_sub_delay = 9; // show the subdelay in OSD
     } break;
+    case MP_CMD_SUB_STEP : {
+      int movement = cmd->args[0].v.i;
+      step_sub(subtitles, d_video->pts, movement);
+      osd_show_sub_delay = 9; // show the subdelay in OSD
+    } break;
     case MP_CMD_OSD : 
       if(sh_video) {
 	int v = cmd->args[0].v.i;
diff -u ./subreader.h.v0 subreader.h
--- ./subreader.h.v0	2002-10-30 20:16:58.000000000 +0100
+++ subreader.h	2002-11-30 18:03:36.000000000 +0100
@@ -44,4 +44,5 @@
 void dump_microdvd(subtitle* subs, float fps);
 void sub_free( subtitle * subs );
 void find_sub(subtitle* subtitles,int key);
+void step_sub(subtitle *subtitles, float pts, int movement);
 #endif


More information about the MPlayer-dev-eng mailing list