[MPlayer-dev-eng] [PATCH] Remove font attributes from subtitles

Robert Ramiega jedi at plukwa.net
Tue Sep 6 13:26:47 CEST 2005


  Hi!
Sometimes subtitles files (i've seen this in mdvd and mpl2 only) contain
information on attributes of the following subtitle (like italics or color).
As of now mplayer just displays this information as part of subtitle. So far
i couldn't make head or tails out of subtitle rendering in mplayer so i made
small patch that removes this extranous information. 
 If someone would be so nice and get me started on subtitle rendering i'm
willing to try to make mplayer actually recognize and use this attributes.

Here is sample subtitle:

[01][19]{C:$aaccff}Battlestar Galactica [1x02]
Water|/{C:$aaccff}http://napisy.gwrota.com
[15][35]{C:$aaccff}/Poprzednio w Battlestar Galactica...
[40][70]{C:$aaccff}CYLONI ZOSTALI STWORZENI|{C:$aaccff}PRZEZ CZLOWIEKA.
[76][106]{C:$aaccff}ZBUNTOWALI SIE.
[112][137]{C:$aaccff}EWOLUOWALI.
[147][167]{C:$aaccff}WYGLADAJA
[171][184]{C:$aaccff}I CZUJA
[185][200]{C:$aaccff}JAK LUDZIE.
[219][247]{C:$aaccff}NIEKTORZY SA ZAPROGRAMOWANI TAK,|{C:$aaccff}BY MYSLEC,ZE SA LUDZMI.
[248][288]{C:$aaccff}ISTNIEJE WIELE TAKICH SAMYCH KOPII.
[297][327]{C:$aaccff}I MAJA PLAN.
[352][370]/- Alarm radiologiczny.|- Skad?
[372][395]Olympic Carrier,|maja jadrówki na pokladzie.



-- 
Just a friendly Jedi Knight     | I find your lack of faith
Robert Ramiega jedi at plukwa.net  | disturbing
-------------- next part --------------
Index: subreader.c
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.c,v
retrieving revision 1.144
diff -u -r1.144 subreader.c
--- subreader.c	1 Jun 2005 09:01:41 -0000	1.144
+++ subreader.c	6 Sep 2005 11:14:44 -0000
@@ -257,6 +257,36 @@
     else return NULL;  // last text field
 }
 
+/*
+ * Removes text atributes ({C:$aabbcc} {y:i} / )
+ * from subtitles
+ *
+ * NOTICE: 
+ * changes string pointed to by source parameter
+ */
+void sub_clean(char *source)
+{
+    char temp_line[LINE_LEN+1]="";
+    char *ptr, *ptr2;
+
+    ptr = source;
+    ptr2 = temp_line;
+    if(*ptr == '/') {
+        ptr++; 
+    }
+    while(*ptr != '\0') {
+        if(*ptr == '{') {
+	    while(*ptr != '}' && *ptr != '\0') ptr++;
+	    if(*ptr == '}') ptr++;
+	    if(*ptr == '/') ptr++;
+	}
+	*ptr2++ = *ptr++;
+	if(*(ptr-1) == '|' && *ptr == '/') ptr++;
+    }
+    strcpy(source, temp_line);
+}
+
+
 subtitle *sub_read_line_microdvd(FILE *fd,subtitle *current) {
     char line[LINE_LEN+1];
     char line2[LINE_LEN+1];
@@ -271,7 +301,7 @@
 	     (sscanf (line,
 		      "{%ld}{%ld}%[^\r\n]",
 		      &(current->start), &(current->end), line2) < 3));
-	
+    sub_clean(line2);	
     p=line2;
 
     next=p, i=0;
@@ -298,6 +328,7 @@
 		      &(current->start), &(current->end), line2) < 3));
     current->start *= 10;
     current->end *= 10;
+    sub_clean(line2);
     p=line2;
 
     next=p, i=0;


More information about the MPlayer-dev-eng mailing list