[MPlayer-dev-eng] [PATCH] disabling/enabling subtitles while playing

Reder Uwe Uwe.Reder at 3SOFT.de
Fri Oct 4 11:07:15 CEST 2002


Hi,

This patch adds the functionality to disable/enable subtitles while playing a video. I mapped it to the input-keyword "sub_visibility". This keyword is mapped to the 'v' key on the keyboard. I tested the patch with old-fashioned subtitles, with freetype subtitles and DVD subtitles. Works fine. The patch also includes documentation updates.

Have fun,
Uwe

----- snip snip -----

diff -Naur MPlayer-0.90pre8.orig/DOCS/documentation.html MPlayer-0.90pre8/DOCS/documentation.html
--- MPlayer-0.90pre8.orig/DOCS/documentation.html	Thu Sep 12 11:42:39 2002
+++ MPlayer-0.90pre8/DOCS/documentation.html	Thu Oct  3 12:58:25 2002
@@ -1099,6 +1099,7 @@
   <TR><TD></TD><TD>/ or *</TD><TD></TD><TD>decrease/increase volume</TD></TR>
   <TR><TD></TD><TD>f</TD><TD></TD><TD>toggle fullscreen</TD></TR>
   <TR><TD></TD><TD>o</TD><TD></TD><TD>toggle OSD: none / seek / seek+timer</TD></TR>
+  <TR><TD></TD><TD>v</TD><TD></TD><TD>toggle subtitle visibility</TD></TR>
   <TR><TD></TD><TD>z or x</TD><TD></TD><TD>adjust subtitle delay by +/- 0.1 second</TD></TR>
   <TR><TD></TD><TD>r or t</TD><TD></TD><TD>adjust subtitle position</TD></TR>
   <TR><TD></TD><TD>HOME or END</TD><TD></TD><TD>go to next/previous playtree entry in the parent list</TD></TR>
@@ -1257,6 +1258,8 @@
     <P>Set/Adjust video parameters. Val range from -100 to 100.</P></LI>
   <LI><B>frame_drop</B> [(int) type=-1]
     <P>Toggle/Set frame dropping mode.</P></LI>
+  <LI><B>sub_visibility</B>
+    <P>Toggle subtitle visibility.</P></LI>
   <LI><B>sub_pos</B> (int) val
     <P>Adjust subtitles position.</P></LI>
   <LI><B>vo_fullscreen</B>
diff -Naur MPlayer-0.90pre8.orig/DOCS/mplayer.1 MPlayer-0.90pre8/DOCS/mplayer.1
--- MPlayer-0.90pre8.orig/DOCS/mplayer.1	Tue Sep 17 23:49:18 2002
+++ MPlayer-0.90pre8/DOCS/mplayer.1	Thu Oct  3 13:02:01 2002
@@ -1998,6 +1998,8 @@
 toggle between OSD states: none / seek / seek+timer
 .IPs d
 toggle frame dropping
+.IPs v
+toggle subtitle visibility
 .IPs "z and x"
 adjust subtitle delay by +/\- 0.1 second
 .IPs "r and t"
@@ -2104,6 +2106,8 @@
 Set/Adjust video parameters.
 .IPs "frame_drop [type=<value>]"
 Toggle/Set frame dropping mode.
+.IPs "sub_visibility"
+Toggle subtitle visibility.
 .IPs "sub_pos <value>"
 Adjust subtitles position.
 .IPs vo_fullscreen
diff -Naur MPlayer-0.90pre8.orig/input/input.c MPlayer-0.90pre8/input/input.c
--- MPlayer-0.90pre8.orig/input/input.c	Wed Aug 28 17:55:57 2002
+++ MPlayer-0.90pre8/input/input.c	Thu Oct  3 12:42:56 2002
@@ -58,6 +58,7 @@
   { MP_CMD_SATURATION, "saturation",1,  { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} }  },
   { MP_CMD_FRAMEDROPPING, "frame_drop",0, { { MP_CMD_ARG_INT,{-1} }, {-1,{0}} } },
   { MP_CMD_SUB_POS, "sub_pos", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
+  { MP_CMD_SUB_VISIBILITY, "sub_visibility", 0, { {-1,{0}} } },
 #ifdef USE_TV
   { MP_CMD_TV_STEP_CHANNEL, "tv_step_channel", 1,  { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
   { MP_CMD_TV_STEP_NORM, "tv_step_norm",0, { {-1,{0}} }  },
@@ -220,6 +221,7 @@
   { { 'd', 0 }, "frame_drop" },
   { { 'r', 0 }, "sub_pos -1" },
   { { 't', 0 }, "sub_pos +1" },
+  { { 'v', 0 }, "sub_visibility" },
 #ifdef USE_TV
   { { 'h', 0 }, "tv_step_channel 1" },
   { { 'k', 0 }, "tv_step_channel -1" },
diff -Naur MPlayer-0.90pre8.orig/input/input.h MPlayer-0.90pre8/input/input.h
--- MPlayer-0.90pre8.orig/input/input.h	Wed Aug 28 17:55:57 2002
+++ MPlayer-0.90pre8/input/input.h	Thu Oct  3 12:42:07 2002
@@ -28,6 +28,7 @@
 #define MP_CMD_LOADFILE 26
 #define MP_CMD_LOADLIST 27
 #define MP_CMD_VF_CHANGE_RECTANGLE 28
+#define MP_CMD_SUB_VISIBILITY 29
 
 #define MP_CMD_GUI_EVENTS       5000
 #define MP_CMD_GUI_LOADFILE     5001
diff -Naur MPlayer-0.90pre8.orig/libvo/sub.c MPlayer-0.90pre8/libvo/sub.c
--- MPlayer-0.90pre8.orig/libvo/sub.c	Wed Aug 28 22:45:42 2002
+++ MPlayer-0.90pre8/libvo/sub.c	Thu Oct  3 13:55:39 2002
@@ -33,6 +33,7 @@
 int sub_unicode=0;
 int sub_utf8=0;
 int sub_pos=100;
+int sub_visibility=1;
 
 // return the real height of a char:
 static inline int get_height(int c,int h){
@@ -298,8 +299,8 @@
    int h,lasth;
    
    obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE;
-   
-   if(!vo_sub || !vo_font){
+
+   if(!vo_sub || !vo_font || !sub_visibility){
        obj->flags&=~OSDFLAG_VISIBLE;
        return;
    }
@@ -504,7 +505,7 @@
 	    vo_update_text_progbar(obj,dxs,dys);
 	    break;
 	case OSDTYPE_SPU:
-	    if(vo_spudec && spudec_visible(vo_spudec)){
+	    if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){
 	        vo_update_spudec_sub(obj, dxs, dys);
 		obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED;
 	    }
diff -Naur MPlayer-0.90pre8.orig/libvo/sub.h MPlayer-0.90pre8/libvo/sub.h
--- MPlayer-0.90pre8.orig/libvo/sub.h	Wed Aug 28 22:45:42 2002
+++ MPlayer-0.90pre8/libvo/sub.h	Thu Oct  3 12:43:19 2002
@@ -97,6 +97,7 @@
 extern char *sub_cp;
 #endif
 extern int sub_pos;
+extern int sub_visibility;
 
 //extern void vo_draw_text_osd(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
 //extern void vo_draw_text_progbar(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
diff -Naur MPlayer-0.90pre8.orig/mplayer.c MPlayer-0.90pre8/mplayer.c
--- MPlayer-0.90pre8.orig/mplayer.c	Mon Sep 23 22:00:24 2002
+++ MPlayer-0.90pre8/mplayer.c	Thu Oct  3 13:52:19 2002
@@ -507,6 +507,7 @@
 int osd_last_pts=-303;
 int osd_show_av_delay = 0;
 int osd_show_sub_delay = 0;
+int osd_show_sub_visibility = 0;
 
 int rtc_fd=-1;
 
@@ -2283,6 +2284,13 @@
 	if(sub_pos <0) sub_pos=0;
 	vo_osd_changed(OSDTYPE_SUBTITLE);
     }	break;
+    case MP_CMD_SUB_VISIBILITY:
+    {
+	sub_visibility=1-sub_visibility;
+	osd_show_sub_visibility = 9; // show state of subtitle visibility in OSD
+	vo_osd_changed(OSDTYPE_SUBTITLE);
+	break;
+    }
     case MP_CMD_SCREENSHOT :
       if(vo_config_count) video_out->control(VOCTRL_SCREENSHOT, NULL);
       break;
@@ -2647,6 +2655,10 @@
           osd_show_dvd_nav_delay--;
       } else
 #endif
+      if (osd_show_sub_visibility) {
+	  sprintf(osd_text_tmp, "Subtitles: %sabled", sub_visibility?"en":"dis");
+	  osd_show_sub_visibility--;
+      } else
       if (osd_show_sub_delay) {
 	  sprintf(osd_text_tmp, "Sub delay: %d ms",(int)(sub_delay*1000));
 	  osd_show_sub_delay--;
diff -Naur MPlayer-0.90pre8.orig/mplayer.h MPlayer-0.90pre8/mplayer.h
--- MPlayer-0.90pre8.orig/mplayer.h	Sat Aug 31 11:45:42 2002
+++ MPlayer-0.90pre8/mplayer.h	Thu Oct  3 12:40:01 2002
@@ -28,6 +28,7 @@
 extern float  sub_fps;
 extern int    sub_auto;
 extern int    sub_pos;
+extern int    sub_visibility;
 extern int    sub_unicode;
 extern subtitle* subtitles;
 extern subtitle* vo_sub;

----- snip snip -----



More information about the MPlayer-dev-eng mailing list