Web lists-archives.com

[MPlayer-dev-eng] [PATCH] Fix attribute parsing at SRT subtitles




Hi,

when SRT subtitles shall be displayed including formatting, they are
converted to ASS markup. The conversion therefore also processes the
"color" attribute of the HTML "font" tag.

At the moment unfortunately also affects attributes who just have
"color" as a prefix, e.g. the attribute "back-color" which is sometimes
contained in subtitles. Therefore the value of this background color
attribute is by mistake used to set the text color.

Please find attached a test SRT file (correct text color: white, not blue).

The attached patch fixes this parsing by also including the leading
space when recognizing the "color" attribute and also the other attributes.

Thanks and regards,
	Stefan Pöschel

Attachment: mplayer_srt_attribute_test.srt
Description: application/subrip

Index: sub/subassconvert.c
===================================================================
--- sub/subassconvert.c	(Revision 37580)
+++ sub/subassconvert.c	(Arbeitskopie)
@@ -195,11 +195,11 @@
             int has_valid_attr = 0;
 
             *tag = tag[-1]; // keep values from previous tag
-            line += 6;
+            line += 5;      // don't skip space!
 
             while (*line && *line != '>') {
-                if (strncmp(line, "size=", 5) == 0) {
-                    line += 5;
+                if (strncmp(line, " size=", 6) == 0) {
+                    line += 6;
                     if (*line == '"') line++;
                     tag->size = strtol(line, &line, 10);
                     if (!tag->size)
@@ -206,8 +206,8 @@
                         break;
                     append_text(&new_line, "{\\fs%d}", tag->size);
                     has_valid_attr = 1;
-                } else if (strncmp(line, "color=", 6) == 0) {
-                    line += 6;
+                } else if (strncmp(line, " color=", 7) == 0) {
+                    line += 7;
                     if (*line == '"') line++;
                     if (*line == '#') {
                         // #RRGGBB format
@@ -241,10 +241,10 @@
                     }
                     append_text(&new_line, "{\\c&H%06X&}", tag->color & 0xffffff);
                     has_valid_attr = 1;
-                } else if (strncmp(line, "face=\"", 6) == 0) {
+                } else if (strncmp(line, " face=\"", 7) == 0) {
                     /* Font face attribute */
                     int len;
-                    line += 6;
+                    line += 7;
                     len = indexof(line, '"');
                     if (len <= 0)
                         break;
_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng