1 /*****************************************************************************
2 * subtitle.c: Demux for subtitle text files.
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Derk-Jan Hartman <hartman at videolan dot org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_input.h>
39 #ifdef HAVE_SYS_TYPES_H
40 # include <sys/types.h>
44 #include <vlc_demux.h>
45 #include <vlc_charset.h>
47 /*****************************************************************************
49 *****************************************************************************/
50 static int Open ( vlc_object_t *p_this );
51 static void Close( vlc_object_t *p_this );
53 #define SUB_DELAY_LONGTEXT \
54 N_("Apply a delay to all subtitles (in 1/10s, eg 100 means 10s).")
55 #define SUB_FPS_LONGTEXT \
56 N_("Override the normal frames per second settings. " \
57 "This will only work with MicroDVD and SubRIP (SRT) subtitles.")
58 #define SUB_TYPE_LONGTEXT \
59 N_("Force the subtiles format. Valid values are : \"microdvd\", " \
60 "\"subrip\", \"subviewer\", \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\", " \
61 "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\", "\
62 "\"mpsub\", \"jacosub\", \"psb\", \"realtext\", \"dks\", \"subviewer1\", " \
63 " and \"auto\" (meaning autodetection, this should always work).")
65 static const char *const ppsz_sub_type[] =
67 "auto", "microdvd", "subrip", "subviewer", "ssa1",
68 "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2",
69 "aqt", "pjs", "mpsub", "jacosub", "psb", "realtext", "dks",
74 set_shortname( N_("Subtitles"));
75 set_description( N_("Text subtitles parser") );
76 set_capability( "demux", 0 );
77 set_category( CAT_INPUT );
78 set_subcategory( SUBCAT_INPUT_DEMUX );
79 add_float( "sub-fps", 0.0, NULL,
80 N_("Frames per second"),
81 SUB_FPS_LONGTEXT, true );
82 add_integer( "sub-delay", 0, NULL,
83 N_("Subtitles delay"),
84 SUB_DELAY_LONGTEXT, true );
85 add_string( "sub-type", "auto", NULL, N_("Subtitles format"),
86 SUB_TYPE_LONGTEXT, true );
87 change_string_list( ppsz_sub_type, NULL, NULL );
88 set_callbacks( Open, Close );
90 add_shortcut( "subtitle" );
93 /*****************************************************************************
95 *****************************************************************************/
98 SUB_TYPE_UNKNOWN = -1,
106 SUB_TYPE_SUBVIEWER, /* SUBVIEWER 2 */
107 SUB_TYPE_DVDSUBTITLE, /* Mplayer calls it subviewer2 */
116 SUB_TYPE_SUBVIEW1 /* SUBVIEWER 1 - mplayer calls it subrip09,
117 and Gnome subtitles SubViewer 1.0 */
127 static int TextLoad( text_t *, stream_t *s );
128 static void TextUnload( text_t * );
145 int64_t i_next_demux_date;
146 int64_t i_microsecperframe;
151 subtitle_t *subtitle;
156 static int ParseMicroDvd ( demux_t *, subtitle_t *, int );
157 static int ParseSubRip ( demux_t *, subtitle_t *, int );
158 static int ParseSubViewer ( demux_t *, subtitle_t *, int );
159 static int ParseSSA ( demux_t *, subtitle_t *, int );
160 static int ParseVplayer ( demux_t *, subtitle_t *, int );
161 static int ParseSami ( demux_t *, subtitle_t *, int );
162 static int ParseDVDSubtitle( demux_t *, subtitle_t *, int );
163 static int ParseMPL2 ( demux_t *, subtitle_t *, int );
164 static int ParseAQT ( demux_t *, subtitle_t *, int );
165 static int ParsePJS ( demux_t *, subtitle_t *, int );
166 static int ParseMPSub ( demux_t *, subtitle_t *, int );
167 static int ParseJSS ( demux_t *, subtitle_t *, int );
168 static int ParsePSB ( demux_t *, subtitle_t *, int );
169 static int ParseRealText ( demux_t *, subtitle_t *, int );
170 static int ParseDKS ( demux_t *, subtitle_t *, int );
171 static int ParseSubViewer1 ( demux_t *, subtitle_t *, int );
175 const char *psz_type_name;
177 const char *psz_name;
178 int (*pf_read)( demux_t *, subtitle_t*, int );
179 } sub_read_subtitle_function [] =
181 { "microdvd", SUB_TYPE_MICRODVD, "MicroDVD", ParseMicroDvd },
182 { "subrip", SUB_TYPE_SUBRIP, "SubRIP", ParseSubRip },
183 { "subviewer", SUB_TYPE_SUBVIEWER, "SubViewer", ParseSubViewer },
184 { "ssa1", SUB_TYPE_SSA1, "SSA-1", ParseSSA },
185 { "ssa2-4", SUB_TYPE_SSA2_4, "SSA-2/3/4", ParseSSA },
186 { "ass", SUB_TYPE_ASS, "SSA/ASS", ParseSSA },
187 { "vplayer", SUB_TYPE_VPLAYER, "VPlayer", ParseVplayer },
188 { "sami", SUB_TYPE_SAMI, "SAMI", ParseSami },
189 { "dvdsubtitle",SUB_TYPE_DVDSUBTITLE, "DVDSubtitle", ParseDVDSubtitle },
190 { "mpl2", SUB_TYPE_MPL2, "MPL2", ParseMPL2 },
191 { "aqt", SUB_TYPE_AQT, "AQTitle", ParseAQT },
192 { "pjs", SUB_TYPE_PJS, "PhoenixSub", ParsePJS },
193 { "mpsub", SUB_TYPE_MPSUB, "MPSub", ParseMPSub },
194 { "jacosub", SUB_TYPE_JACOSUB, "JacoSub", ParseJSS },
195 { "psb", SUB_TYPE_PSB, "PowerDivx", ParsePSB },
196 { "realtext", SUB_TYPE_RT, "RealText", ParseRealText },
197 { "dks", SUB_TYPE_DKS, "DKS", ParseDKS },
198 { "subviewer1", SUB_TYPE_SUBVIEW1, "Subviewer 1", ParseSubViewer1 },
199 { NULL, SUB_TYPE_UNKNOWN, "Unknown", NULL }
202 static int Demux( demux_t * );
203 static int Control( demux_t *, int, va_list );
205 /*static void Fix( demux_t * );*/
207 /*****************************************************************************
209 *****************************************************************************/
210 static int Open ( vlc_object_t *p_this )
212 demux_t *p_demux = (demux_t*)p_this;
217 int (*pf_read)( demux_t *, subtitle_t*, int );
220 if( !p_demux->b_force )
222 msg_Dbg( p_demux, "subtitle demux discarded" );
226 p_demux->pf_demux = Demux;
227 p_demux->pf_control = Control;
228 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
232 p_sys->psz_header = NULL;
233 p_sys->i_subtitle = 0;
234 p_sys->i_subtitles = 0;
235 p_sys->subtitle = NULL;
236 p_sys->i_microsecperframe = 40000;
239 f_fps = var_CreateGetFloat( p_demux, "sub-original-fps" ); /* FIXME */
241 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
243 msg_Dbg( p_demux, "Movie fps: %f", f_fps );
245 /* Check for override of the fps */
246 f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
249 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
250 msg_Dbg( p_demux, "Override subtitle fps %f", f_fps );
253 /* Get or probe the type */
254 p_sys->i_type = SUB_TYPE_UNKNOWN;
255 psz_type = var_CreateGetString( p_demux, "sub-type" );
256 if( psz_type && *psz_type )
262 if( sub_read_subtitle_function[i].psz_type_name == NULL )
265 if( !strcmp( sub_read_subtitle_function[i].psz_type_name,
268 p_sys->i_type = sub_read_subtitle_function[i].i_type;
275 /* Probe if unknown type */
276 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
281 msg_Dbg( p_demux, "autodetecting subtitle format" );
282 for( i_try = 0; i_try < 256; i_try++ )
287 if( ( s = stream_ReadLine( p_demux->s ) ) == NULL )
290 if( strcasestr( s, "<SAMI>" ) )
292 p_sys->i_type = SUB_TYPE_SAMI;
295 else if( sscanf( s, "{%d}{%d}", &i_dummy, &i_dummy ) == 2 ||
296 sscanf( s, "{%d}{}", &i_dummy ) == 1)
298 p_sys->i_type = SUB_TYPE_MICRODVD;
302 "%d:%d:%d,%d --> %d:%d:%d,%d",
303 &i_dummy,&i_dummy,&i_dummy,&i_dummy,
304 &i_dummy,&i_dummy,&i_dummy,&i_dummy ) == 8 )
306 p_sys->i_type = SUB_TYPE_SUBRIP;
309 else if( !strncasecmp( s, "!: This is a Sub Station Alpha v1", 33 ) )
311 p_sys->i_type = SUB_TYPE_SSA1;
314 else if( !strncasecmp( s, "ScriptType: v4.00+", 18 ) )
316 p_sys->i_type = SUB_TYPE_ASS;
319 else if( !strncasecmp( s, "ScriptType: v4.00", 17 ) )
321 p_sys->i_type = SUB_TYPE_SSA2_4;
324 else if( !strncasecmp( s, "Dialogue: Marked", 16 ) )
326 p_sys->i_type = SUB_TYPE_SSA2_4;
329 else if( !strncasecmp( s, "Dialogue:", 9 ) )
331 p_sys->i_type = SUB_TYPE_ASS;
334 else if( strcasestr( s, "[INFORMATION]" ) )
336 p_sys->i_type = SUB_TYPE_SUBVIEWER; /* I hope this will work */
339 else if( sscanf( s, "%d:%d:%d.%d %d:%d:%d",
340 &i_dummy, &i_dummy, &i_dummy, &i_dummy,
341 &i_dummy, &i_dummy, &i_dummy ) == 7 ||
342 sscanf( s, "@%d @%d", &i_dummy, &i_dummy) == 2)
344 p_sys->i_type = SUB_TYPE_JACOSUB;
347 else if( sscanf( s, "%d:%d:%d:", &i_dummy, &i_dummy, &i_dummy ) == 3 ||
348 sscanf( s, "%d:%d:%d ", &i_dummy, &i_dummy, &i_dummy ) == 3 )
350 p_sys->i_type = SUB_TYPE_VPLAYER;
353 else if( sscanf( s, "{T %d:%d:%d:%d", &i_dummy, &i_dummy,
354 &i_dummy, &i_dummy ) == 4 )
356 p_sys->i_type = SUB_TYPE_DVDSUBTITLE;
359 else if( sscanf( s, "[%d:%d:%d]%c",
360 &i_dummy, &i_dummy, &i_dummy, &p_dummy ) == 4 )
362 p_sys->i_type = SUB_TYPE_DKS;
365 else if( strstr( s, "*** START SCRIPT" ) )
367 p_sys->i_type = SUB_TYPE_SUBVIEW1;
370 else if( sscanf( s, "[%d][%d]", &i_dummy, &i_dummy ) == 2 ||
371 sscanf( s, "[%d][]", &i_dummy ) == 1)
373 p_sys->i_type = SUB_TYPE_MPL2;
376 else if( sscanf (s, "FORMAT=%d", &i_dummy) == 1 ||
377 ( sscanf (s, "FORMAT=TIM%c", &p_dummy) == 1
380 p_sys->i_type = SUB_TYPE_MPSUB;
383 else if( sscanf( s, "-->> %d", &i_dummy) == 1 )
385 p_sys->i_type = SUB_TYPE_AQT;
388 else if( sscanf( s, "%d,%d,", &i_dummy, &i_dummy ) == 2 )
390 p_sys->i_type = SUB_TYPE_PJS;
393 else if( sscanf( s, "{%d:%d:%d}",
394 &i_dummy, &i_dummy, &i_dummy ) == 3 )
396 p_sys->i_type = SUB_TYPE_PSB;
399 else if( strcasestr( s, "<time" ) )
401 p_sys->i_type = SUB_TYPE_RT;
411 /* It will nearly always work even for non seekable stream thanks the
412 * caching system, and if it fails we lose just a few sub */
413 if( stream_Seek( p_demux->s, 0 ) )
415 msg_Warn( p_demux, "failed to rewind" );
419 /* Quit on unknown subtitles */
420 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
422 msg_Err( p_demux, "failed to recognize subtitle type" );
429 if( sub_read_subtitle_function[i].i_type == p_sys->i_type )
431 msg_Dbg( p_demux, "detected %s format",
432 sub_read_subtitle_function[i].psz_name );
433 pf_read = sub_read_subtitle_function[i].pf_read;
438 msg_Dbg( p_demux, "loading all subtitles..." );
440 /* Load the whole file */
441 TextLoad( &p_sys->txt, p_demux->s );
446 if( p_sys->i_subtitles >= i_max )
449 if( !( p_sys->subtitle = realloc( p_sys->subtitle,
450 sizeof(subtitle_t) * i_max ) ) )
452 free( p_sys->subtitle );
453 TextUnload( &p_sys->txt );
459 if( pf_read( p_demux, &p_sys->subtitle[p_sys->i_subtitles],
460 p_sys->i_subtitles ) )
463 p_sys->i_subtitles++;
466 TextUnload( &p_sys->txt );
468 msg_Dbg(p_demux, "loaded %d subtitles", p_sys->i_subtitles );
470 /* Fix subtitle (order and time) *** */
471 p_sys->i_subtitle = 0;
473 if( p_sys->i_subtitles > 0 )
475 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_stop;
477 if( p_sys->i_length <= 0 )
478 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_start+1;
481 /* *** add subtitle ES *** */
482 if( p_sys->i_type == SUB_TYPE_SSA1 ||
483 p_sys->i_type == SUB_TYPE_SSA2_4 ||
484 p_sys->i_type == SUB_TYPE_ASS )
486 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','s','a',' ' ) );
490 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','u','b','t' ) );
492 if( p_sys->psz_header != NULL )
494 fmt.i_extra = strlen( p_sys->psz_header ) + 1;
495 fmt.p_extra = strdup( p_sys->psz_header );
497 p_sys->es = es_out_Add( p_demux->out, &fmt );
502 /*****************************************************************************
503 * Close: Close subtitle demux
504 *****************************************************************************/
505 static void Close( vlc_object_t *p_this )
507 demux_t *p_demux = (demux_t*)p_this;
508 demux_sys_t *p_sys = p_demux->p_sys;
511 for( i = 0; i < p_sys->i_subtitles; i++ )
512 free( p_sys->subtitle[i].psz_text );
513 free( p_sys->subtitle );
518 /*****************************************************************************
520 *****************************************************************************/
521 static int Control( demux_t *p_demux, int i_query, va_list args )
523 demux_sys_t *p_sys = p_demux->p_sys;
529 case DEMUX_GET_LENGTH:
530 pi64 = (int64_t*)va_arg( args, int64_t * );
531 *pi64 = p_sys->i_length;
535 pi64 = (int64_t*)va_arg( args, int64_t * );
536 if( p_sys->i_subtitle < p_sys->i_subtitles )
538 *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;
544 i64 = (int64_t)va_arg( args, int64_t );
545 p_sys->i_subtitle = 0;
546 while( p_sys->i_subtitle < p_sys->i_subtitles &&
547 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
552 if( p_sys->i_subtitle >= p_sys->i_subtitles )
556 case DEMUX_GET_POSITION:
557 pf = (double*)va_arg( args, double * );
558 if( p_sys->i_subtitle >= p_sys->i_subtitles )
562 else if( p_sys->i_subtitles > 0 )
564 *pf = (double)p_sys->subtitle[p_sys->i_subtitle].i_start /
565 (double)p_sys->i_length;
573 case DEMUX_SET_POSITION:
574 f = (double)va_arg( args, double );
575 i64 = f * p_sys->i_length;
577 p_sys->i_subtitle = 0;
578 while( p_sys->i_subtitle < p_sys->i_subtitles &&
579 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
583 if( p_sys->i_subtitle >= p_sys->i_subtitles )
587 case DEMUX_SET_NEXT_DEMUX_TIME:
588 p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t );
593 case DEMUX_GET_ATTACHMENTS:
594 case DEMUX_GET_TITLE_INFO:
595 case DEMUX_HAS_UNSUPPORTED_META:
599 msg_Err( p_demux, "unknown query %d in subtitle control", i_query );
604 /*****************************************************************************
605 * Demux: Send subtitle to decoder
606 *****************************************************************************/
607 static int Demux( demux_t *p_demux )
609 demux_sys_t *p_sys = p_demux->p_sys;
612 if( p_sys->i_subtitle >= p_sys->i_subtitles )
615 i_maxdate = p_sys->i_next_demux_date - var_GetTime( p_demux->p_parent, "spu-delay" );;
616 if( i_maxdate <= 0 && p_sys->i_subtitle < p_sys->i_subtitles )
618 /* Should not happen */
619 i_maxdate = p_sys->subtitle[p_sys->i_subtitle].i_start + 1;
622 while( p_sys->i_subtitle < p_sys->i_subtitles &&
623 p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
626 int i_len = strlen( p_sys->subtitle[p_sys->i_subtitle].psz_text ) + 1;
635 if( ( p_block = block_New( p_demux, i_len ) ) == NULL )
641 if( p_sys->subtitle[p_sys->i_subtitle].i_start < 0 )
647 p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
648 p_block->i_dts = p_block->i_pts;
649 if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )
652 p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;
655 memcpy( p_block->p_buffer,
656 p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );
657 if( p_block->i_pts > 0 )
659 es_out_Send( p_demux->out, p_sys->es, p_block );
663 block_Release( p_block );
669 p_sys->i_next_demux_date = 0;
674 /*****************************************************************************
675 * Fix: fix time stamp and order of subtitle
676 *****************************************************************************/
677 #ifdef USE_THIS_UNUSED_PIECE_OF_CODE
678 static void Fix( demux_t *p_demux )
680 demux_sys_t *p_sys = p_demux->p_sys;
684 /* *** fix order (to be sure...) *** */
685 /* We suppose that there are near in order and this durty bubble sort
686 * wont take too much time
691 for( i_index = 1; i_index < p_sys->i_subtitles; i_index++ )
693 if( p_sys->subtitle[i_index].i_start <
694 p_sys->subtitle[i_index - 1].i_start )
698 p_sys->subtitle + i_index - 1,
699 sizeof( subtitle_t ) );
700 memcpy( p_sys->subtitle + i_index - 1,
701 p_sys->subtitle + i_index,
702 sizeof( subtitle_t ) );
703 memcpy( p_sys->subtitle + i_index,
705 sizeof( subtitle_t ) );
713 static int TextLoad( text_t *txt, stream_t *s )
719 txt->i_line_count = 0;
721 txt->line = calloc( i_line_max, sizeof( char * ) );
723 /* load the complete file */
726 char *psz = stream_ReadLine( s );
731 txt->line[txt->i_line_count++] = psz;
732 if( txt->i_line_count >= i_line_max )
735 txt->line = realloc( txt->line, i_line_max * sizeof( char * ) );
739 if( txt->i_line_count <= 0 )
747 static void TextUnload( text_t *txt )
751 for( i = 0; i < txt->i_line_count; i++ )
753 free( txt->line[i] );
757 txt->i_line_count = 0;
760 static char *TextGetLine( text_t *txt )
762 if( txt->i_line >= txt->i_line_count )
765 return txt->line[txt->i_line++];
767 static void TextPreviousLine( text_t *txt )
769 if( txt->i_line > 0 )
773 /*****************************************************************************
774 * Specific Subtitle function
775 *****************************************************************************/
778 * {n1}{n2}Line1|Line2|Line3....
779 * where n1 and n2 are the video frame number (n2 can be empty)
781 static int ParseMicroDvd( demux_t *p_demux, subtitle_t *p_subtitle,
785 demux_sys_t *p_sys = p_demux->p_sys;
786 text_t *txt = &p_sys->txt;
794 const char *s = TextGetLine( txt );
798 psz_text = malloc( strlen(s) + 1 );
804 if( sscanf( s, "{%d}{}%[^\r\n]", &i_start, psz_text ) == 2 ||
805 sscanf( s, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
808 if( i_start != 1 || i_stop != 1 )
811 /* We found a possible setting of the framerate "{1}{1}23.976" */
812 /* Check if it's usable, and if the sub-fps is not set */
813 f_fps = us_strtod( psz_text, NULL );
814 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
815 p_sys->i_microsecperframe = (int64_t)((float)1000000 / f_fps);
820 /* replace | by \n */
821 for( i = 0; psz_text[i] != '\0'; i++ )
823 if( psz_text[i] == '|' )
828 p_subtitle->i_start = i_start * p_sys->i_microsecperframe;
829 p_subtitle->i_stop = i_stop * p_sys->i_microsecperframe;
830 p_subtitle->psz_text = psz_text;
834 /* ParseSubRipSubViewer
837 * h1:m1:s1,d1 --> h2:m2:s2,d2
842 * Format SubViewer v1/v2
843 * h1:m1:s1.d1,h2:m2:s2.d2
848 * We ignore line number for SubRip
850 static int ParseSubRipSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
854 demux_sys_t *p_sys = p_demux->p_sys;
855 text_t *txt = &p_sys->txt;
860 const char *s = TextGetLine( txt );
861 int h1, m1, s1, d1, h2, m2, s2, d2;
866 if( sscanf( s, psz_fmt,
868 &h2, &m2, &s2, &d2 ) == 8 )
870 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
871 (int64_t)m1 * 60*1000 +
873 (int64_t)d1 ) * 1000;
875 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
876 (int64_t)m2 * 60*1000 +
878 (int64_t)d2 ) * 1000;
883 /* Now read text until an empty line */
884 psz_text = strdup("");
889 const char *s = TextGetLine( txt );
902 p_subtitle->psz_text = psz_text;
906 i_old = strlen( psz_text );
907 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
910 strcat( psz_text, s );
911 strcat( psz_text, "\n" );
913 /* replace [br] by \n */
918 while( ( p = strstr( psz_text, "[br]" ) ) )
921 memmove( p, &p[3], strlen(&p[3])+1 );
928 static int ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle,
932 return ParseSubRipSubViewer( p_demux, p_subtitle,
933 "%d:%d:%d,%d --> %d:%d:%d,%d",
938 static int ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
943 return ParseSubRipSubViewer( p_demux, p_subtitle,
944 "%d:%d:%d.%d,%d:%d:%d.%d",
950 static int ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle,
953 demux_sys_t *p_sys = p_demux->p_sys;
954 text_t *txt = &p_sys->txt;
958 const char *s = TextGetLine( txt );
959 int h1, m1, s1, c1, h2, m2, s2, c2;
966 /* We expect (SSA2-4):
967 * Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
968 * Dialogue: Marked=0,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
970 * SSA-1 is similar but only has 8 commas up untill the subtitle text. Probably the Effect field is no present, but not 100 % sure.
974 * Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
975 * Dialogue: Layer#,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
978 /* The output text is - at least, not removing numbers - 18 chars shorter than the input text. */
979 psz_text = malloc( strlen(s) );
984 "Dialogue: %15[^,],%d:%d:%d.%d,%d:%d:%d.%d,%[^\r\n]",
990 /* The dec expects: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */
991 /* (Layer comes from ASS specs ... it's empty for SSA.) */
992 if( p_sys->i_type == SUB_TYPE_SSA1 )
994 /* SSA1 has only 8 commas before the text starts, not 9 */
995 memmove( &psz_text[1], psz_text, strlen(psz_text)+1 );
1000 int i_layer = ( p_sys->i_type == SUB_TYPE_ASS ) ? atoi( temp ) : 0;
1002 /* ReadOrder, Layer, %s(rest of fields) */
1003 snprintf( temp, sizeof(temp), "%d,%d,", i_idx, i_layer );
1004 memmove( psz_text + strlen(temp), psz_text, strlen(psz_text)+1 );
1005 memcpy( psz_text, temp, strlen(temp) );
1008 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1009 (int64_t)m1 * 60*1000 +
1010 (int64_t)s1 * 1000 +
1011 (int64_t)c1 * 10 ) * 1000;
1012 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1013 (int64_t)m2 * 60*1000 +
1014 (int64_t)s2 * 1000 +
1015 (int64_t)c2 * 10 ) * 1000;
1016 p_subtitle->psz_text = psz_text;
1021 /* All the other stuff we add to the header field */
1022 if( !p_sys->psz_header )
1023 p_sys->psz_header = strdup( "" );
1024 if( !p_sys->psz_header )
1028 realloc( p_sys->psz_header,
1029 strlen( p_sys->psz_header ) + strlen( s ) + 2 );
1030 strcat( p_sys->psz_header, s );
1031 strcat( p_sys->psz_header, "\n" );
1037 * h:m:s:Line1|Line2|Line3....
1039 * h:m:s Line1|Line2|Line3....
1041 static int ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle,
1044 VLC_UNUSED( i_idx );
1046 demux_sys_t *p_sys = p_demux->p_sys;
1047 text_t *txt = &p_sys->txt;
1053 const char *s = TextGetLine( txt );
1057 return VLC_EGENERIC;
1059 psz_text = malloc( strlen( s ) + 1 );
1063 if( sscanf( s, "%d:%d:%d%*c%[^\r\n]",
1064 &h1, &m1, &s1, psz_text ) == 4 )
1066 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1067 (int64_t)m1 * 60*1000 +
1068 (int64_t)s1 * 1000 ) * 1000;
1069 p_subtitle->i_stop = 0;
1075 /* replace | by \n */
1076 for( i = 0; psz_text[i] != '\0'; i++ )
1078 if( psz_text[i] == '|' )
1081 p_subtitle->psz_text = psz_text;
1087 static char *ParseSamiSearch( text_t *txt,
1088 char *psz_start, const char *psz_str )
1090 if( psz_start && strcasestr( psz_start, psz_str ) )
1092 char *s = strcasestr( psz_start, psz_str );
1093 return &s[strlen( psz_str )];
1098 char *p = TextGetLine( txt );
1102 if( strcasestr( p, psz_str ) )
1104 char *s = strcasestr( p, psz_str );
1105 return &s[strlen( psz_str )];
1109 static int ParseSami( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1111 VLC_UNUSED( i_idx );
1112 demux_sys_t *p_sys = p_demux->p_sys;
1113 text_t *txt = &p_sys->txt;
1118 unsigned int i_text;
1119 char text[8192]; /* Arbitrary but should be long enough */
1121 /* search "Start=" */
1122 if( !( s = ParseSamiSearch( txt, NULL, "Start=" ) ) )
1123 return VLC_EGENERIC;
1125 /* get start value */
1126 i_start = strtol( s, &s, 0 );
1129 if( !( s = ParseSamiSearch( txt, s, "<P" ) ) )
1130 return VLC_EGENERIC;
1133 if( !( s = ParseSamiSearch( txt, s, ">" ) ) )
1134 return VLC_EGENERIC;
1138 /* now get all txt until a "Start=" line */
1142 /* Search non empty line */
1143 while( s && *s == '\0' )
1144 s = TextGetLine( txt );
1150 if( !strncasecmp( s, "<br", 3 ) )
1154 else if( strcasestr( s, "Start=" ) )
1156 TextPreviousLine( txt );
1159 s = ParseSamiSearch( txt, s, ">" );
1161 else if( !strncmp( s, " ", 6 ) )
1166 else if( *s == '\t' )
1176 if( c != '\0' && i_text+1 < sizeof(text) )
1179 text[i_text] = '\0';
1183 p_subtitle->i_start = i_start * 1000;
1184 p_subtitle->i_stop = 0;
1185 p_subtitle->psz_text = strdup( text );
1197 * TODO it can have a header
1204 * LANG support would be cool
1205 * CODEPAGE is probably mandatory FIXME
1207 static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle,
1210 VLC_UNUSED( i_idx );
1212 demux_sys_t *p_sys = p_demux->p_sys;
1213 text_t *txt = &p_sys->txt;
1218 const char *s = TextGetLine( txt );
1222 return VLC_EGENERIC;
1226 &h1, &m1, &s1, &c1 ) == 4 )
1228 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1229 (int64_t)m1 * 60*1000 +
1230 (int64_t)s1 * 1000 +
1231 (int64_t)c1 * 10) * 1000;
1232 p_subtitle->i_stop = 0;
1237 /* Now read text until a line containing "}" */
1238 psz_text = strdup("");
1243 const char *s = TextGetLine( txt );
1250 return VLC_EGENERIC;
1253 i_len = strlen( s );
1254 if( i_len == 1 && s[0] == '}')
1256 p_subtitle->psz_text = psz_text;
1260 i_old = strlen( psz_text );
1261 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1264 strcat( psz_text, s );
1265 strcat( psz_text, "\n" );
1271 * [n1][n2]Line1|Line2|Line3...
1272 * where n1 and n2 are the video frame number (n2 can be empty)
1274 static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1276 VLC_UNUSED( i_idx );
1278 demux_sys_t *p_sys = p_demux->p_sys;
1279 text_t *txt = &p_sys->txt;
1285 const char *s = TextGetLine( txt );
1290 return VLC_EGENERIC;
1292 psz_text = malloc( strlen(s) + 1 );
1298 if( sscanf( s, "[%d][] %[^\r\n]", &i_start, psz_text ) == 2 ||
1299 sscanf( s, "[%d][%d] %[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
1301 p_subtitle->i_start = (int64_t)i_start * 100000;
1302 p_subtitle->i_stop = (int64_t)i_stop * 100000;
1308 for( i = 0; psz_text[i] != '\0'; )
1310 /* replace | by \n */
1311 if( psz_text[i] == '|' )
1315 if( psz_text[i] == '/' && ( i == 0 || psz_text[i-1] == '\n' ) )
1316 memmove( &psz_text[i], &psz_text[i+1], strlen(&psz_text[i+1])+1 );
1320 p_subtitle->psz_text = psz_text;
1324 static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1326 VLC_UNUSED( i_idx );
1328 demux_sys_t *p_sys = p_demux->p_sys;
1329 text_t *txt = &p_sys->txt;
1330 char *psz_text = strdup( "" );
1332 int i_firstline = 1;
1338 const char *s = TextGetLine( txt );
1341 return VLC_EGENERIC;
1344 if( sscanf (s, "-->> %d", &t) == 1)
1346 p_subtitle->i_start = (int64_t)t; /* * FPS*/
1347 p_subtitle->i_stop = 0;
1349 /* Starting of a subtitle */
1354 /* We have been too far: end of the subtitle, begin of next */
1357 TextPreviousLine( txt );
1364 i_old = strlen( psz_text ) + 1;
1365 psz_text = realloc( psz_text, i_old + strlen( s ) + 1 );
1368 strcat( psz_text, s );
1369 strcat( psz_text, "\n" );
1370 if( txt->i_line == txt->i_line_count )
1374 p_subtitle->psz_text = psz_text;
1378 static int ParsePJS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1380 VLC_UNUSED( i_idx );
1382 demux_sys_t *p_sys = p_demux->p_sys;
1383 text_t *txt = &p_sys->txt;
1389 const char *s = TextGetLine( txt );
1393 return VLC_EGENERIC;
1395 psz_text = malloc( strlen(s) + 1 );
1400 if( sscanf (s, "%d,%d,\"%[^\n\r]", &t1, &t2, psz_text ) == 3 )
1402 /* 1/10th of second ? Frame based ? FIXME */
1403 p_subtitle->i_start = 10 * t1;
1404 p_subtitle->i_stop = 10 * t2;
1405 /* Remove latest " */
1406 psz_text[ strlen(psz_text) - 1 ] = '\0';
1413 /* replace | by \n */
1414 for( i = 0; psz_text[i] != '\0'; i++ )
1416 if( psz_text[i] == '|' )
1420 p_subtitle->psz_text = psz_text;
1421 msg_Dbg( p_demux, "%s", psz_text );
1425 static float mpsub_total = 0.0;
1426 static float mpsub_factor = 0.0;
1428 static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1430 VLC_UNUSED( i_idx );
1432 demux_sys_t *p_sys = p_demux->p_sys;
1433 text_t *txt = &p_sys->txt;
1434 char *psz_text = strdup( "" );
1442 const char *s = TextGetLine( txt );
1444 return VLC_EGENERIC;
1446 if( strstr( s, "FORMAT" ) )
1448 if( sscanf (s, "FORMAT=TIM%c", &p_dummy ) == 1 && p_dummy == 'E')
1450 mpsub_factor = 100.0;
1454 psz_temp = malloc( strlen(s) );
1458 if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
1461 f_fps = us_strtod( psz_temp, NULL );
1462 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
1463 var_SetFloat( p_demux, "sub-fps", f_fps );
1472 f1 = us_strtod( s, &psz_temp );
1475 f2 = us_strtod( psz_temp, NULL );
1476 mpsub_total += f1 * mpsub_factor;
1477 p_subtitle->i_start = (int64_t)(10000.0 * mpsub_total);
1478 mpsub_total += f2 * mpsub_factor;
1479 p_subtitle->i_stop = (int64_t)(10000.0 * mpsub_total);
1486 const char *s = TextGetLine( txt );
1489 return VLC_EGENERIC;
1491 int i_len = strlen( s );
1495 int i_old = strlen( psz_text );
1497 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1501 strcat( psz_text, s );
1502 strcat( psz_text, "\n" );
1505 p_subtitle->psz_text = psz_text;
1509 static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1511 VLC_UNUSED( i_idx );
1513 demux_sys_t *p_sys = p_demux->p_sys;
1514 text_t *txt = &p_sys->txt;
1515 char *psz_text, *psz_orig;
1516 char *psz_text2, *psz_orig2;
1517 int h1, h2, m1, m2, s1, s2, f1, f2;
1519 static int i_comment = 0;
1521 static int jss_time_resolution = 30;
1522 static int jss_time_shift = 0;
1524 /* Parse the main lines */
1527 const char *s = TextGetLine( txt );
1529 return VLC_EGENERIC;
1531 psz_orig = malloc( strlen( s ) + 1 );
1534 psz_text = psz_orig;
1536 /* Complete time lines */
1537 if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]",
1538 &h1, &m1, &s1, &f1, &h2, &m2, &s2, &f2, psz_text ) == 9 )
1540 p_subtitle->i_start = ( (int64_t)( h1 *3600 + m1 * 60 + s1 ) +
1541 (int64_t)( ( f1 + jss_time_shift ) / jss_time_resolution ) )
1543 p_subtitle->i_stop = ( (int64_t)( h2 *3600 + m2 * 60 + s2 ) +
1544 (int64_t)( ( f2 + jss_time_shift ) / jss_time_resolution ) )
1548 /* Short time lines */
1549 else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 )
1551 p_subtitle->i_start = (int64_t)(
1552 ( f1 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
1553 p_subtitle->i_stop = (int64_t)(
1554 ( f2 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
1557 /* General Directive lines */
1558 /* Only TIME and SHIFT are supported so far */
1559 else if( s[0] == '#' )
1561 int h = 0, m =0, sec = 1, f = 1;
1565 strcpy( psz_text, s );
1567 switch( toupper( psz_text[1] ) )
1570 shift = isalpha( psz_text[2] ) ? 6 : 2 ;
1572 if( sscanf( &psz_text[shift], "%d", &h ) )
1574 /* Negative shifting */
1581 if( sscanf( &psz_text[shift], "%*d:%d", &m ) )
1583 if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) )
1585 sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f );
1590 sscanf( &psz_text[shift], "%d:%d.%d",
1598 sscanf( &psz_text[shift], "%d.%d", &sec, &f);
1601 jss_time_shift = ( ( h * 3600 + m * 60 + sec )
1602 * jss_time_resolution + f ) * inv;
1607 shift = isalpha( psz_text[2] ) ? 8 : 2 ;
1609 sscanf( &psz_text[shift], "%d", &jss_time_resolution );
1616 /* Unkown type line, probably a comment */
1623 while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
1625 const char *s2 = TextGetLine( txt );
1628 return VLC_EGENERIC;
1630 int i_len = strlen( s2 );
1634 int i_old = strlen( psz_text );
1636 psz_text = realloc( psz_text, i_old + i_len + 1 );
1640 psz_orig = psz_text;
1641 strcat( psz_text, s2 );
1644 /* Skip the blanks */
1645 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1647 /* Parse the directives */
1648 if( isalpha( *psz_text ) || *psz_text == '[' )
1650 while( *psz_text != ' ' )
1653 /* Directives are NOT parsed yet */
1654 /* This has probably a better place in a decoder ? */
1655 /* directive = malloc( strlen( psz_text ) + 1 );
1656 if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/
1659 /* Skip the blanks after directives */
1660 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1662 /* Clean all the lines from inline comments and other stuffs */
1663 psz_orig2 = calloc( strlen( psz_text) + 1, 1 );
1664 psz_text2 = psz_orig2;
1666 for( ; *psz_text != '\0' && *psz_text != '\n' && *psz_text != '\r'; )
1677 if( (*(psz_text + 1 ) ) == ' ' ) psz_text++;
1689 if( (*(psz_text + 1 ) ) == ' ' || (*(psz_text + 1 ) ) == '\t' )
1698 if( (*(psz_text + 1 ) ) == 'n' )
1705 if( ( toupper(*(psz_text + 1 ) ) == 'C' ) ||
1706 ( toupper(*(psz_text + 1 ) ) == 'F' ) )
1708 psz_text++; psz_text++;
1711 if( (*(psz_text + 1 ) ) == 'B' || (*(psz_text + 1 ) ) == 'b' ||
1712 (*(psz_text + 1 ) ) == 'I' || (*(psz_text + 1 ) ) == 'i' ||
1713 (*(psz_text + 1 ) ) == 'U' || (*(psz_text + 1 ) ) == 'u' ||
1714 (*(psz_text + 1 ) ) == 'D' || (*(psz_text + 1 ) ) == 'N' )
1719 if( (*(psz_text + 1 ) ) == '~' || (*(psz_text + 1 ) ) == '{' ||
1720 (*(psz_text + 1 ) ) == '\\' )
1722 else if( *(psz_text + 1 ) == '\r' || *(psz_text + 1 ) == '\n' ||
1723 *(psz_text + 1 ) == '\0' )
1731 *psz_text2 = *psz_text;
1738 p_subtitle->psz_text = psz_orig2;
1739 msg_Dbg( p_demux, "%s", p_subtitle->psz_text );
1744 static int ParsePSB( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1746 VLC_UNUSED( i_idx );
1748 demux_sys_t *p_sys = p_demux->p_sys;
1749 text_t *txt = &p_sys->txt;
1757 const char *s = TextGetLine( txt );
1760 return VLC_EGENERIC;
1762 psz_text = malloc( strlen( s ) + 1 );
1766 if( sscanf( s, "{%d:%d:%d}{%d:%d:%d}%[^\r\n]",
1767 &h1, &m1, &s1, &h2, &m2, &s2, psz_text ) == 7 )
1769 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1770 (int64_t)m1 * 60*1000 +
1771 (int64_t)s1 * 1000 ) * 1000;
1772 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1773 (int64_t)m2 * 60*1000 +
1774 (int64_t)s2 * 1000 ) * 1000;
1780 /* replace | by \n */
1781 for( i = 0; psz_text[i] != '\0'; i++ )
1783 if( psz_text[i] == '|' )
1786 p_subtitle->psz_text = psz_text;
1790 static int64_t ParseRealTime( char *psz, int *h, int *m, int *s, int *f )
1792 if( strlen( psz ) == 0 ) return 0;
1793 if( sscanf( psz, "%d:%d:%d.%d", h, m, s, f ) == 4 ||
1794 sscanf( psz, "%d:%d.%d", m, s, f ) == 3 ||
1795 sscanf( psz, "%d.%d", s, f ) == 2 ||
1796 sscanf( psz, "%d:%d", m, s ) == 2 ||
1797 sscanf( psz, "%d", s ) == 1 )
1799 return (int64_t)((( *h * 60 + *m ) * 60 ) + *s ) * 1000 * 1000
1800 + (int64_t)*f * 10 * 1000;
1802 else return VLC_EGENERIC;
1805 static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1807 VLC_UNUSED( i_idx );
1808 demux_sys_t *p_sys = p_demux->p_sys;
1809 text_t *txt = &p_sys->txt;
1811 char psz_end[12]= "", psz_begin[12] = "";
1815 int h1 = 0, m1 = 0, s1 = 0, f1 = 0;
1816 int h2 = 0, m2 = 0, s2 = 0, f2 = 0;
1817 const char *s = TextGetLine( txt );
1820 return VLC_EGENERIC;
1822 psz_text = malloc( strlen( s ) + 1 );
1826 /* Find the good begining. This removes extra spaces at the beginning
1828 char *psz_temp = strcasestr( s, "<time");
1829 if( psz_temp != NULL )
1831 /* Line has begin and end */
1832 if( ( sscanf( psz_temp,
1833 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\" %*[e|E]nd=\"%[^\"]%*[^>]%[^\n\r]",
1834 psz_begin, psz_end, psz_text) != 3 ) &&
1835 /* Line has begin and no end */
1837 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\"%*[^>]%[^\n\r]",
1838 psz_begin, psz_text ) != 2) )
1839 /* Line is not recognized */
1846 int64_t i_time = ParseRealTime( psz_begin, &h1, &m1, &s1, &f1 );
1849 p_subtitle->i_start = i_time;
1852 i_time = ParseRealTime( psz_end, &h2, &m2, &s2, &f2 );
1855 p_subtitle->i_stop = i_time;
1859 /* Line is not recognized */
1864 /* Get the following Lines */
1867 const char *s = TextGetLine( txt );
1870 return VLC_EGENERIC;
1872 int i_len = strlen( s );
1873 if( i_len == 0 ) break;
1875 if( strcasestr( s, "<time" ) ||
1876 strcasestr( s, "<clear/") )
1878 TextPreviousLine( txt );
1882 int i_old = strlen( psz_text );
1884 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1888 strcat( psz_text, s );
1889 strcat( psz_text, "\n" );
1892 /* Remove the starting ">" that remained after the sscanf */
1893 memmove( &psz_text[0], &psz_text[1], strlen( psz_text ) );
1895 p_subtitle->psz_text = psz_text;
1900 static int ParseDKS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1902 VLC_UNUSED( i_idx );
1904 demux_sys_t *p_sys = p_demux->p_sys;
1905 text_t *txt = &p_sys->txt;
1912 char *s = TextGetLine( txt );
1915 return VLC_EGENERIC;
1917 psz_text = malloc( strlen( s ) + 1 );
1921 if( sscanf( s, "[%d:%d:%d]%[^\r\n]",
1922 &h1, &m1, &s1, psz_text ) == 4 )
1924 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1925 (int64_t)m1 * 60*1000 +
1926 (int64_t)s1 * 1000 ) * 1000;
1928 char *s = TextGetLine( txt );
1930 return VLC_EGENERIC;
1932 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1933 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1934 (int64_t)m2 * 60*1000 +
1935 (int64_t)s2 * 1000 ) * 1000;
1941 /* replace [br] by \n */
1943 while( ( p = strstr( psz_text, "[br]" ) ) )
1946 memmove( p, &p[3], strlen(&p[3])+1 );
1949 p_subtitle->psz_text = psz_text;
1953 static int ParseSubViewer1( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1955 VLC_UNUSED( i_idx );
1957 demux_sys_t *p_sys = p_demux->p_sys;
1958 text_t *txt = &p_sys->txt;
1965 char *s = TextGetLine( txt );
1968 return VLC_EGENERIC;
1970 if( sscanf( s, "[%d:%d:%d]", &h1, &m1, &s1 ) == 3 )
1972 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1973 (int64_t)m1 * 60*1000 +
1974 (int64_t)s1 * 1000 ) * 1000;
1976 char *s = TextGetLine( txt );
1978 return VLC_EGENERIC;
1980 psz_text = strdup( s );
1984 s = TextGetLine( txt );
1986 return VLC_EGENERIC;
1988 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1989 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1990 (int64_t)m2 * 60*1000 +
1991 (int64_t)s2 * 1000 ) * 1000;
1996 p_subtitle->psz_text = psz_text;