[Mplayer-cvslog] CVS: main mplayer.c,1.361,1.362 subreader.c,1.48,1.49 subreader.h,1.11,1.12
Adam Tla/lka
atlka at mplayer.dev.hu
Wed Jan 9 17:35:27 CET 2002
Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv3154
Modified Files:
mplayer.c subreader.c subreader.h
Log Message:
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
Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.361
retrieving revision 1.362
diff -u -r1.361 -r1.362
--- mplayer.c 8 Jan 2002 14:10:22 -0000 1.361
+++ mplayer.c 9 Jan 2002 16:35:24 -0000 1.362
@@ -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";
Index: subreader.c
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- subreader.c 8 Jan 2002 14:10:22 -0000 1.48
+++ subreader.c 9 Jan 2002 16:35:24 -0000 1.49
@@ -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;
+ 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];
Index: subreader.h
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- subreader.h 25 Dec 2001 16:39:12 -0000 1.11
+++ subreader.h 9 Jan 2002 16:35:24 -0000 1.12
@@ -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
More information about the MPlayer-cvslog
mailing list