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" );
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 msg_Err( p_demux, "out of memory");
453 free( p_sys->subtitle );
454 TextUnload( &p_sys->txt );
460 if( pf_read( p_demux, &p_sys->subtitle[p_sys->i_subtitles],
461 p_sys->i_subtitles ) )
464 p_sys->i_subtitles++;
467 TextUnload( &p_sys->txt );
469 msg_Dbg(p_demux, "loaded %d subtitles", p_sys->i_subtitles );
471 /* Fix subtitle (order and time) *** */
472 p_sys->i_subtitle = 0;
474 if( p_sys->i_subtitles > 0 )
476 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_stop;
478 if( p_sys->i_length <= 0 )
479 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_start+1;
482 /* *** add subtitle ES *** */
483 if( p_sys->i_type == SUB_TYPE_SSA1 ||
484 p_sys->i_type == SUB_TYPE_SSA2_4 ||
485 p_sys->i_type == SUB_TYPE_ASS )
487 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','s','a',' ' ) );
491 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','u','b','t' ) );
493 if( p_sys->psz_header != NULL )
495 fmt.i_extra = strlen( p_sys->psz_header ) + 1;
496 fmt.p_extra = strdup( p_sys->psz_header );
498 p_sys->es = es_out_Add( p_demux->out, &fmt );
503 /*****************************************************************************
504 * Close: Close subtitle demux
505 *****************************************************************************/
506 static void Close( vlc_object_t *p_this )
508 demux_t *p_demux = (demux_t*)p_this;
509 demux_sys_t *p_sys = p_demux->p_sys;
512 for( i = 0; i < p_sys->i_subtitles; i++ )
513 free( p_sys->subtitle[i].psz_text );
514 free( p_sys->subtitle );
519 /*****************************************************************************
521 *****************************************************************************/
522 static int Control( demux_t *p_demux, int i_query, va_list args )
524 demux_sys_t *p_sys = p_demux->p_sys;
530 case DEMUX_GET_LENGTH:
531 pi64 = (int64_t*)va_arg( args, int64_t * );
532 *pi64 = p_sys->i_length;
536 pi64 = (int64_t*)va_arg( args, int64_t * );
537 if( p_sys->i_subtitle < p_sys->i_subtitles )
539 *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;
545 i64 = (int64_t)va_arg( args, int64_t );
546 p_sys->i_subtitle = 0;
547 while( p_sys->i_subtitle < p_sys->i_subtitles &&
548 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
553 if( p_sys->i_subtitle >= p_sys->i_subtitles )
557 case DEMUX_GET_POSITION:
558 pf = (double*)va_arg( args, double * );
559 if( p_sys->i_subtitle >= p_sys->i_subtitles )
563 else if( p_sys->i_subtitles > 0 )
565 *pf = (double)p_sys->subtitle[p_sys->i_subtitle].i_start /
566 (double)p_sys->i_length;
574 case DEMUX_SET_POSITION:
575 f = (double)va_arg( args, double );
576 i64 = f * p_sys->i_length;
578 p_sys->i_subtitle = 0;
579 while( p_sys->i_subtitle < p_sys->i_subtitles &&
580 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
584 if( p_sys->i_subtitle >= p_sys->i_subtitles )
588 case DEMUX_SET_NEXT_DEMUX_TIME:
589 p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t );
594 case DEMUX_GET_ATTACHMENTS:
595 case DEMUX_GET_TITLE_INFO:
596 case DEMUX_HAS_UNSUPPORTED_META:
600 msg_Err( p_demux, "unknown query %d in subtitle control", i_query );
605 /*****************************************************************************
606 * Demux: Send subtitle to decoder
607 *****************************************************************************/
608 static int Demux( demux_t *p_demux )
610 demux_sys_t *p_sys = p_demux->p_sys;
613 if( p_sys->i_subtitle >= p_sys->i_subtitles )
616 i_maxdate = p_sys->i_next_demux_date - var_GetTime( p_demux->p_parent, "spu-delay" );;
617 if( i_maxdate <= 0 && p_sys->i_subtitle < p_sys->i_subtitles )
619 /* Should not happen */
620 i_maxdate = p_sys->subtitle[p_sys->i_subtitle].i_start + 1;
623 while( p_sys->i_subtitle < p_sys->i_subtitles &&
624 p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
627 int i_len = strlen( p_sys->subtitle[p_sys->i_subtitle].psz_text ) + 1;
636 if( ( p_block = block_New( p_demux, i_len ) ) == NULL )
642 if( p_sys->subtitle[p_sys->i_subtitle].i_start < 0 )
648 p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
649 p_block->i_dts = p_block->i_pts;
650 if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )
653 p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;
656 memcpy( p_block->p_buffer,
657 p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );
658 if( p_block->i_pts > 0 )
660 es_out_Send( p_demux->out, p_sys->es, p_block );
664 block_Release( p_block );
670 p_sys->i_next_demux_date = 0;
675 /*****************************************************************************
676 * Fix: fix time stamp and order of subtitle
677 *****************************************************************************/
678 #ifdef USE_THIS_UNUSED_PIECE_OF_CODE
679 static void Fix( demux_t *p_demux )
681 demux_sys_t *p_sys = p_demux->p_sys;
685 /* *** fix order (to be sure...) *** */
686 /* We suppose that there are near in order and this durty bubble sort
687 * wont take too much time
692 for( i_index = 1; i_index < p_sys->i_subtitles; i_index++ )
694 if( p_sys->subtitle[i_index].i_start <
695 p_sys->subtitle[i_index - 1].i_start )
699 p_sys->subtitle + i_index - 1,
700 sizeof( subtitle_t ) );
701 memcpy( p_sys->subtitle + i_index - 1,
702 p_sys->subtitle + i_index,
703 sizeof( subtitle_t ) );
704 memcpy( p_sys->subtitle + i_index,
706 sizeof( subtitle_t ) );
714 static int TextLoad( text_t *txt, stream_t *s )
720 txt->i_line_count = 0;
722 txt->line = calloc( i_line_max, sizeof( char * ) );
724 /* load the complete file */
727 char *psz = stream_ReadLine( s );
732 txt->line[txt->i_line_count++] = psz;
733 if( txt->i_line_count >= i_line_max )
736 txt->line = realloc( txt->line, i_line_max * sizeof( char * ) );
740 if( txt->i_line_count <= 0 )
748 static void TextUnload( text_t *txt )
752 for( i = 0; i < txt->i_line_count; i++ )
754 free( txt->line[i] );
758 txt->i_line_count = 0;
761 static char *TextGetLine( text_t *txt )
763 if( txt->i_line >= txt->i_line_count )
766 return txt->line[txt->i_line++];
768 static void TextPreviousLine( text_t *txt )
770 if( txt->i_line > 0 )
774 /*****************************************************************************
775 * Specific Subtitle function
776 *****************************************************************************/
779 * {n1}{n2}Line1|Line2|Line3....
780 * where n1 and n2 are the video frame number (n2 can be empty)
782 static int ParseMicroDvd( demux_t *p_demux, subtitle_t *p_subtitle,
786 demux_sys_t *p_sys = p_demux->p_sys;
787 text_t *txt = &p_sys->txt;
795 const char *s = TextGetLine( txt );
799 psz_text = malloc( strlen(s) + 1 );
805 if( sscanf( s, "{%d}{}%[^\r\n]", &i_start, psz_text ) == 2 ||
806 sscanf( s, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
809 if( i_start != 1 || i_stop != 1 )
812 /* We found a possible setting of the framerate "{1}{1}23.976" */
813 /* Check if it's usable, and if the sub-fps is not set */
814 f_fps = us_strtod( psz_text, NULL );
815 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
816 p_sys->i_microsecperframe = (int64_t)((float)1000000 / f_fps);
821 /* replace | by \n */
822 for( i = 0; psz_text[i] != '\0'; i++ )
824 if( psz_text[i] == '|' )
829 p_subtitle->i_start = i_start * p_sys->i_microsecperframe;
830 p_subtitle->i_stop = i_stop * p_sys->i_microsecperframe;
831 p_subtitle->psz_text = psz_text;
835 /* ParseSubRipSubViewer
838 * h1:m1:s1,d1 --> h2:m2:s2,d2
843 * Format SubViewer v1/v2
844 * h1:m1:s1.d1,h2:m2:s2.d2
849 * We ignore line number for SubRip
851 static int ParseSubRipSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
855 demux_sys_t *p_sys = p_demux->p_sys;
856 text_t *txt = &p_sys->txt;
861 const char *s = TextGetLine( txt );
862 int h1, m1, s1, d1, h2, m2, s2, d2;
867 if( sscanf( s, psz_fmt,
869 &h2, &m2, &s2, &d2 ) == 8 )
871 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
872 (int64_t)m1 * 60*1000 +
874 (int64_t)d1 ) * 1000;
876 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
877 (int64_t)m2 * 60*1000 +
879 (int64_t)d2 ) * 1000;
884 /* Now read text until an empty line */
885 psz_text = strdup("");
890 const char *s = TextGetLine( txt );
903 p_subtitle->psz_text = psz_text;
907 i_old = strlen( psz_text );
908 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
911 strcat( psz_text, s );
912 strcat( psz_text, "\n" );
914 /* replace [br] by \n */
919 while( ( p = strstr( psz_text, "[br]" ) ) )
922 memmove( p, &p[3], strlen(&p[3])+1 );
929 static int ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle,
933 return ParseSubRipSubViewer( p_demux, p_subtitle,
934 "%d:%d:%d,%d --> %d:%d:%d,%d",
939 static int ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
944 return ParseSubRipSubViewer( p_demux, p_subtitle,
945 "%d:%d:%d.%d,%d:%d:%d.%d",
951 static int ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle,
954 demux_sys_t *p_sys = p_demux->p_sys;
955 text_t *txt = &p_sys->txt;
959 const char *s = TextGetLine( txt );
960 int h1, m1, s1, c1, h2, m2, s2, c2;
967 /* We expect (SSA2-4):
968 * Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
969 * Dialogue: Marked=0,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
971 * 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.
975 * Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
976 * Dialogue: Layer#,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
979 /* The output text is - at least, not removing numbers - 18 chars shorter than the input text. */
980 psz_text = malloc( strlen(s) );
985 "Dialogue: %15[^,],%d:%d:%d.%d,%d:%d:%d.%d,%[^\r\n]",
991 /* The dec expects: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */
992 /* (Layer comes from ASS specs ... it's empty for SSA.) */
993 if( p_sys->i_type == SUB_TYPE_SSA1 )
995 /* SSA1 has only 8 commas before the text starts, not 9 */
996 memmove( &psz_text[1], psz_text, strlen(psz_text)+1 );
1001 int i_layer = ( p_sys->i_type == SUB_TYPE_ASS ) ? atoi( temp ) : 0;
1003 /* ReadOrder, Layer, %s(rest of fields) */
1004 snprintf( temp, sizeof(temp), "%d,%d,", i_idx, i_layer );
1005 memmove( psz_text + strlen(temp), psz_text, strlen(psz_text)+1 );
1006 memcpy( psz_text, temp, strlen(temp) );
1009 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1010 (int64_t)m1 * 60*1000 +
1011 (int64_t)s1 * 1000 +
1012 (int64_t)c1 * 10 ) * 1000;
1013 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1014 (int64_t)m2 * 60*1000 +
1015 (int64_t)s2 * 1000 +
1016 (int64_t)c2 * 10 ) * 1000;
1017 p_subtitle->psz_text = psz_text;
1022 /* All the other stuff we add to the header field */
1023 if( !p_sys->psz_header )
1024 p_sys->psz_header = strdup( "" );
1025 if( !p_sys->psz_header )
1029 realloc( p_sys->psz_header,
1030 strlen( p_sys->psz_header ) + strlen( s ) + 2 );
1031 strcat( p_sys->psz_header, s );
1032 strcat( p_sys->psz_header, "\n" );
1038 * h:m:s:Line1|Line2|Line3....
1040 * h:m:s Line1|Line2|Line3....
1042 static int ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle,
1045 VLC_UNUSED( i_idx );
1047 demux_sys_t *p_sys = p_demux->p_sys;
1048 text_t *txt = &p_sys->txt;
1054 const char *s = TextGetLine( txt );
1058 return VLC_EGENERIC;
1060 psz_text = malloc( strlen( s ) + 1 );
1064 if( sscanf( s, "%d:%d:%d%*c%[^\r\n]",
1065 &h1, &m1, &s1, psz_text ) == 4 )
1067 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1068 (int64_t)m1 * 60*1000 +
1069 (int64_t)s1 * 1000 ) * 1000;
1070 p_subtitle->i_stop = 0;
1076 /* replace | by \n */
1077 for( i = 0; psz_text[i] != '\0'; i++ )
1079 if( psz_text[i] == '|' )
1082 p_subtitle->psz_text = psz_text;
1088 static char *ParseSamiSearch( text_t *txt,
1089 char *psz_start, const char *psz_str )
1091 if( psz_start && strcasestr( psz_start, psz_str ) )
1093 char *s = strcasestr( psz_start, psz_str );
1094 return &s[strlen( psz_str )];
1099 char *p = TextGetLine( txt );
1103 if( strcasestr( p, psz_str ) )
1105 char *s = strcasestr( p, psz_str );
1106 return &s[strlen( psz_str )];
1110 static int ParseSami( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1112 VLC_UNUSED( i_idx );
1113 demux_sys_t *p_sys = p_demux->p_sys;
1114 text_t *txt = &p_sys->txt;
1119 unsigned int i_text;
1120 char text[8192]; /* Arbitrary but should be long enough */
1122 /* search "Start=" */
1123 if( !( s = ParseSamiSearch( txt, NULL, "Start=" ) ) )
1124 return VLC_EGENERIC;
1126 /* get start value */
1127 i_start = strtol( s, &s, 0 );
1130 if( !( s = ParseSamiSearch( txt, s, "<P" ) ) )
1131 return VLC_EGENERIC;
1134 if( !( s = ParseSamiSearch( txt, s, ">" ) ) )
1135 return VLC_EGENERIC;
1139 /* now get all txt until a "Start=" line */
1143 /* Search non empty line */
1144 while( s && *s == '\0' )
1145 s = TextGetLine( txt );
1151 if( !strncasecmp( s, "<br", 3 ) )
1155 else if( strcasestr( s, "Start=" ) )
1157 TextPreviousLine( txt );
1160 s = ParseSamiSearch( txt, s, ">" );
1162 else if( !strncmp( s, " ", 6 ) )
1167 else if( *s == '\t' )
1177 if( c != '\0' && i_text+1 < sizeof(text) )
1180 text[i_text] = '\0';
1184 p_subtitle->i_start = i_start * 1000;
1185 p_subtitle->i_stop = 0;
1186 p_subtitle->psz_text = strdup( text );
1198 * TODO it can have a header
1205 * LANG support would be cool
1206 * CODEPAGE is probably mandatory FIXME
1208 static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle,
1211 VLC_UNUSED( i_idx );
1213 demux_sys_t *p_sys = p_demux->p_sys;
1214 text_t *txt = &p_sys->txt;
1219 const char *s = TextGetLine( txt );
1223 return VLC_EGENERIC;
1227 &h1, &m1, &s1, &c1 ) == 4 )
1229 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1230 (int64_t)m1 * 60*1000 +
1231 (int64_t)s1 * 1000 +
1232 (int64_t)c1 * 10) * 1000;
1233 p_subtitle->i_stop = 0;
1238 /* Now read text until a line containing "}" */
1239 psz_text = strdup("");
1244 const char *s = TextGetLine( txt );
1251 return VLC_EGENERIC;
1254 i_len = strlen( s );
1255 if( i_len == 1 && s[0] == '}')
1257 p_subtitle->psz_text = psz_text;
1261 i_old = strlen( psz_text );
1262 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1265 strcat( psz_text, s );
1266 strcat( psz_text, "\n" );
1272 * [n1][n2]Line1|Line2|Line3...
1273 * where n1 and n2 are the video frame number (n2 can be empty)
1275 static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1277 VLC_UNUSED( i_idx );
1279 demux_sys_t *p_sys = p_demux->p_sys;
1280 text_t *txt = &p_sys->txt;
1286 const char *s = TextGetLine( txt );
1291 return VLC_EGENERIC;
1293 psz_text = malloc( strlen(s) + 1 );
1299 if( sscanf( s, "[%d][] %[^\r\n]", &i_start, psz_text ) == 2 ||
1300 sscanf( s, "[%d][%d] %[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
1302 p_subtitle->i_start = (int64_t)i_start * 100000;
1303 p_subtitle->i_stop = (int64_t)i_stop * 100000;
1309 for( i = 0; psz_text[i] != '\0'; )
1311 /* replace | by \n */
1312 if( psz_text[i] == '|' )
1316 if( psz_text[i] == '/' && ( i == 0 || psz_text[i-1] == '\n' ) )
1317 memmove( &psz_text[i], &psz_text[i+1], strlen(&psz_text[i+1])+1 );
1321 p_subtitle->psz_text = psz_text;
1325 static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1327 VLC_UNUSED( i_idx );
1329 demux_sys_t *p_sys = p_demux->p_sys;
1330 text_t *txt = &p_sys->txt;
1331 char *psz_text = strdup( "" );
1333 int i_firstline = 1;
1339 const char *s = TextGetLine( txt );
1342 return VLC_EGENERIC;
1345 if( sscanf (s, "-->> %d", &t) == 1)
1347 p_subtitle->i_start = (int64_t)t; /* * FPS*/
1348 p_subtitle->i_stop = 0;
1350 /* Starting of a subtitle */
1355 /* We have been too far: end of the subtitle, begin of next */
1358 TextPreviousLine( txt );
1365 i_old = strlen( psz_text ) + 1;
1366 psz_text = realloc( psz_text, i_old + strlen( s ) + 1 );
1369 strcat( psz_text, s );
1370 strcat( psz_text, "\n" );
1371 if( txt->i_line == txt->i_line_count )
1375 p_subtitle->psz_text = psz_text;
1379 static int ParsePJS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1381 VLC_UNUSED( i_idx );
1383 demux_sys_t *p_sys = p_demux->p_sys;
1384 text_t *txt = &p_sys->txt;
1390 const char *s = TextGetLine( txt );
1394 return VLC_EGENERIC;
1396 psz_text = malloc( strlen(s) + 1 );
1401 if( sscanf (s, "%d,%d,\"%[^\n\r]", &t1, &t2, psz_text ) == 3 )
1403 /* 1/10th of second ? Frame based ? FIXME */
1404 p_subtitle->i_start = 10 * t1;
1405 p_subtitle->i_stop = 10 * t2;
1406 /* Remove latest " */
1407 psz_text[ strlen(psz_text) - 1 ] = '\0';
1414 /* replace | by \n */
1415 for( i = 0; psz_text[i] != '\0'; i++ )
1417 if( psz_text[i] == '|' )
1421 p_subtitle->psz_text = psz_text;
1422 msg_Dbg( p_demux, "%s", psz_text );
1426 static float mpsub_total = 0.0;
1427 static float mpsub_factor = 0.0;
1429 static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1431 VLC_UNUSED( i_idx );
1433 demux_sys_t *p_sys = p_demux->p_sys;
1434 text_t *txt = &p_sys->txt;
1435 char *psz_text = strdup( "" );
1443 const char *s = TextGetLine( txt );
1445 return VLC_EGENERIC;
1447 if( strstr( s, "FORMAT" ) )
1449 if( sscanf (s, "FORMAT=TIM%c", &p_dummy ) == 1 && p_dummy == 'E')
1451 mpsub_factor = 100.0;
1455 psz_temp = malloc( strlen(s) );
1459 if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
1462 f_fps = us_strtod( psz_temp, NULL );
1463 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
1464 var_SetFloat( p_demux, "sub-fps", f_fps );
1473 f1 = us_strtod( s, &psz_temp );
1476 f2 = us_strtod( psz_temp, NULL );
1477 mpsub_total += f1 * mpsub_factor;
1478 p_subtitle->i_start = (int64_t)(10000.0 * mpsub_total);
1479 mpsub_total += f2 * mpsub_factor;
1480 p_subtitle->i_stop = (int64_t)(10000.0 * mpsub_total);
1487 const char *s = TextGetLine( txt );
1490 return VLC_EGENERIC;
1492 int i_len = strlen( s );
1496 int i_old = strlen( psz_text );
1498 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1502 strcat( psz_text, s );
1503 strcat( psz_text, "\n" );
1506 p_subtitle->psz_text = psz_text;
1510 static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1512 VLC_UNUSED( i_idx );
1514 demux_sys_t *p_sys = p_demux->p_sys;
1515 text_t *txt = &p_sys->txt;
1516 char *psz_text, *psz_orig;
1517 char *psz_text2, *psz_orig2;
1518 int h1, h2, m1, m2, s1, s2, f1, f2;
1520 static int i_comment = 0;
1522 static int jss_time_resolution = 30;
1523 static int jss_time_shift = 0;
1525 /* Parse the main lines */
1528 const char *s = TextGetLine( txt );
1530 return VLC_EGENERIC;
1532 psz_orig = malloc( strlen( s ) + 1 );
1535 psz_text = psz_orig;
1537 /* Complete time lines */
1538 if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]",
1539 &h1, &m1, &s1, &f1, &h2, &m2, &s2, &f2, psz_text ) == 9 )
1541 p_subtitle->i_start = ( (int64_t)( h1 *3600 + m1 * 60 + s1 ) +
1542 (int64_t)( ( f1 + jss_time_shift ) / jss_time_resolution ) )
1544 p_subtitle->i_stop = ( (int64_t)( h2 *3600 + m2 * 60 + s2 ) +
1545 (int64_t)( ( f2 + jss_time_shift ) / jss_time_resolution ) )
1549 /* Short time lines */
1550 else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 )
1552 p_subtitle->i_start = (int64_t)(
1553 ( f1 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
1554 p_subtitle->i_stop = (int64_t)(
1555 ( f2 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
1558 /* General Directive lines */
1559 /* Only TIME and SHIFT are supported so far */
1560 else if( s[0] == '#' )
1562 int h = 0, m =0, sec = 1, f = 1;
1566 strcpy( psz_text, s );
1568 switch( toupper( psz_text[1] ) )
1571 shift = isalpha( psz_text[2] ) ? 6 : 2 ;
1573 if( sscanf( &psz_text[shift], "%d", &h ) )
1575 /* Negative shifting */
1582 if( sscanf( &psz_text[shift], "%*d:%d", &m ) )
1584 if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) )
1586 sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f );
1591 sscanf( &psz_text[shift], "%d:%d.%d",
1599 sscanf( &psz_text[shift], "%d.%d", &sec, &f);
1602 jss_time_shift = ( ( h * 3600 + m * 60 + sec )
1603 * jss_time_resolution + f ) * inv;
1608 shift = isalpha( psz_text[2] ) ? 8 : 2 ;
1610 sscanf( &psz_text[shift], "%d", &jss_time_resolution );
1617 /* Unkown type line, probably a comment */
1624 while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
1626 const char *s2 = TextGetLine( txt );
1629 return VLC_EGENERIC;
1631 int i_len = strlen( s2 );
1635 int i_old = strlen( psz_text );
1637 psz_text = realloc( psz_text, i_old + i_len + 1 );
1641 psz_orig = psz_text;
1642 strcat( psz_text, s2 );
1645 /* Skip the blanks */
1646 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1648 /* Parse the directives */
1649 if( isalpha( *psz_text ) || *psz_text == '[' )
1651 while( *psz_text != ' ' )
1654 /* Directives are NOT parsed yet */
1655 /* This has probably a better place in a decoder ? */
1656 /* directive = malloc( strlen( psz_text ) + 1 );
1657 if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/
1660 /* Skip the blanks after directives */
1661 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1663 /* Clean all the lines from inline comments and other stuffs */
1664 psz_orig2 = calloc( strlen( psz_text) + 1, 1 );
1665 psz_text2 = psz_orig2;
1667 for( ; *psz_text != '\0' && *psz_text != '\n' && *psz_text != '\r'; )
1678 if( (*(psz_text + 1 ) ) == ' ' ) psz_text++;
1690 if( (*(psz_text + 1 ) ) == ' ' || (*(psz_text + 1 ) ) == '\t' )
1699 if( (*(psz_text + 1 ) ) == 'n' )
1706 if( ( toupper(*(psz_text + 1 ) ) == 'C' ) ||
1707 ( toupper(*(psz_text + 1 ) ) == 'F' ) )
1709 psz_text++; psz_text++;
1712 if( (*(psz_text + 1 ) ) == 'B' || (*(psz_text + 1 ) ) == 'b' ||
1713 (*(psz_text + 1 ) ) == 'I' || (*(psz_text + 1 ) ) == 'i' ||
1714 (*(psz_text + 1 ) ) == 'U' || (*(psz_text + 1 ) ) == 'u' ||
1715 (*(psz_text + 1 ) ) == 'D' || (*(psz_text + 1 ) ) == 'N' )
1720 if( (*(psz_text + 1 ) ) == '~' || (*(psz_text + 1 ) ) == '{' ||
1721 (*(psz_text + 1 ) ) == '\\' )
1723 else if( *(psz_text + 1 ) == '\r' || *(psz_text + 1 ) == '\n' ||
1724 *(psz_text + 1 ) == '\0' )
1732 *psz_text2 = *psz_text;
1739 p_subtitle->psz_text = psz_orig2;
1740 msg_Dbg( p_demux, "%s", p_subtitle->psz_text );
1745 static int ParsePSB( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1747 VLC_UNUSED( i_idx );
1749 demux_sys_t *p_sys = p_demux->p_sys;
1750 text_t *txt = &p_sys->txt;
1758 const char *s = TextGetLine( txt );
1761 return VLC_EGENERIC;
1763 psz_text = malloc( strlen( s ) + 1 );
1767 if( sscanf( s, "{%d:%d:%d}{%d:%d:%d}%[^\r\n]",
1768 &h1, &m1, &s1, &h2, &m2, &s2, psz_text ) == 7 )
1770 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1771 (int64_t)m1 * 60*1000 +
1772 (int64_t)s1 * 1000 ) * 1000;
1773 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1774 (int64_t)m2 * 60*1000 +
1775 (int64_t)s2 * 1000 ) * 1000;
1781 /* replace | by \n */
1782 for( i = 0; psz_text[i] != '\0'; i++ )
1784 if( psz_text[i] == '|' )
1787 p_subtitle->psz_text = psz_text;
1791 static int64_t ParseRealTime( char *psz, int *h, int *m, int *s, int *f )
1793 if( strlen( psz ) == 0 ) return 0;
1794 if( sscanf( psz, "%d:%d:%d.%d", h, m, s, f ) == 4 ||
1795 sscanf( psz, "%d:%d.%d", m, s, f ) == 3 ||
1796 sscanf( psz, "%d.%d", s, f ) == 2 ||
1797 sscanf( psz, "%d:%d", m, s ) == 2 ||
1798 sscanf( psz, "%d", s ) == 1 )
1800 return (int64_t)((( *h * 60 + *m ) * 60 ) + *s ) * 1000 * 1000
1801 + (int64_t)*f * 10 * 1000;
1803 else return VLC_EGENERIC;
1806 static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1808 VLC_UNUSED( i_idx );
1809 demux_sys_t *p_sys = p_demux->p_sys;
1810 text_t *txt = &p_sys->txt;
1812 char psz_end[12]= "", psz_begin[12] = "";
1816 int h1 = 0, m1 = 0, s1 = 0, f1 = 0;
1817 int h2 = 0, m2 = 0, s2 = 0, f2 = 0;
1818 const char *s = TextGetLine( txt );
1821 return VLC_EGENERIC;
1823 psz_text = malloc( strlen( s ) + 1 );
1827 /* Find the good begining. This removes extra spaces at the beginning
1829 char *psz_temp = strcasestr( s, "<time");
1830 if( psz_temp != NULL )
1832 /* Line has begin and end */
1833 if( ( sscanf( psz_temp,
1834 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\" %*[e|E]nd=\"%[^\"]%*[^>]%[^\n\r]",
1835 psz_begin, psz_end, psz_text) != 3 ) &&
1836 /* Line has begin and no end */
1838 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\"%*[^>]%[^\n\r]",
1839 psz_begin, psz_text ) != 2) )
1840 /* Line is not recognized */
1847 int64_t i_time = ParseRealTime( psz_begin, &h1, &m1, &s1, &f1 );
1850 p_subtitle->i_start = i_time;
1853 i_time = ParseRealTime( psz_end, &h2, &m2, &s2, &f2 );
1856 p_subtitle->i_stop = i_time;
1860 /* Line is not recognized */
1865 /* Get the following Lines */
1868 const char *s = TextGetLine( txt );
1871 return VLC_EGENERIC;
1873 int i_len = strlen( s );
1874 if( i_len == 0 ) break;
1876 if( strcasestr( s, "<time" ) ||
1877 strcasestr( s, "<clear/") )
1879 TextPreviousLine( txt );
1883 int i_old = strlen( psz_text );
1885 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1889 strcat( psz_text, s );
1890 strcat( psz_text, "\n" );
1893 /* Remove the starting ">" that remained after the sscanf */
1894 memmove( &psz_text[0], &psz_text[1], strlen( psz_text ) );
1896 p_subtitle->psz_text = psz_text;
1901 static int ParseDKS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1903 VLC_UNUSED( i_idx );
1905 demux_sys_t *p_sys = p_demux->p_sys;
1906 text_t *txt = &p_sys->txt;
1913 char *s = TextGetLine( txt );
1916 return VLC_EGENERIC;
1918 psz_text = malloc( strlen( s ) + 1 );
1922 if( sscanf( s, "[%d:%d:%d]%[^\r\n]",
1923 &h1, &m1, &s1, psz_text ) == 4 )
1925 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1926 (int64_t)m1 * 60*1000 +
1927 (int64_t)s1 * 1000 ) * 1000;
1929 char *s = TextGetLine( txt );
1931 return VLC_EGENERIC;
1933 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1934 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1935 (int64_t)m2 * 60*1000 +
1936 (int64_t)s2 * 1000 ) * 1000;
1942 /* replace [br] by \n */
1944 while( ( p = strstr( psz_text, "[br]" ) ) )
1947 memmove( p, &p[3], strlen(&p[3])+1 );
1950 p_subtitle->psz_text = psz_text;
1954 static int ParseSubViewer1( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1956 VLC_UNUSED( i_idx );
1958 demux_sys_t *p_sys = p_demux->p_sys;
1959 text_t *txt = &p_sys->txt;
1966 char *s = TextGetLine( txt );
1969 return VLC_EGENERIC;
1971 if( sscanf( s, "[%d:%d:%d]", &h1, &m1, &s1 ) == 3 )
1973 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1974 (int64_t)m1 * 60*1000 +
1975 (int64_t)s1 * 1000 ) * 1000;
1977 char *s = TextGetLine( txt );
1979 return VLC_EGENERIC;
1981 psz_text = strdup( s );
1985 s = TextGetLine( txt );
1987 return VLC_EGENERIC;
1989 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1990 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1991 (int64_t)m2 * 60*1000 +
1992 (int64_t)s2 * 1000 ) * 1000;
1997 p_subtitle->psz_text = psz_text;