[MPlayer-dev-eng] [PATCH] two pathes: RT subtitles and info fields for MEncoder

Andriy N. Gritsenko andrej at lucky.net
Tue Aug 27 18:42:43 CEST 2002


    Hi!

    I found some bugs with .rt subtitles. .rt subtitles can have line as:

<Time Begin="4.1" End="7.5"><clear/>Some text
<Time Begin="1:4:52.7"><clear/>Other text

First patch fixes it. It works fine now with all subtitles I have.

    Second patch implements some avi info fields into MEncoder. These
fields are: Software (MEncoder, of course :), Name, Artist, Genre,
Subject, Copyright, Source, Comment. It also fixes broken RIFF header
(I wonder why nobody noticed that yet) in generated avi file.

    With best wishes.
    Andriy.

P.S. I didn't implement multiline .rt subs since its are rare but these
ones I've seen have any of <br/> or <br> tag. :)
-------------- next part --------------
diff -udpr MPlayer-20020827.orig/subreader.c MPlayer-20020827/subreader.c
--- MPlayer-20020827.orig/subreader.c	Thu Jul 25 21:05:08 2002
+++ MPlayer-20020827/subreader.c	Tue Aug  6 15:16:02 2002
@@ -351,15 +351,24 @@ subtitle *sub_read_line_rt(FILE *fd,subt
 	//if ((len=sscanf (line, "<Time Begin=\"%d:%d:%d.%d\" End=\"%d:%d:%d.%d\"",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8)
 	plen=a1=a2=a3=a4=b1=b2=b3=b4=0;
 	if (
+	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&b3,&b4,&plen)) < 4) &&
+	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&b2,&b3,&b4,&plen)) < 5) &&
 	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&plen)) < 4) &&
 	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&b4,&plen)) < 5) &&
 //	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&plen)) < 5) &&
 	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&b4,&plen)) < 6) &&
-	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&plen)) < 8) 
+	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&plen)) < 8) &&
+	//now try it without end time
+	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&plen)) < 2) &&
+	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&plen)) < 2) &&
+	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&plen)) < 3) &&
+	((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&plen)) < 4) 
 	)
 	    continue;
 	current->start = a1*360000+a2*6000+a3*100+a4/10;
 	current->end   = b1*360000+b2*6000+b3*100+b4/10;
+	if (b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0)
+	  current->end = current->start+200;
 	p=line;	p+=plen;i=0;
 	// TODO: I don't know what kind of convention is here for marking multiline subs, maybe <br/> like in xml?
 	next = strstr(line,"<clear/>");
-------------- next part --------------
diff -udpr MPlayer-20020827.orig/cfg-mencoder.h MPlayer-20020827/cfg-mencoder.h
--- MPlayer-20020827.orig/cfg-mencoder.h	Mon Aug  5 16:41:32 2002
+++ MPlayer-20020827/cfg-mencoder.h	Wed Aug 21 21:51:30 2002
@@ -130,6 +130,15 @@ static config_t mencoder_opts[]={
 	{"vobsuboutindex", &vobsub_out_index, CONF_TYPE_INT, CONF_RANGE, 0, 31, NULL},
 	{"vobsuboutid", &vobsub_out_id, CONF_TYPE_STRING, 0, 0, 0, NULL},
 
+	// info header strings
+	{"inam", &info_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
+	{"iart", &info_artist, CONF_TYPE_STRING, 0, 0, 0, NULL},
+	{"ignr", &info_genre, CONF_TYPE_STRING, 0, 0, 0, NULL},
+	{"isbj", &info_subject, CONF_TYPE_STRING, 0, 0, 0, NULL},
+	{"icop", &info_copyright, CONF_TYPE_STRING, 0, 0, 0, NULL},
+	{"isrc", &info_source, CONF_TYPE_STRING, 0, 0, 0, NULL},
+	{"icmt", &info_comment, CONF_TYPE_STRING, 0, 0, 0, NULL},
+
 #ifdef HAVE_DIVX4ENCORE
 	{"divx4opts", divx4opts_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
 #endif
diff -udpr MPlayer-20020827.orig/libmpdemux/aviwrite.c MPlayer-20020827/libmpdemux/aviwrite.c
--- MPlayer-20020827.orig/libmpdemux/aviwrite.c	Mon Aug  5 14:26:26 2002
+++ MPlayer-20020827/libmpdemux/aviwrite.c	Thu Aug 22 00:53:53 2002
@@ -146,7 +146,7 @@ void aviwrite_write_header(aviwrite_t *m
       return;
 #endif
   riff[0]=mmioFOURCC('R','I','F','F');
-  riff[1]=muxer->file_end;  // filesize
+  riff[1]=muxer->file_end-2*sizeof(unsigned int);  // filesize
   riff[2]=formtypeAVI; // 'AVI '
   riff[0]=le2me_32(riff[0]);
   riff[1]=le2me_32(riff[1]);
@@ -218,6 +218,21 @@ void aviwrite_write_header(aviwrite_t *m
           le2me_WAVEFORMATEX(muxer->streams[i]->wf);
 }	  
 	  break;
+      }
+  }
+
+  // INFO:
+  hdrsize=0;
+  // calc info size:
+  for(i=0;muxer->info[i]!=NULL;i+=2){
+      register size_t sz=strlen(muxer->info[i+1])+1;
+      hdrsize+=sz+8+sz%2;
+  }
+  // write infos:
+  if (hdrsize!=0){
+      write_avi_list(f,mmioFOURCC('I','N','F','O'),hdrsize);
+      for(i=0;muxer->info[i]!=NULL;i+=2){
+          write_avi_chunk(f,*(unsigned int *)muxer->info[i],strlen(muxer->info[i+1])+1,muxer->info[i+1]);
       }
   }
 
diff -udpr MPlayer-20020827.orig/libmpdemux/aviwrite.h MPlayer-20020827/libmpdemux/aviwrite.h
--- MPlayer-20020827.orig/libmpdemux/aviwrite.h	Fri Apr 12 13:40:38 2002
+++ MPlayer-20020827/libmpdemux/aviwrite.h	Wed Aug 21 21:59:21 2002
@@ -35,6 +35,8 @@ typedef struct {
   AVIINDEXENTRY *idx;
   int idx_pos;
   int idx_size;
+  // info list
+  char **info;
   // streams:
   //int num_streams;
   aviwrite_stream_t* def_v;  // default video stream (for general headers)
diff -udpr MPlayer-20020827.orig/mencoder.c MPlayer-20020827/mencoder.c
--- MPlayer-20020827.orig/mencoder.c	Thu Aug 22 00:31:18 2002
+++ MPlayer-20020827/mencoder.c	Wed Aug 21 22:59:39 2002
@@ -168,6 +168,23 @@ static subtitle* subtitles=NULL;
 float sub_last_pts = -303;
 #endif
 
+// infos
+char *info_name=NULL;
+char *info_artist=NULL;
+char *info_genre=NULL;
+char *info_subject=NULL;
+char *info_copyright=NULL;
+char *info_source=NULL;
+char *info_comment=NULL;
+int infotypeISFT=mmioFOURCC('I','S','F','T');
+int infotypeINAM=mmioFOURCC('I','N','A','M');
+int infotypeIART=mmioFOURCC('I','A','R','T');
+int infotypeIGNR=mmioFOURCC('I','G','N','R');
+int infotypeISBJ=mmioFOURCC('I','S','B','J');
+int infotypeICOP=mmioFOURCC('I','C','O','P');
+int infotypeISRC=mmioFOURCC('I','S','R','C');
+int infotypeICMT=mmioFOURCC('I','C','M','T');
+
 
 
 //char *out_audio_codec=NULL; // override audio codec
@@ -304,6 +321,8 @@ sh_video_t *sh_video=NULL;
 int file_format=DEMUXER_TYPE_UNKNOWN;
 int i;
 void *vobsub_writer=NULL;
+char *info[32]; // number of header comands is 7 plus "ISFT" and padded NULL;
+               // so it has 8 pair of pointers and 1 i.e. 17; let it be more...
 
 uint32_t ptimer_start;
 uint32_t audiorate=0;
@@ -578,6 +597,49 @@ if(!muxer_f) {
 }
 
 muxer=aviwrite_new_muxer();
+
+// ============= INFO ===============
+
+muxer->info=info;
+info[0]=(char *)&infotypeISFT; // Software:
+info[1]="MEncoder " VERSION;
+i=2;
+if(info_name!=NULL){
+  info[i]=(char *)&infotypeINAM; // Name:
+  info[i+1]=info_name;
+  i+=2;
+}
+if(info_artist!=NULL){
+  info[i]=(char *)&infotypeIART; // Artist:
+  info[i+1]=info_artist;
+  i+=2;
+}
+if(info_genre!=NULL){
+  info[i]=(char *)&infotypeIGNR; // Genre:
+  info[i+1]=info_genre;
+  i+=2;
+}
+if(info_subject!=NULL){
+  info[i]=(char *)&infotypeISBJ; // Subject:
+  info[i+1]=info_subject;
+  i+=2;
+}
+if(info_copyright!=NULL){
+  info[i]=(char *)&infotypeICOP; // Copyright:
+  info[i+1]=info_copyright;
+  i+=2;
+}
+if(info_source!=NULL){
+  info[i]=(char *)&infotypeISRC; // Source:
+  info[i+1]=info_source;
+  i+=2;
+}
+if(info_comment!=NULL){
+  info[i]=(char *)&infotypeICMT; // Comment:
+  info[i+1]=info_comment;
+  i+=2;
+}
+info[i]=NULL;
 
 // ============= VIDEO ===============
 


More information about the MPlayer-dev-eng mailing list