changeset 4064:3c747168eb6e

1. subs know are readed after reading AVI header so we already know fps 2. modified vplayer format reader - default time is ~6 sec - maybe that should be an option
author atlka
date Wed, 09 Jan 2002 16:35:24 +0000
parents 5a1558a521fb
children 763a0e7e0521
files mplayer.c subreader.c subreader.h
diffstat 3 files changed, 65 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/mplayer.c	Wed Jan 09 16:20:41 2002 +0000
+++ b/mplayer.c	Wed Jan 09 16:35:24 2002 +0000
@@ -29,8 +29,6 @@
 
 #ifdef USE_SUB
 #include "subreader.h"
-void find_sub(subtitle* subtitles,int key);
-void adjust_subs_time(subtitle* subtitles, float subadj, float fps);
 #endif
 
 #ifdef USE_LIBVO2
@@ -730,7 +728,7 @@
 
     if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);
 
-#ifdef USE_SUB
+#ifdef USE_SUB_OLD
 // check .sub
   if(sub_name){
 #if 0
@@ -752,7 +750,7 @@
   }
 
   if(subtitles && stream_dump_type==3) list_sub_file(subtitles);
-  if(subtitles && stream_dump_type==4) dump_mpsub(subtitles);
+  if(subtitles && stream_dump_type==4) dump_mpsub(subtitles, fps);
 #endif
 
     stream=NULL;
@@ -1030,14 +1028,40 @@
     goto goto_next_file; // exit_player(MSGTR_Exit_error);
 }
 
-/* display clip info */
-demux_info_print(demuxer);
 	
 #ifdef USE_SUB
+// after reading video params we should load subtitles because
 // we know fps so now we can adjust subtitles time to ~6 seconds AST
-adjust_subs_time(subtitles, 6.0, sh_video->fps);
+// check .sub
+current_module="read_subtitles_file";
+if(sub_name){
+#if 0
+       int l=strlen(sub_name);
+       if ((l>4) && ((0==strcmp(&sub_name[l-4],".utf"))
+		   ||(0==strcmp(&sub_name[l-4],".UTF"))))
+	  sub_utf8=1;
+#endif  
+       subtitles=sub_read_file(sub_name, sh_video->fps);
+       if(!subtitles || sub_num == 0) mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CantLoadSub,sub_name);
+  }
+  if(!sub_name){
+      if(sub_auto && filename) { // auto load sub file ...
+         subtitles=sub_read_file( sub_filename( get_path("sub/"), filename ), 
+				  sh_video->fps );
+      }
+#if 0
+      if(!subtitles) subtitles=sub_read_file(get_path("default.sub"),
+					     sh_video->fps); // try default
+#endif
+  }
+
+  if(subtitles && stream_dump_type==3) list_sub_file(subtitles);
+  if(subtitles && stream_dump_type==4) dump_mpsub(subtitles, sh_video->fps);
 #endif	
-	
+
+/* display clip info */
+demux_info_print(demuxer);
+
 //================== Init AUDIO (codec) ==========================
 
 current_module="init_audio_codec";
--- a/subreader.c	Wed Jan 09 16:20:41 2002 +0000
+++ b/subreader.c	Wed Jan 09 16:35:24 2002 +0000
@@ -171,8 +171,6 @@
     char *p, *next;
     int i;
 
-    memset(current, 0, sizeof(subtitle));
-
     do {
 	if (!fgets (line, LINE_LEN, fd)) return NULL;
     } while ((sscanf (line,
@@ -201,8 +199,6 @@
     char *p=NULL, *q=NULL;
     int len;
     
-    memset(current, 0, sizeof(subtitle));
-    
     while (1) {
 	if (!fgets (line, LINE_LEN, fd)) return NULL;
 	if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) continue;
@@ -232,8 +228,6 @@
     char *p=NULL;
     int i,len;
     
-    memset(current, '\0', sizeof(subtitle));
-    
     while (!current->text[0]) {
 	if (!fgets (line, LINE_LEN, fd)) return NULL;
 	if ((len=sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8)
@@ -260,28 +254,18 @@
 
 subtitle *sub_read_line_vplayer(FILE *fd,subtitle *current) {
 	char line[LINE_LEN+1];
-	char line2[LINE_LEN+1];
-	int a1,a2,a3,b1,b2,b3;
+	int a1,a2,a3;
 	char *p=NULL, *next,separator;
-	int i,len,len2,plen;
-
-	memset(current, '\0', sizeof(subtitle));
+	int i,len,plen;
 
 	while (!current->text[0]) {
 		if (!fgets (line, LINE_LEN, fd)) return NULL;
 		if ((len=sscanf (line, "%d:%d:%d%c%n",&a1,&a2,&a3,&separator,&plen)) < 4)
 			continue;
-		if (!fgets (line2, LINE_LEN, fd)) return NULL;
-		if ((len2=sscanf (line2, "%d:%d:%d%c",&b1,&b2,&b3,&separator)) < 3)
+		
+		if (!(current->start = a1*360000+a2*6000+a3*100))
 			continue;
-		// przewiń o linijkę do tyłu:
-		fseek(fd,-strlen(line2),SEEK_CUR);
-
-		current->start = a1*360000+a2*6000+a3*100;
-		current->end   = b1*360000+b2*6000+b3*100;
-		if ((current->end - current->start) > 1000) {current->end = current->start + 1000;} // not too long though. 
-		// teraz czas na wkopiowanie stringu
- 		p=line;	
+		p=line;	
  		// finds the body of the subtitle
  		for (i=0; i<3; i++){              
 		   p=strchr(p,':');
@@ -292,8 +276,8 @@
 		    printf("SUB: Skipping incorrect subtitle line!\n");
 		    continue;
 		}
+
  		i=0;
-
 		if (*p!='|') {
 			//
 			next = p,i=0;
@@ -317,8 +301,6 @@
     char *p=NULL,*next=NULL;
     int i,len,plen;
     
-    memset(current, '\0', sizeof(subtitle));
-    
     while (!current->text[0]) {
 	if (!fgets (line, LINE_LEN, fd)) return NULL;
 	//TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0
@@ -394,8 +376,6 @@
     char line[LINE_LEN+1];
     char text[LINE_LEN+1];
 
-    memset(current, '\0', sizeof(subtitle));
-
     if (!fgets (line, LINE_LEN, fd))
 	return NULL;
     if (sscanf (line, "%ld,%ld,\"%[^\"]", &(current->start),
@@ -449,8 +429,6 @@
 subtitle *sub_read_line_aqt(FILE *fd,subtitle *current) {
     char line[LINE_LEN+1];
 
-    memset(current, '\0', sizeof(subtitle));
-
     while (1) {
     // try to locate next subtitle
         if (!fgets (line, LINE_LEN, fd))
@@ -599,29 +577,40 @@
 
 #endif
 
-void adjust_subs_time(subtitle* sub, float subtime, float fps){
+static void adjust_subs_time(subtitle* sub, float subtime, float fps){
+	int n,m;
 	subtitle* nextsub;
 	int i = sub_num;
 	unsigned long subfms = (sub_uses_time ? 100 : fps) * subtime;
-
+	
+	n=m=0;
 	if (i)	for (;;){	
-		if (sub->end <= sub->start)
+		if (sub->end <= sub->start){
 			sub->end = sub->start + subfms;
-		if (!--i) return;
+			m++;
+			n++;
+		}
+		if (!--i) break;
 		nextsub = sub + 1;
 		if (sub->end >= nextsub->start){
 			sub->end = nextsub->start - 1;
 			if (sub->end - sub->start > subfms)
 				sub->end = sub->start + subfms;
+			if (!m)
+				n++;
 		}
 		sub = nextsub;
+		m = 0;
 	}
+	if (n) printf ("SUB: Adjusted %d subtitle(s).\n", n);
 }
 
-subtitle* sub_read_file (char *filename) {
+subtitle* sub_read_file (char *filename, float fps) {
     FILE *fd;
     int n_max;
     subtitle *first;
+    char *fmtname[] = { "microdvd", "subrip", "subviewer", "sami", "vplayer",
+		        "rt", "ssa", "dunnowhat", "mpsub", "aqt" };
     subtitle * (*func[])(FILE *fd,subtitle *dest)=
     {
 	    sub_read_line_microdvd,
@@ -641,7 +630,7 @@
 
     sub_format=sub_autodetect (fd);
     if (sub_format==SUB_INVALID) {printf ("SUB: Could not determine file format\n");return NULL;}
-    printf ("SUB: Detected subtitle file format: %d\n",sub_format);
+    printf ("SUB: Detected subtitle file format: %s\n", fmtname[sub_format]);
     
     rewind (fd);
 
@@ -659,7 +648,9 @@
             n_max+=16;
             first=realloc(first,n_max*sizeof(subtitle));
         }
-        sub=func[sub_format](fd,&first[sub_num]);
+	sub = &first[sub_num];
+	memset(sub, '\0', sizeof(subtitle));
+        sub=func[sub_format](fd,sub);
         if(!sub) break;   // EOF
 #ifdef USE_ICONV
 	if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub);
@@ -683,6 +674,7 @@
 	return NULL;
     }
 
+    adjust_subs_time(first, 6.0, fps); /* ~6 secs AST */
     return first;
 }
 
@@ -786,7 +778,7 @@
 
 }
 
-void dump_mpsub(subtitle* subs){
+void dump_mpsub(subtitle* subs, float fps){
 	int i,j;
 	FILE *fd;
 	float a,b;
@@ -801,7 +793,7 @@
 	
 
 	if (sub_uses_time) fprintf (fd,"FORMAT=TIME\n\n");
-	else fprintf (fd, "FORMAT=25\n\n");  // FIXME: fps
+	else fprintf (fd, "FORMAT=%5.2f\n\n", fps);
 
 	for(j=0;j<sub_num;j++){
 		subtitle* egysub=&subs[j];
--- a/subreader.h	Wed Jan 09 16:20:41 2002 +0000
+++ b/subreader.h	Wed Jan 09 16:35:24 2002 +0000
@@ -1,4 +1,3 @@
-
 #ifndef __MPLAYER_SUBREADER_H
 #define __MPLAYER_SUBREADER_H
 
@@ -34,10 +33,10 @@
     char *text[SUB_MAX_TEXT];
 } subtitle;
 
-subtitle* sub_read_file (char *filename);
-char * sub_filename(char *path, char * fname );
+subtitle* sub_read_file (char *filename, float pts);
+char * sub_filename(char *path, char * fname);
 void list_sub_file(subtitle* subs);
-void dump_mpsub(subtitle* subs);
+void dump_mpsub(subtitle* subs, float fps);
 void sub_free( subtitle * subs );
-
+void find_sub(subtitle* subtitles,int key);
 #endif