[MPlayer-dev-eng] [PATCH] Incomplete patch for USF NOVIRUS

Avery Morrow ashitaka-san at comcast.net
Tue Dec 9 04:48:51 CET 2003


MPlayer's lack of Universal Subtitle Format (http://usf.corecodec.org) support has been a bit of a problem for me, so I've hacked together a quick patch. Currently, it is lacking correct XML support, so it is limited to files that use one line for each subtitle <text>, which is the way U96 exports them.

I have probably made and attached this diff file completely incorrectly, as it's the first time I've had to make one. I hope that this patch can be improved on to include in 1.0.

Avery

----------------

subreader.c
264a265,315
> subtitle *sub_read_line_usf(FILE *fd,subtitle *current) {
> 	char line[LINE_LEN+1];
> 	int i, j, count, skip, stopnow, start, a1, a2, a3, a4, b1, b2, b3, b4;
> 	char *p=NULL;
> 	count = 0;
> 	int warning = 0;
> while (!current->text[0]) {
> 	while (!strstr(line, "<subtitle ")) {
> 		if(!fgets(line, LINE_LEN, fd))
> 			return NULL;
> 	}
> 	if (!sscanf(line, " <subtitle start=\"%d:%d:%d.%d\" stop=\"%d:%d:%d.%d\"", &a1, &a2, &a3, &a4, &b1, &b2, &b3, &b4)) {
> 		printf("SUB: SORRY! USF decoding doesn't parse XML correctly.\n"); //XXX currently it assumes the whole tag is on 1 line
> 		break;
> 	}
> 	current->start = a1*360000+a2*6000+a3*100+a4/10;
> 	current->end   = b1*360000+b2*6000+b3*100+b4/10;
> 	if (current->end <= current->start)
> 	  current->end = current->start+200;
> 	while (!(p = strstr(line, "<text"))) {
> 		fgets(line, LINE_LEN, fd);
> 	}
> 	p = &line[0];
> 	int len = 0;
> 	for (; *p!='\n' && *p!='\r' && *p; p++,len++); //XXX not good XML - it doesn't even check for </text>
> 	i = 0;
> 	skip = 1;
> 	//blatantly stolen :)
> 		char *curptr=current->text[count]=(char *)malloc (len + 1);
>                 for(j = 0; j<len; j++) {
> 		    if(line[j]=='>') {
> 			skip=0;
> 			continue;
> 		    }
> 		    if(line[j]=='<') {
> 			skip=1;
> 			continue;
> 		    }
> 		    if(skip) {
> 			continue;
> 		    }
> 		     *curptr=line[j];
> 		    curptr++;
> 		}
> 		*curptr='\0';
> 	count++;
> }
>     current->lines=count;
>     return current;
> }
> 
925a977,979
> 	// If it's XML, it's parsed as USF... this is just as bad as the RT detection
> 	if (strstr(line, "<?xml"))
> 		{*uses_time=1;return SUB_USF;}
929a984
> 	// ... it doesn't as long as it comes last --A.M.
1195c1250,1251
< 	    { sub_read_line_jacosub, NULL, "jacosub" }
---
> 	    { sub_read_line_jacosub, NULL, "jacosub" },
> 	    { sub_read_line_usf, NULL, "USF" }

subreader.h
22a23
> #define SUB_USF      13



More information about the MPlayer-dev-eng mailing list