[MPlayer-dev-eng] Re: [PATCH] Better handing of ssa subtitle

Bernd Ernesti mplayer at lists.veego.de
Sat Feb 21 10:17:02 CET 2004


Hi,

what about this patch?

With this patch I could use a sub file (v4+) and now the styles
are finally gone when watching the avi.

Bernd

On Mon, Feb 09, 2004 at 11:03:04PM +0100, matthieu wrote:
> matthieu wrote:
> >Attila Kinali wrote:
> >
> >>Please never send patches direct to me unless i ask for it.
> >>Patches should always go to dev-eng
> >>
> >>On Sat, 07 Feb 2004 00:46:12 +0100
> >>matthieu <mat100 at ifrance.com> wrote:
> >>
> >>
> >>>Ok, i have make a new patch that work even if there are no section.
> >>>But for better handing in this case I have to decrease the default 
> >>>maxcomma to 9.
> >>>But if you realy what set it to 32, for no section one, it will work 
> >>>like before minus the bug with double comma (",,") that I corrected.
> >>>I there are a section, and we are in complex case like
> >>>Dialogue: 
> >>>Marked=0,0:00:01.00,0:00:05.00,*Default,~,0000,0000,0000,,TOTO,TATA
> >>>it will also work.
> >>
> >>
> >>
> >>Do you have access to older SSA specs ?
> >>I only have the specs for v4+
> >
> >me too
> >but i had somme old script and it seem that V1 as 8 comma and since v3 
> >there are 9 comma.
> >
> >>I suspect that this whole patch could be simplified by just decreasing 
> >>the max comas number.
> >
> >I am not sure because you need to make the difference between 8 or 9 
> >commas version. So you need to deternime if between the 8 and 9 comma it 
> >is text or effect. But some subtitler seen to put effects that are not 
> >in the specs....
> >An easy way could be to try to read ScriptType value, but I don't know 
> >if all v3+ script have it.
> >Or as you can see in v3 script we can use the fact that we need to had 
> >Timer or/and Style line before Dialogue in v3+ scripts.
> >
> >>
> >>            Attila Kinali
> >>
> >Matthieu
> >
> >
> here my last patch that I have test with ssa v1,v3,v4,v4+.
> 
> Matthieu
> 
> Ps : I my test with ssa v4+ I have enconter a bug in sub_pp_ssa.
> In the following script, the test are not cleanned...
> 
> Dialogue: 
> 1,0:01:26.58,0:01:28.72,Kare,Script,0000,0000,0000,,{\shad0}{\bord0}{\1c&HFFFFFF&}{\a3}Riz
> Dialogue: 
> 1,0:01:26.58,0:01:28.72,Kare,,0000,0000,0000,,{\shad0}{\bord0}{\1c&HFFFFFF&}{\a3}Soupe 
> de\nnouilles
> Dialogue: 
> 1,0:01:26.58,0:01:28.72,Kare,,0000,0000,0000,,{\shad0}{\bord0}{\1c&HFFFFFF&}{\a3}Saumon
> Dialogue: 
> 1,0:01:26.58,0:01:28.72,Kare,,0000,0000,0000,,{\shad0}{\bord0}{\1c&HFFFFFF&}{\a3}Radis
> Dialogue: 
> 1,0:01:26.58,0:01:28.72,Kare,,0000,0000,0000,,{\shad0}{\bord0}{\1c&HFFFFFF&}{\a3}Haricots
> Dialogue: 
> 1,0:01:26.58,0:01:28.72,Kare,,0000,0000,0000,,{\shad0}{\bord0}{\1c&HFFFFFF&}{\a3}Pickles

> Index: subreader.c
> ===================================================================
> RCS file: /cvsroot/mplayer/main/subreader.c,v
> retrieving revision 1.128
> diff -u -r1.128 subreader.c
> --- subreader.c	29 Jan 2004 10:53:19 -0000	1.128
> +++ subreader.c	9 Feb 2004 21:56:47 -0000
> @@ -461,66 +461,68 @@
>   * http://www.scriptclub.org is a good place to find more examples
>   * http://www.eswat.demon.co.uk is where the SSA specs can be found
>   */
> -        int comma;
> -        static int max_comma = 32; /* let's use 32 for the case that the */
> -                    /*  amount of commas increase with newer SSA versions */
> +	static int max_comma = 8;
>  
>  	int hour1, min1, sec1, hunsec1,
> -	    hour2, min2, sec2, hunsec2, nothing;
> -	int num;
> +	    hour2, min2, sec2, hunsec2;
> +	int num, comma;
>  	
>  	char line[LINE_LEN+1],
> -	     line3[LINE_LEN+1],
>  	     *line2;
>  	char *tmp;
>  
> -	do {
> -		if (!fgets (line, LINE_LEN, fd)) return NULL;
> -	} while (sscanf (line, "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d,"
> -			"%[^\n\r]", &nothing,
> -			&hour1, &min1, &sec1, &hunsec1, 
> +	while (fgets (line, LINE_LEN, fd)) {
> +		
> +		if (!strncmp (line, "ScriptType: v",13)) {
> +			max_comma = 9;
> +			continue;/*read the next line*/
> +		}
> +		else if (strncmp (line, "Dialogue:",9))
> +			continue;/*read the next line*/
> +
> +		tmp = strchr(line, ',');
> +		if (!tmp) continue;/*read the next line*/
> +
> +		if (sscanf (tmp,","
> +			"%1d:%2d:%2d.%2d,%1d:%2d:%2d.%2d,"
> +			"%[^\n\r]",
> +			&hour1, &min1, &sec1, &hunsec1,
>  			&hour2, &min2, &sec2, &hunsec2,
> -			line3) < 9
> -		 &&
> -		 sscanf (line, "Dialogue: %d,%d:%d:%d.%d,%d:%d:%d.%d,"
> -			 "%[^\n\r]", &nothing,
> -			 &hour1, &min1, &sec1, &hunsec1, 
> -			 &hour2, &min2, &sec2, &hunsec2,
> -			 line3) < 9	    );
> -
> -        line2=strchr(line3, ',');
> -
> -        for (comma = 4; comma < max_comma; comma ++)
> -          {
> -            tmp = line2;
> -            if(!(tmp=strchr(++tmp, ','))) break;
> -            if(*(++tmp) == ' ') break; 
> -                  /* a space after a comma means we're already in a sentence */
> -            line2 = tmp;
> -          }
> -
> -        if(comma < max_comma)max_comma = comma;
> -	/* eliminate the trailing comma */
> -	if(*line2 == ',') line2++;
> -
> -	current->lines=0;num=0;
> -	current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1;
> -	current->end   = 360000*hour2 + 6000*min2 + 100*sec2 + hunsec2;
> +			line) < 9)
> +			continue;/*read the next line*/
> +
> +		line2=strchr(line, ',');
> +		if (!line2) continue; /*Line broken*/
> +		tmp=line2+1;
> +		for (comma = 4; comma < max_comma; comma ++) {
> +			tmp=strchr(tmp, ',');
> +			if(!tmp) {
> +				max_comma = 8;
> +				break;
> +			}
> +			line2 = ++tmp;
> +		}
> +			
> +		current->lines=0;num=0;
> +		current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1;
> +		current->end   = 360000*hour2 + 6000*min2 + 100*sec2 + hunsec2;
>  	
> -        while (((tmp=strstr(line2, "\\n")) != NULL) || ((tmp=strstr(line2, "\\N")) != NULL) ){
> -		current->text[num]=(char *)malloc(tmp-line2+1);
> -		strncpy (current->text[num], line2, tmp-line2);
> -		current->text[num][tmp-line2]='\0';
> -		line2=tmp+2;
> -		num++;
> -		current->lines++;
> -		if (current->lines >=  SUB_MAX_TEXT) return current;
> -	}
> +		while (((tmp=strstr(line2, "\\n")) != NULL) || ((tmp=strstr(line2, "\\N")) != NULL) ){
> +			current->text[num]=(char *)malloc(tmp-line2+1);
> +			strncpy (current->text[num], line2, tmp-line2);
> +			current->text[num][tmp-line2]='\0';
> +			line2=tmp+2;
> +			num++;
> +			current->lines++;
> +			if (current->lines >=  SUB_MAX_TEXT) return current;
> +		}
>  
> -	current->text[num]=strdup(line2);
> -	current->lines++;
> +		current->text[num]=strdup(line2);
> +		current->lines++;
>  
> -	return current;
> +		return current;
> +	}
> +	return NULL;
>  }
>  
>  void sub_pp_ssa(subtitle *sub) {




> _______________________________________________
> MPlayer-dev-eng mailing list
> MPlayer-dev-eng at mplayerhq.hu
> http://mplayerhq.hu/mailman/listinfo/mplayer-dev-eng




More information about the MPlayer-dev-eng mailing list