[Mplayer-cvslog] CVS: main cfg-mplayer.h,1.85,1.86 mplayer.c,1.291,1.292 subreader.c,1.28,1.29

Megyer Laszlo laaz at mplayer.dev.hu
Fri Oct 12 18:22:18 CEST 2001


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv12307

Modified Files:
	cfg-mplayer.h mplayer.c subreader.c 
Log Message:
MPsub read/write support 0.5  (-dumpmpsub switch)


Index: cfg-mplayer.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-mplayer.h,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -r1.85 -r1.86
--- cfg-mplayer.h	10 Oct 2001 13:07:42 -0000	1.85
+++ cfg-mplayer.h	12 Oct 2001 16:21:55 -0000	1.86
@@ -176,7 +176,8 @@
 	{"dumpaudio", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 1},
 	{"dumpvideo", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 2},
 	{"dumpsub", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 3},
-	
+	{"dumpmpsub", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 4},
+
 	{"aofile", &ao_outputfilename, CONF_TYPE_STRING, 0, 0, 0},
 	{"waveheader", &ao_pcm_waveheader, CONF_TYPE_FLAG, 0, 0, 1},
 	{"nowaveheader", &ao_pcm_waveheader, CONF_TYPE_FLAG, 0, 1, 0},

Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.291
retrieving revision 1.292
diff -u -r1.291 -r1.292
--- mplayer.c	7 Oct 2001 00:57:28 -0000	1.291
+++ mplayer.c	12 Oct 2001 16:21:55 -0000	1.292
@@ -672,6 +672,7 @@
 #endif
 
   if(subtitles && stream_dump_type==3) list_sub_file(subtitles);
+  if(subtitles && stream_dump_type==4) dump_mpsub(subtitles);
 
     stream=NULL;
     demuxer=NULL;
@@ -796,7 +797,8 @@
   switch(stream_dump_type){
   case 1: ds=d_audio;break;
   case 2: ds=d_video;break;
-  case 3: ds=d_dvdsub;break;
+  case 3:
+  case 4: ds=d_dvdsub;break;
   }
   if(!ds){        
       mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_DumpSelectedSteramMissing);

Index: subreader.c
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- subreader.c	12 Oct 2001 13:51:58 -0000	1.28
+++ subreader.c	12 Oct 2001 16:21:55 -0000	1.29
@@ -23,7 +23,7 @@
 #endif
 
 
-static long int mpsub_position=0;
+static float mpsub_position=0;
 
 int sub_uses_time=0;
 int sub_errs=0;
@@ -373,18 +373,19 @@
 
 subtitle *sub_read_line_mpsub(FILE *fd, subtitle *current) {
 	char line[1000];
-	int a,b,num=0;
+	float a,b;
+	int num=0;
 	char *p, *q;
 
 	do
 	{
 		if (!fgets(line, 1000, fd)) return NULL;
-	} while (sscanf (line, "%d %d", &a, &b) !=2);
+	} while (sscanf (line, "%f %f", &a, &b) !=2);
 
-	mpsub_position += (a*100);
-	current->start=mpsub_position+1;
-	mpsub_position += (b*100);
-	current->end=mpsub_position;
+	mpsub_position += (a*100.0);
+	current->start=(int) mpsub_position;
+	mpsub_position += (b*100.0);
+	current->end=(int) mpsub_position;
 
 	while (num < SUB_MAX_TEXT) {
 		if (!fgets (line, 1000, fd)) return NULL;
@@ -673,6 +674,49 @@
     printf ("Read %i subtitles, %i errors.\n", sub_num, sub_errs);
 
 }
+
+void dump_mpsub(subtitle* subs){
+	int i,j;
+	FILE *fd;
+	float a,b;
+
+	mpsub_position=0.0;
+
+	fd=fopen ("dump.mpsub", "w");
+	if (!fd) {
+		perror ("dump_mpsub: fopen");
+		return;
+	}
+	
+
+	if (sub_uses_time) fprintf (fd,"FORMAT=TIME\n\n");
+	else fprintf (fd, "FORMAT=25");  // FIXME: fps
+
+	for(j=0;j<sub_num;j++){
+	    subtitle* egysub=&subs[j];
+	    a=((egysub->start-mpsub_position)/100.0);
+	    b=((egysub->end-egysub->start)/100.0);
+	    if ( (float)((int)a) == a)
+		fprintf (fd, "%.0f",a);
+	    else
+		fprintf (fd, "%.2f",a);
+	    
+	    if ( (float)((int)b) == b)
+		fprintf (fd, " %.0f\n",b);
+	    else
+		fprintf (fd, " %.2f\n",b);
+	    
+	    mpsub_position = egysub->end;
+	    for (i=0; i<egysub->lines; i++) {
+		fprintf (fd, "%s\n",egysub->text[i]);
+	    }
+	    fprintf (fd, "\n");
+	}
+	fclose (fd);
+	printf ("Subtitles dumped in \'dump.mpsub\'.\n");
+}
+
+
 
 #if 0
 int main(int argc, char **argv) {  // for testing




More information about the MPlayer-cvslog mailing list