[MPlayer-dev-eng] [PATCH] Style tag support for srt and microdvd subtitles

ubitux ubitux at gmail.com
Wed May 12 21:06:48 CEST 2010


On Wed, May 12, 2010 at 09:02:20PM +0200, ubitux wrote:
> Okay, it was very easy in fact. Does this patch look good to you? It's
> just a test using the libass rendering, so it works if you play the video
> with -ass. Also, it's actually just for subrip files (.srt). If you like
> it I can easily do the same for MicroSub.
> 
> It may be not very optimized but it's just a "proof of concept" following
> what Uoti was saying.
> 

Oups, once again I send the mail too fast: just a new version avoiding an
overflow.

-- 
ubitux
-------------- next part --------------
Index: subreader.c
===================================================================
--- subreader.c	(revision 31163)
+++ subreader.c	(working copy)
@@ -36,6 +36,8 @@
 #include "libavutil/common.h"
 #include "libavutil/avstring.h"
 
+#include "libass/ass_mp.h"
+
 #ifdef CONFIG_ENCA
 #include <enca.h>
 #endif
@@ -358,6 +360,42 @@
     return current;
 }
 
+static const struct {
+    char *from;
+    char *to;
+} subviewer_to_ass[] = {
+    {"<i>", "{\\i1}"}, {"</i>", "{\\i0}"},
+    {"<b>", "{\\b1}"}, {"</b>", "{\\b0}"},
+    {"<u>", "{\\u1}"}, {"</u>", "{\\u0}"},
+    {"<s>", "{\\s1}"}, {"</s>", "{\\s0}"}
+};
+
+static void sub_subviewer_line_to_ass(char *line)
+{
+    char new_line[LINE_LEN + 1];
+    int i = 0, j = 0;
+
+    while (line[i] && j < sizeof(new_line)) {
+        int n, match = 0;
+
+        for (n = 0; n < (int)(sizeof(subviewer_to_ass) / sizeof(*subviewer_to_ass)); n++) {
+            int from_len = strlen(subviewer_to_ass[n].from);
+
+            if (strncmp(&line[i], subviewer_to_ass[n].from, from_len) == 0) {
+                strcpy(&new_line[j], subviewer_to_ass[n].to);
+                i += from_len;
+                j += strlen(subviewer_to_ass[n].to);
+                match = 1;
+                break;
+            }
+        }
+        if (!match)
+            new_line[j++] = line[i++];
+    }
+    new_line[j] = 0;
+    strcpy(line, new_line);
+}
+
 static subtitle *sub_read_line_subviewer(stream_t *st,subtitle *current, int utf16) {
     char line[LINE_LEN+1];
     int a1,a2,a3,a4,b1,b2,b3,b4;
@@ -373,6 +411,10 @@
 	for (i=0; i<SUB_MAX_TEXT;) {
 	    int blank = 1;
 	    if (!stream_read_line (st, line, LINE_LEN, utf16)) break;
+
+	    if (ass_enabled)
+		sub_subviewer_line_to_ass(line);
+
 	    len=0;
 	    for (p=line; *p!='\n' && *p!='\r' && *p; p++,len++)
 		if (*p != ' ' && *p != '\t')
@@ -384,17 +426,19 @@
 		//strncpy (current->text[i], line, len); current->text[i][len]='\0';
                 for(; j<len; j++) {
 		    /* let's filter html tags ::atmos */
-		    if(line[j]=='>') {
-			skip=0;
-			continue;
+		    if (!ass_enabled) {
+			if(line[j]=='>') {
+			    skip=0;
+			    continue;
+			}
+			if(line[j]=='<') {
+			    skip=1;
+			    continue;
+			}
+			if(skip) {
+			    continue;
+			}
 		    }
-		    if(line[j]=='<') {
-			skip=1;
-			continue;
-		    }
-		    if(skip) {
-			continue;
-		    }
 		    *curptr=line[j];
 		    curptr++;
 		}


More information about the MPlayer-dev-eng mailing list