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 *****************************************************************************/
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\", \"ssa1\", \"ssa2-4\", \"ass\", \"vplayer\" " \
61 "\"sami\", \"dvdsubtitle\", \"mpl2\", \"aqt\", \"pjs\" "\
62 "\"mpsub\" \"jacosub\" \"psb\" and \"auto\" (meaning autodetection, this " \
63 "should always work).")
64 static const char *ppsz_sub_type[] =
66 "auto", "microdvd", "subrip", "subviewer", "ssa1",
67 "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2",
68 "aqt", "pjs", "mpsub", "jacosub", "psb"
72 set_shortname( _("Subtitles"));
73 set_description( _("Text subtitles parser") );
74 set_capability( "demux", 0 );
75 set_category( CAT_INPUT );
76 set_subcategory( SUBCAT_INPUT_DEMUX );
77 add_float( "sub-fps", 0.0, NULL,
78 N_("Frames per second"),
79 SUB_FPS_LONGTEXT, true );
80 add_integer( "sub-delay", 0, NULL,
81 N_("Subtitles delay"),
82 SUB_DELAY_LONGTEXT, true );
83 add_string( "sub-type", "auto", NULL, N_("Subtitles format"),
84 SUB_TYPE_LONGTEXT, true );
85 change_string_list( ppsz_sub_type, NULL, NULL );
86 set_callbacks( Open, Close );
88 add_shortcut( "subtitle" );
91 /*****************************************************************************
93 *****************************************************************************/
96 SUB_TYPE_UNKNOWN = -1,
104 SUB_TYPE_SUBVIEWER, //SUBVIEWER 2!
105 SUB_TYPE_DVDSUBTITLE,
124 static int TextLoad( text_t *, stream_t *s );
125 static void TextUnload( text_t * );
142 int64_t i_next_demux_date;
143 int64_t i_microsecperframe;
148 subtitle_t *subtitle;
153 static int ParseMicroDvd ( demux_t *, subtitle_t *, int );
154 static int ParseSubRip ( demux_t *, subtitle_t *, int );
155 static int ParseSubViewer ( demux_t *, subtitle_t *, int );
156 static int ParseSSA ( demux_t *, subtitle_t *, int );
157 static int ParseVplayer ( demux_t *, subtitle_t *, int );
158 static int ParseSami ( demux_t *, subtitle_t *, int );
159 static int ParseDVDSubtitle( demux_t *, subtitle_t *, int );
160 static int ParseMPL2 ( demux_t *, subtitle_t *, int );
161 static int ParseAQT ( demux_t *, subtitle_t *, int );
162 static int ParsePJS ( demux_t *, subtitle_t *, int );
163 static int ParseMPSub ( demux_t *, subtitle_t *, int );
164 static int ParseJSS ( demux_t *, subtitle_t *, int );
165 static int ParsePSB ( demux_t *, subtitle_t *, int );
166 static int ParseRealText ( demux_t *, subtitle_t *, int );
167 static int ParseDKS ( demux_t *, subtitle_t *, int );
168 static int ParseSub1 ( demux_t *, subtitle_t *, int );
172 const char *psz_type_name;
174 const char *psz_name;
175 int (*pf_read)( demux_t *, subtitle_t*, int );
176 } sub_read_subtitle_function [] =
178 { "microdvd", SUB_TYPE_MICRODVD, "MicroDVD", ParseMicroDvd },
179 { "subrip", SUB_TYPE_SUBRIP, "SubRIP", ParseSubRip },
180 { "subviewer", SUB_TYPE_SUBVIEWER, "SubViewer", ParseSubViewer },
181 { "ssa1", SUB_TYPE_SSA1, "SSA-1", ParseSSA },
182 { "ssa2-4", SUB_TYPE_SSA2_4, "SSA-2/3/4", ParseSSA },
183 { "ass", SUB_TYPE_ASS, "SSA/ASS", ParseSSA },
184 { "vplayer", SUB_TYPE_VPLAYER, "VPlayer", ParseVplayer },
185 { "sami", SUB_TYPE_SAMI, "SAMI", ParseSami },
186 { "dvdsubtitle",SUB_TYPE_DVDSUBTITLE, "DVDSubtitle", ParseDVDSubtitle },
187 { "mpl2", SUB_TYPE_MPL2, "MPL2", ParseMPL2 },
188 { "aqt", SUB_TYPE_AQT, "AQTitle", ParseAQT },
189 { "pjs", SUB_TYPE_PJS, "PhoenixSub", ParsePJS },
190 { "mpsub", SUB_TYPE_MPSUB, "MPSub", ParseMPSub },
191 { "jacosub", SUB_TYPE_JACOSUB, "JacoSub", ParseJSS },
192 { "psb", SUB_TYPE_PSB, "PowerDivx", ParsePSB },
193 { "realtext", SUB_TYPE_RT, "RealText", ParseRealText },
194 { "dks", SUB_TYPE_DKS, "DKS", ParseDKS },
195 { "subviewer1", SUB_TYPE_SUBVIEW1, "Subviewer 1", ParseSub1 },
196 { NULL, SUB_TYPE_UNKNOWN, "Unknown", NULL }
199 static int Demux( demux_t * );
200 static int Control( demux_t *, int, va_list );
202 /*static void Fix( demux_t * );*/
204 /*****************************************************************************
206 *****************************************************************************/
207 static int Open ( vlc_object_t *p_this )
209 demux_t *p_demux = (demux_t*)p_this;
214 int (*pf_read)( demux_t *, subtitle_t*, int );
217 if( !p_demux->b_force )
219 msg_Dbg( p_demux, "subtitle demux discarded" );
223 p_demux->pf_demux = Demux;
224 p_demux->pf_control = Control;
225 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
229 p_sys->psz_header = NULL;
230 p_sys->i_subtitle = 0;
231 p_sys->i_subtitles = 0;
232 p_sys->subtitle = NULL;
233 p_sys->i_microsecperframe = 40000;
236 f_fps = var_CreateGetFloat( p_demux, "sub-original-fps" ); /* FIXME */
238 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
240 msg_Dbg( p_demux, "Movie fps: %f", f_fps );
242 /* Check for override of the fps */
243 f_fps = var_CreateGetFloat( p_demux, "sub-fps" );
246 p_sys->i_microsecperframe = (int64_t)( (float)1000000 / f_fps );
247 msg_Dbg( p_demux, "Override subtitle fps %f", f_fps );
250 /* Get or probe the type */
251 p_sys->i_type = SUB_TYPE_UNKNOWN;
252 psz_type = var_CreateGetString( p_demux, "sub-type" );
259 if( sub_read_subtitle_function[i].psz_type_name == NULL )
262 if( !strcmp( sub_read_subtitle_function[i].psz_type_name,
265 p_sys->i_type = sub_read_subtitle_function[i].i_type;
272 /* Probe if unknown type */
273 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
278 msg_Dbg( p_demux, "autodetecting subtitle format" );
279 for( i_try = 0; i_try < 256; i_try++ )
284 if( ( s = stream_ReadLine( p_demux->s ) ) == NULL )
287 if( strcasestr( s, "<SAMI>" ) )
289 p_sys->i_type = SUB_TYPE_SAMI;
292 else if( sscanf( s, "{%d}{%d}", &i_dummy, &i_dummy ) == 2 ||
293 sscanf( s, "{%d}{}", &i_dummy ) == 1)
295 p_sys->i_type = SUB_TYPE_MICRODVD;
299 "%d:%d:%d,%d --> %d:%d:%d,%d",
300 &i_dummy,&i_dummy,&i_dummy,&i_dummy,
301 &i_dummy,&i_dummy,&i_dummy,&i_dummy ) == 8 )
303 p_sys->i_type = SUB_TYPE_SUBRIP;
306 else if( !strncasecmp( s, "!: This is a Sub Station Alpha v1", 33 ) )
308 p_sys->i_type = SUB_TYPE_SSA1;
311 else if( !strncasecmp( s, "ScriptType: v4.00+", 18 ) )
313 p_sys->i_type = SUB_TYPE_ASS;
316 else if( !strncasecmp( s, "ScriptType: v4.00", 17 ) )
318 p_sys->i_type = SUB_TYPE_SSA2_4;
321 else if( !strncasecmp( s, "Dialogue: Marked", 16 ) )
323 p_sys->i_type = SUB_TYPE_SSA2_4;
326 else if( !strncasecmp( s, "Dialogue:", 9 ) )
328 p_sys->i_type = SUB_TYPE_ASS;
331 else if( strcasestr( s, "[INFORMATION]" ) )
333 p_sys->i_type = SUB_TYPE_SUBVIEWER; /* I hope this will work */
336 else if( sscanf( s, "%d:%d:%d.%d %d:%d:%d",
337 &i_dummy, &i_dummy, &i_dummy, &i_dummy,
338 &i_dummy, &i_dummy, &i_dummy ) == 7 ||
339 sscanf( s, "@%d @%d", &i_dummy, &i_dummy) == 2)
341 p_sys->i_type = SUB_TYPE_JACOSUB;
344 else if( sscanf( s, "%d:%d:%d:", &i_dummy, &i_dummy, &i_dummy ) == 3 ||
345 sscanf( s, "%d:%d:%d ", &i_dummy, &i_dummy, &i_dummy ) == 3 )
347 p_sys->i_type = SUB_TYPE_VPLAYER;
350 else if( sscanf( s, "{T %d:%d:%d:%d", &i_dummy, &i_dummy,
351 &i_dummy, &i_dummy ) == 4 )
353 p_sys->i_type = SUB_TYPE_DVDSUBTITLE;
356 else if( sscanf( s, "[%d:%d:%d]%c",
357 &i_dummy, &i_dummy, &i_dummy, &p_dummy ) == 4 )
359 p_sys->i_type = SUB_TYPE_DKS;
362 else if( strstr( s, "*** START SCRIPT" ) )
364 p_sys->i_type = SUB_TYPE_SUBVIEW1;
367 else if( sscanf( s, "[%d][%d]", &i_dummy, &i_dummy ) == 2 ||
368 sscanf( s, "[%d][]", &i_dummy ) == 1)
370 p_sys->i_type = SUB_TYPE_MPL2;
373 else if( sscanf (s, "FORMAT=%d", &i_dummy) == 1 ||
374 ( sscanf (s, "FORMAT=TIM%c", &p_dummy) == 1
377 p_sys->i_type = SUB_TYPE_MPSUB;
380 else if( sscanf( s, "-->> %d", &i_dummy) == 1 )
382 p_sys->i_type = SUB_TYPE_AQT;
385 else if( sscanf( s, "%d,%d,", &i_dummy, &i_dummy ) == 2 )
387 p_sys->i_type = SUB_TYPE_PJS;
390 else if( sscanf( s, "{%d:%d:%d}",
391 &i_dummy, &i_dummy, &i_dummy ) == 3 )
393 p_sys->i_type = SUB_TYPE_PSB;
396 else if( strcasestr( s, "<time" ) )
398 p_sys->i_type = SUB_TYPE_RT;
408 /* It will nearly always work even for non seekable stream thanks the
409 * caching system, and if it fails we lose just a few sub */
410 if( stream_Seek( p_demux->s, 0 ) )
412 msg_Warn( p_demux, "failed to rewind" );
416 /* Quit on unknown subtitles */
417 if( p_sys->i_type == SUB_TYPE_UNKNOWN )
419 msg_Err( p_demux, "failed to recognize subtitle type" );
426 if( sub_read_subtitle_function[i].i_type == p_sys->i_type )
428 msg_Dbg( p_demux, "detected %s format",
429 sub_read_subtitle_function[i].psz_name );
430 pf_read = sub_read_subtitle_function[i].pf_read;
435 msg_Dbg( p_demux, "loading all subtitles..." );
437 /* Load the whole file */
438 TextLoad( &p_sys->txt, p_demux->s );
443 if( p_sys->i_subtitles >= i_max )
446 if( !( p_sys->subtitle = realloc( p_sys->subtitle,
447 sizeof(subtitle_t) * i_max ) ) )
449 msg_Err( p_demux, "out of memory");
450 free( p_sys->subtitle );
451 TextUnload( &p_sys->txt );
457 if( pf_read( p_demux, &p_sys->subtitle[p_sys->i_subtitles],
458 p_sys->i_subtitles ) )
461 p_sys->i_subtitles++;
464 TextUnload( &p_sys->txt );
466 msg_Dbg(p_demux, "loaded %d subtitles", p_sys->i_subtitles );
468 /* Fix subtitle (order and time) *** */
469 p_sys->i_subtitle = 0;
471 if( p_sys->i_subtitles > 0 )
473 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_stop;
475 if( p_sys->i_length <= 0 )
476 p_sys->i_length = p_sys->subtitle[p_sys->i_subtitles-1].i_start+1;
479 /* *** add subtitle ES *** */
480 if( p_sys->i_type == SUB_TYPE_SSA1 ||
481 p_sys->i_type == SUB_TYPE_SSA2_4 ||
482 p_sys->i_type == SUB_TYPE_ASS )
484 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','s','a',' ' ) );
488 es_format_Init( &fmt, SPU_ES, VLC_FOURCC( 's','u','b','t' ) );
490 if( p_sys->psz_header != NULL )
492 fmt.i_extra = strlen( p_sys->psz_header ) + 1;
493 fmt.p_extra = strdup( p_sys->psz_header );
495 p_sys->es = es_out_Add( p_demux->out, &fmt );
500 /*****************************************************************************
501 * Close: Close subtitle demux
502 *****************************************************************************/
503 static void Close( vlc_object_t *p_this )
505 demux_t *p_demux = (demux_t*)p_this;
506 demux_sys_t *p_sys = p_demux->p_sys;
509 for( i = 0; i < p_sys->i_subtitles; i++ )
510 free( p_sys->subtitle[i].psz_text );
511 free( p_sys->subtitle );
516 /*****************************************************************************
518 *****************************************************************************/
519 static int Control( demux_t *p_demux, int i_query, va_list args )
521 demux_sys_t *p_sys = p_demux->p_sys;
527 case DEMUX_GET_LENGTH:
528 pi64 = (int64_t*)va_arg( args, int64_t * );
529 *pi64 = p_sys->i_length;
533 pi64 = (int64_t*)va_arg( args, int64_t * );
534 if( p_sys->i_subtitle < p_sys->i_subtitles )
536 *pi64 = p_sys->subtitle[p_sys->i_subtitle].i_start;
542 i64 = (int64_t)va_arg( args, int64_t );
543 p_sys->i_subtitle = 0;
544 while( p_sys->i_subtitle < p_sys->i_subtitles &&
545 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
550 if( p_sys->i_subtitle >= p_sys->i_subtitles )
554 case DEMUX_GET_POSITION:
555 pf = (double*)va_arg( args, double * );
556 if( p_sys->i_subtitle >= p_sys->i_subtitles )
560 else if( p_sys->i_subtitles > 0 )
562 *pf = (double)p_sys->subtitle[p_sys->i_subtitle].i_start /
563 (double)p_sys->i_length;
571 case DEMUX_SET_POSITION:
572 f = (double)va_arg( args, double );
573 i64 = f * p_sys->i_length;
575 p_sys->i_subtitle = 0;
576 while( p_sys->i_subtitle < p_sys->i_subtitles &&
577 p_sys->subtitle[p_sys->i_subtitle].i_start < i64 )
581 if( p_sys->i_subtitle >= p_sys->i_subtitles )
585 case DEMUX_SET_NEXT_DEMUX_TIME:
586 p_sys->i_next_demux_date = (int64_t)va_arg( args, int64_t );
591 case DEMUX_GET_ATTACHMENTS:
592 case DEMUX_GET_TITLE_INFO:
593 case DEMUX_HAS_UNSUPPORTED_META:
597 msg_Err( p_demux, "unknown query %d in subtitle control", i_query );
602 /*****************************************************************************
603 * Demux: Send subtitle to decoder
604 *****************************************************************************/
605 static int Demux( demux_t *p_demux )
607 demux_sys_t *p_sys = p_demux->p_sys;
610 if( p_sys->i_subtitle >= p_sys->i_subtitles )
613 i_maxdate = p_sys->i_next_demux_date - var_GetTime( p_demux->p_parent, "spu-delay" );;
614 if( i_maxdate <= 0 && p_sys->i_subtitle < p_sys->i_subtitles )
616 /* Should not happen */
617 i_maxdate = p_sys->subtitle[p_sys->i_subtitle].i_start + 1;
620 while( p_sys->i_subtitle < p_sys->i_subtitles &&
621 p_sys->subtitle[p_sys->i_subtitle].i_start < i_maxdate )
624 int i_len = strlen( p_sys->subtitle[p_sys->i_subtitle].psz_text ) + 1;
633 if( ( p_block = block_New( p_demux, i_len ) ) == NULL )
639 if( p_sys->subtitle[p_sys->i_subtitle].i_start < 0 )
645 p_block->i_pts = p_sys->subtitle[p_sys->i_subtitle].i_start;
646 p_block->i_dts = p_block->i_pts;
647 if( p_sys->subtitle[p_sys->i_subtitle].i_stop > 0 )
650 p_sys->subtitle[p_sys->i_subtitle].i_stop - p_block->i_pts;
653 memcpy( p_block->p_buffer,
654 p_sys->subtitle[p_sys->i_subtitle].psz_text, i_len );
655 if( p_block->i_pts > 0 )
657 es_out_Send( p_demux->out, p_sys->es, p_block );
661 block_Release( p_block );
667 p_sys->i_next_demux_date = 0;
672 /*****************************************************************************
673 * Fix: fix time stamp and order of subtitle
674 *****************************************************************************/
675 #ifdef USE_THIS_UNUSED_PIECE_OF_CODE
676 static void Fix( demux_t *p_demux )
678 demux_sys_t *p_sys = p_demux->p_sys;
682 /* *** fix order (to be sure...) *** */
683 /* We suppose that there are near in order and this durty bubble sort
684 * wont take too much time
689 for( i_index = 1; i_index < p_sys->i_subtitles; i_index++ )
691 if( p_sys->subtitle[i_index].i_start <
692 p_sys->subtitle[i_index - 1].i_start )
696 p_sys->subtitle + i_index - 1,
697 sizeof( subtitle_t ) );
698 memcpy( p_sys->subtitle + i_index - 1,
699 p_sys->subtitle + i_index,
700 sizeof( subtitle_t ) );
701 memcpy( p_sys->subtitle + i_index,
703 sizeof( subtitle_t ) );
711 static int TextLoad( text_t *txt, stream_t *s )
717 txt->i_line_count = 0;
719 txt->line = calloc( i_line_max, sizeof( char * ) );
721 /* load the complete file */
724 char *psz = stream_ReadLine( s );
729 txt->line[txt->i_line_count++] = psz;
730 if( txt->i_line_count >= i_line_max )
733 txt->line = realloc( txt->line, i_line_max * sizeof( char * ) );
737 if( txt->i_line_count <= 0 )
745 static void TextUnload( text_t *txt )
749 for( i = 0; i < txt->i_line_count; i++ )
751 free( txt->line[i] );
755 txt->i_line_count = 0;
758 static char *TextGetLine( text_t *txt )
760 if( txt->i_line >= txt->i_line_count )
763 return txt->line[txt->i_line++];
765 static void TextPreviousLine( text_t *txt )
767 if( txt->i_line > 0 )
771 /*****************************************************************************
772 * Specific Subtitle function
773 *****************************************************************************/
776 * {n1}{n2}Line1|Line2|Line3....
777 * where n1 and n2 are the video frame number (n2 can be empty)
779 static int ParseMicroDvd( demux_t *p_demux, subtitle_t *p_subtitle,
783 demux_sys_t *p_sys = p_demux->p_sys;
784 text_t *txt = &p_sys->txt;
792 const char *s = TextGetLine( txt );
796 psz_text = malloc( strlen(s) + 1 );
802 if( sscanf( s, "{%d}{}%[^\r\n]", &i_start, psz_text ) == 2 ||
803 sscanf( s, "{%d}{%d}%[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
806 if( i_start != 1 || i_stop != 1 )
809 /* We found a possible setting of the framerate "{1}{1}23.976" */
810 /* Check if it's usable, and if the sub-fps is not set */
811 f_fps = us_strtod( psz_text, NULL );
812 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
813 p_sys->i_microsecperframe = (int64_t)((float)1000000 / f_fps);
818 /* replace | by \n */
819 for( i = 0; psz_text[i] != '\0'; i++ )
821 if( psz_text[i] == '|' )
826 p_subtitle->i_start = i_start * p_sys->i_microsecperframe;
827 p_subtitle->i_stop = i_stop * p_sys->i_microsecperframe;
828 p_subtitle->psz_text = psz_text;
832 /* ParseSubRipSubViewer
835 * h1:m1:s1,d1 --> h2:m2:s2,d2
840 * Format SubViewer v1/v2
841 * h1:m1:s1.d1,h2:m2:s2.d2
846 * We ignore line number for SubRip
848 static int ParseSubRipSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
852 demux_sys_t *p_sys = p_demux->p_sys;
853 text_t *txt = &p_sys->txt;
858 const char *s = TextGetLine( txt );
859 int h1, m1, s1, d1, h2, m2, s2, d2;
864 if( sscanf( s, psz_fmt,
866 &h2, &m2, &s2, &d2 ) == 8 )
868 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
869 (int64_t)m1 * 60*1000 +
871 (int64_t)d1 ) * 1000;
873 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
874 (int64_t)m2 * 60*1000 +
876 (int64_t)d2 ) * 1000;
881 /* Now read text until an empty line */
882 psz_text = strdup("");
887 const char *s = TextGetLine( txt );
900 p_subtitle->psz_text = psz_text;
904 i_old = strlen( psz_text );
905 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
908 strcat( psz_text, s );
909 strcat( psz_text, "\n" );
911 /* replace [br] by \n */
916 while( ( p = strstr( psz_text, "[br]" ) ) )
919 memmove( p, &p[3], strlen(&p[3])+1 );
926 static int ParseSubRip( demux_t *p_demux, subtitle_t *p_subtitle,
930 return ParseSubRipSubViewer( p_demux, p_subtitle,
931 "%d:%d:%d,%d --> %d:%d:%d,%d",
936 static int ParseSubViewer( demux_t *p_demux, subtitle_t *p_subtitle,
941 return ParseSubRipSubViewer( p_demux, p_subtitle,
942 "%d:%d:%d.%d,%d:%d:%d.%d",
948 static int ParseSSA( demux_t *p_demux, subtitle_t *p_subtitle,
951 demux_sys_t *p_sys = p_demux->p_sys;
952 text_t *txt = &p_sys->txt;
956 const char *s = TextGetLine( txt );
957 int h1, m1, s1, c1, h2, m2, s2, c2;
964 /* We expect (SSA2-4):
965 * Format: Marked, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
966 * Dialogue: Marked=0,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
968 * 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.
972 * Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
973 * Dialogue: Layer#,0:02:40.65,0:02:41.79,Wolf main,Cher,0000,0000,0000,,Et les enregistrements de ses ondes delta ?
976 /* The output text is - at least, not removing numbers - 18 chars shorter than the input text. */
977 psz_text = malloc( strlen(s) );
982 "Dialogue: %15[^,],%d:%d:%d.%d,%d:%d:%d.%d,%[^\r\n]",
988 /* The dec expects: ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text */
989 /* (Layer comes from ASS specs ... it's empty for SSA.) */
990 if( p_sys->i_type == SUB_TYPE_SSA1 )
992 /* SSA1 has only 8 commas before the text starts, not 9 */
993 memmove( &psz_text[1], psz_text, strlen(psz_text)+1 );
998 int i_layer = ( p_sys->i_type == SUB_TYPE_ASS ) ? atoi( temp ) : 0;
1000 /* ReadOrder, Layer, %s(rest of fields) */
1001 snprintf( temp, sizeof(temp), "%d,%d,", i_idx, i_layer );
1002 memmove( psz_text + strlen(temp), psz_text, strlen(psz_text)+1 );
1003 memcpy( psz_text, temp, strlen(temp) );
1006 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1007 (int64_t)m1 * 60*1000 +
1008 (int64_t)s1 * 1000 +
1009 (int64_t)c1 * 10 ) * 1000;
1010 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1011 (int64_t)m2 * 60*1000 +
1012 (int64_t)s2 * 1000 +
1013 (int64_t)c2 * 10 ) * 1000;
1014 p_subtitle->psz_text = psz_text;
1019 /* All the other stuff we add to the header field */
1020 if( !p_sys->psz_header )
1021 p_sys->psz_header = strdup( "" );
1022 if( !p_sys->psz_header )
1026 realloc( p_sys->psz_header,
1027 strlen( p_sys->psz_header ) + strlen( s ) + 2 );
1028 strcat( p_sys->psz_header, s );
1029 strcat( p_sys->psz_header, "\n" );
1035 * h:m:s:Line1|Line2|Line3....
1037 * h:m:s Line1|Line2|Line3....
1039 static int ParseVplayer( demux_t *p_demux, subtitle_t *p_subtitle,
1042 VLC_UNUSED( i_idx );
1044 demux_sys_t *p_sys = p_demux->p_sys;
1045 text_t *txt = &p_sys->txt;
1051 const char *s = TextGetLine( txt );
1055 return VLC_EGENERIC;
1057 psz_text = malloc( strlen( s ) + 1 );
1061 if( sscanf( s, "%d:%d:%d%*c%[^\r\n]",
1062 &h1, &m1, &s1, psz_text ) == 4 )
1064 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1065 (int64_t)m1 * 60*1000 +
1066 (int64_t)s1 * 1000 ) * 1000;
1067 p_subtitle->i_stop = 0;
1073 /* replace | by \n */
1074 for( i = 0; psz_text[i] != '\0'; i++ )
1076 if( psz_text[i] == '|' )
1079 p_subtitle->psz_text = psz_text;
1085 static char *ParseSamiSearch( text_t *txt,
1086 char *psz_start, const char *psz_str )
1088 if( psz_start && strcasestr( psz_start, psz_str ) )
1090 char *s = strcasestr( psz_start, psz_str );
1091 return &s[strlen( psz_str )];
1096 char *p = TextGetLine( txt );
1100 if( strcasestr( p, psz_str ) )
1102 char *s = strcasestr( p, psz_str );
1103 return &s[strlen( psz_str )];
1107 static int ParseSami( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1109 VLC_UNUSED( i_idx );
1110 demux_sys_t *p_sys = p_demux->p_sys;
1111 text_t *txt = &p_sys->txt;
1116 unsigned int i_text;
1117 char text[8192]; /* Arbitrary but should be long enough */
1119 /* search "Start=" */
1120 if( !( s = ParseSamiSearch( txt, NULL, "Start=" ) ) )
1121 return VLC_EGENERIC;
1123 /* get start value */
1124 i_start = strtol( s, &s, 0 );
1127 if( !( s = ParseSamiSearch( txt, s, "<P" ) ) )
1128 return VLC_EGENERIC;
1131 if( !( s = ParseSamiSearch( txt, s, ">" ) ) )
1132 return VLC_EGENERIC;
1136 /* now get all txt until a "Start=" line */
1140 /* Search non empty line */
1141 while( s && *s == '\0' )
1142 s = TextGetLine( txt );
1148 if( !strncasecmp( s, "<br", 3 ) )
1152 else if( strcasestr( s, "Start=" ) )
1154 TextPreviousLine( txt );
1157 s = ParseSamiSearch( txt, s, ">" );
1159 else if( !strncmp( s, " ", 6 ) )
1164 else if( *s == '\t' )
1174 if( c != '\0' && i_text+1 < sizeof(text) )
1177 text[i_text] = '\0';
1181 p_subtitle->i_start = i_start * 1000;
1182 p_subtitle->i_stop = 0;
1183 p_subtitle->psz_text = strdup( text );
1195 * TODO it can have a header
1202 * LANG support would be cool
1203 * CODEPAGE is probably mandatory FIXME
1205 static int ParseDVDSubtitle( demux_t *p_demux, subtitle_t *p_subtitle,
1208 VLC_UNUSED( i_idx );
1210 demux_sys_t *p_sys = p_demux->p_sys;
1211 text_t *txt = &p_sys->txt;
1216 const char *s = TextGetLine( txt );
1220 return VLC_EGENERIC;
1224 &h1, &m1, &s1, &c1 ) == 4 )
1226 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1227 (int64_t)m1 * 60*1000 +
1228 (int64_t)s1 * 1000 +
1229 (int64_t)c1 * 10) * 1000;
1230 p_subtitle->i_stop = 0;
1235 /* Now read text until a line containing "}" */
1236 psz_text = strdup("");
1241 const char *s = TextGetLine( txt );
1248 return VLC_EGENERIC;
1251 i_len = strlen( s );
1252 if( i_len == 1 && s[0] == '}')
1254 p_subtitle->psz_text = psz_text;
1258 i_old = strlen( psz_text );
1259 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1262 strcat( psz_text, s );
1263 strcat( psz_text, "\n" );
1269 * [n1][n2]Line1|Line2|Line3...
1270 * where n1 and n2 are the video frame number (n2 can be empty)
1272 static int ParseMPL2( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1274 VLC_UNUSED( i_idx );
1276 demux_sys_t *p_sys = p_demux->p_sys;
1277 text_t *txt = &p_sys->txt;
1283 const char *s = TextGetLine( txt );
1288 return VLC_EGENERIC;
1290 psz_text = malloc( strlen(s) + 1 );
1296 if( sscanf( s, "[%d][] %[^\r\n]", &i_start, psz_text ) == 2 ||
1297 sscanf( s, "[%d][%d] %[^\r\n]", &i_start, &i_stop, psz_text ) == 3)
1299 p_subtitle->i_start = (int64_t)i_start * 100000;
1300 p_subtitle->i_stop = (int64_t)i_stop * 100000;
1306 for( i = 0; psz_text[i] != '\0'; )
1308 /* replace | by \n */
1309 if( psz_text[i] == '|' )
1313 if( psz_text[i] == '/' && ( i == 0 || psz_text[i-1] == '\n' ) )
1314 memmove( &psz_text[i], &psz_text[i+1], strlen(&psz_text[i+1])+1 );
1318 p_subtitle->psz_text = psz_text;
1322 static int ParseAQT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1324 VLC_UNUSED( i_idx );
1326 demux_sys_t *p_sys = p_demux->p_sys;
1327 text_t *txt = &p_sys->txt;
1328 char *psz_text = strdup( "" );
1330 int i_firstline = 1;
1336 const char *s = TextGetLine( txt );
1339 return VLC_EGENERIC;
1342 if( sscanf (s, "-->> %d", &t) == 1)
1344 p_subtitle->i_start = (int64_t)t; /* * FPS*/
1345 p_subtitle->i_stop = 0;
1347 /* Starting of a subtitle */
1352 /* We have been too far: end of the subtitle, begin of next */
1355 TextPreviousLine( txt );
1362 i_old = strlen( psz_text ) + 1;
1363 psz_text = realloc( psz_text, i_old + strlen( s ) + 1 );
1366 strcat( psz_text, s );
1367 strcat( psz_text, "\n" );
1368 if( txt->i_line == txt->i_line_count )
1372 p_subtitle->psz_text = psz_text;
1376 static int ParsePJS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1378 VLC_UNUSED( i_idx );
1380 demux_sys_t *p_sys = p_demux->p_sys;
1381 text_t *txt = &p_sys->txt;
1387 const char *s = TextGetLine( txt );
1391 return VLC_EGENERIC;
1393 psz_text = malloc( strlen(s) + 1 );
1398 if( sscanf (s, "%d,%d,\"%[^\n\r]", &t1, &t2, psz_text ) == 3 )
1400 /* 1/10th of second ? Frame based ? FIXME */
1401 p_subtitle->i_start = 10 * t1;
1402 p_subtitle->i_stop = 10 * t2;
1403 /* Remove latest " */
1404 psz_text[ strlen(psz_text) - 1 ] = '\0';
1411 /* replace | by \n */
1412 for( i = 0; psz_text[i] != '\0'; i++ )
1414 if( psz_text[i] == '|' )
1418 p_subtitle->psz_text = psz_text;
1419 msg_Dbg( p_demux, "%s", psz_text );
1423 static float mpsub_total = 0.0;
1424 static float mpsub_factor = 0.0;
1426 static int ParseMPSub( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1428 VLC_UNUSED( i_idx );
1430 demux_sys_t *p_sys = p_demux->p_sys;
1431 text_t *txt = &p_sys->txt;
1432 char *psz_text = strdup( "" );
1440 const char *s = TextGetLine( txt );
1442 return VLC_EGENERIC;
1444 if( strstr( s, "FORMAT" ) )
1446 if( sscanf (s, "FORMAT=TIM%c", &p_dummy ) == 1 && p_dummy == 'E')
1448 mpsub_factor = 100.0;
1452 psz_temp = malloc( strlen(s) );
1456 if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
1459 f_fps = us_strtod( psz_temp, NULL );
1460 if( f_fps > 0.0 && var_GetFloat( p_demux, "sub-fps" ) <= 0.0 )
1461 var_SetFloat( p_demux, "sub-fps", f_fps );
1470 if( sscanf (s, "%f %f", &f1, &f2 ) == 2 )
1472 mpsub_total += f1 * mpsub_factor;
1473 p_subtitle->i_start = (int64_t)(10000.0 * mpsub_total);
1474 mpsub_total += f2 * mpsub_factor;
1475 p_subtitle->i_stop = (int64_t)(10000.0 * mpsub_total);
1482 const char *s = TextGetLine( txt );
1485 return VLC_EGENERIC;
1487 int i_len = strlen( s );
1491 int i_old = strlen( psz_text );
1493 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1497 strcat( psz_text, s );
1498 strcat( psz_text, "\n" );
1501 p_subtitle->psz_text = psz_text;
1505 static int ParseJSS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1507 VLC_UNUSED( i_idx );
1509 demux_sys_t *p_sys = p_demux->p_sys;
1510 text_t *txt = &p_sys->txt;
1511 char *psz_text, *psz_orig;
1512 char *psz_text2, *psz_orig2;
1513 int h1, h2, m1, m2, s1, s2, f1, f2;
1515 static int i_comment = 0;
1517 static int jss_time_resolution = 30;
1518 static int jss_time_shift = 0;
1520 /* Parse the main lines */
1523 const char *s = TextGetLine( txt );
1525 return VLC_EGENERIC;
1527 psz_orig = malloc( strlen( s ) + 1 );
1530 psz_text = psz_orig;
1532 /* Complete time lines */
1533 if( sscanf( s, "%d:%d:%d.%d %d:%d:%d.%d %[^\n\r]",
1534 &h1, &m1, &s1, &f1, &h2, &m2, &s2, &f2, psz_text ) == 9 )
1536 p_subtitle->i_start = ( (int64_t)( h1 *3600 + m1 * 60 + s1 ) +
1537 (int64_t)( ( f1 + jss_time_shift ) / jss_time_resolution ) )
1539 p_subtitle->i_stop = ( (int64_t)( h2 *3600 + m2 * 60 + s2 ) +
1540 (int64_t)( ( f2 + jss_time_shift ) / jss_time_resolution ) )
1544 /* Short time lines */
1545 else if( sscanf( s, "@%d @%d %[^\n\r]", &f1, &f2, psz_text ) == 3 )
1547 p_subtitle->i_start = (int64_t)(
1548 ( f1 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
1549 p_subtitle->i_stop = (int64_t)(
1550 ( f2 + jss_time_shift ) / jss_time_resolution * 1000000.0 );
1553 /* General Directive lines */
1554 /* Only TIME and SHIFT are supported so far */
1555 else if( s[0] == '#' )
1557 int h = 0, m =0, sec = 1, f = 1;
1561 strcpy( psz_text, s );
1563 switch( toupper( psz_text[1] ) )
1566 shift = isalpha( psz_text[2] ) ? 6 : 2 ;
1568 if( sscanf( &psz_text[shift], "%d", &h ) )
1570 /* Negative shifting */
1577 if( sscanf( &psz_text[shift], "%*d:%d", &m ) )
1579 if( sscanf( &psz_text[shift], "%*d:%*d:%d", &sec ) )
1581 sscanf( &psz_text[shift], "%*d:%*d:%*d.%d", &f );
1586 sscanf( &psz_text[shift], "%d:%d.%d",
1594 sscanf( &psz_text[shift], "%d.%d", &sec, &f);
1597 jss_time_shift = ( ( h * 3600 + m * 60 + sec )
1598 * jss_time_resolution + f ) * inv;
1603 shift = isalpha( psz_text[2] ) ? 8 : 2 ;
1605 sscanf( &psz_text[shift], "%d", &jss_time_resolution );
1612 /* Unkown type line, probably a comment */
1619 while( psz_text[ strlen( psz_text ) - 1 ] == '\\' )
1621 const char *s2 = TextGetLine( txt );
1624 return VLC_EGENERIC;
1626 int i_len = strlen( s2 );
1630 int i_old = strlen( psz_text );
1632 psz_text = realloc( psz_text, i_old + i_len + 1 );
1636 psz_orig = psz_text;
1637 strcat( psz_text, s2 );
1640 /* Skip the blanks */
1641 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1643 /* Parse the directives */
1644 if( isalpha( *psz_text ) || *psz_text == '[' )
1646 while( *psz_text != ' ' )
1649 /* Directives are NOT parsed yet */
1650 /* This has probably a better place in a decoder ? */
1651 /* directive = malloc( strlen( psz_text ) + 1 );
1652 if( sscanf( psz_text, "%s %[^\n\r]", directive, psz_text2 ) == 2 )*/
1655 /* Skip the blanks after directives */
1656 while( *psz_text == ' ' || *psz_text == '\t' ) psz_text++;
1658 /* Clean all the lines from inline comments and other stuffs */
1659 psz_orig2 = calloc( strlen( psz_text) + 1, 1 );
1660 psz_text2 = psz_orig2;
1662 for( ; *psz_text != '\0' && *psz_text != '\n' && *psz_text != '\r'; )
1673 if( (*(psz_text + 1 ) ) == ' ' ) psz_text++;
1685 if( (*(psz_text + 1 ) ) == ' ' || (*(psz_text + 1 ) ) == '\t' )
1694 if( (*(psz_text + 1 ) ) == 'n' )
1701 if( ( toupper(*(psz_text + 1 ) ) == 'C' ) ||
1702 ( toupper(*(psz_text + 1 ) ) == 'F' ) )
1704 psz_text++; psz_text++;
1707 if( (*(psz_text + 1 ) ) == 'B' || (*(psz_text + 1 ) ) == 'b' ||
1708 (*(psz_text + 1 ) ) == 'I' || (*(psz_text + 1 ) ) == 'i' ||
1709 (*(psz_text + 1 ) ) == 'U' || (*(psz_text + 1 ) ) == 'u' ||
1710 (*(psz_text + 1 ) ) == 'D' || (*(psz_text + 1 ) ) == 'N' )
1715 if( (*(psz_text + 1 ) ) == '~' || (*(psz_text + 1 ) ) == '{' ||
1716 (*(psz_text + 1 ) ) == '\\' )
1718 else if( *(psz_text + 1 ) == '\r' || *(psz_text + 1 ) == '\n' ||
1719 *(psz_text + 1 ) == '\0' )
1727 *psz_text2 = *psz_text;
1734 p_subtitle->psz_text = psz_orig2;
1735 msg_Dbg( p_demux, "%s", p_subtitle->psz_text );
1740 static int ParsePSB( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1742 VLC_UNUSED( i_idx );
1744 demux_sys_t *p_sys = p_demux->p_sys;
1745 text_t *txt = &p_sys->txt;
1753 const char *s = TextGetLine( txt );
1756 return VLC_EGENERIC;
1758 psz_text = malloc( strlen( s ) + 1 );
1762 if( sscanf( s, "{%d:%d:%d}{%d:%d:%d}%[^\r\n]",
1763 &h1, &m1, &s1, &h2, &m2, &s2, psz_text ) == 7 )
1765 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1766 (int64_t)m1 * 60*1000 +
1767 (int64_t)s1 * 1000 ) * 1000;
1768 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1769 (int64_t)m2 * 60*1000 +
1770 (int64_t)s2 * 1000 ) * 1000;
1776 /* replace | by \n */
1777 for( i = 0; psz_text[i] != '\0'; i++ )
1779 if( psz_text[i] == '|' )
1782 p_subtitle->psz_text = psz_text;
1786 static int64_t ParseRealTime( char *psz, int *h, int *m, int *s, int *f )
1788 if( strlen( psz ) == 0 ) return 0;
1789 if( sscanf( psz, "%d:%d:%d.%d", h, m, s, f ) == 4 ||
1790 sscanf( psz, "%d:%d.%d", m, s, f ) == 3 ||
1791 sscanf( psz, "%d.%d", s, f ) == 2 ||
1792 sscanf( psz, "%d:%d", m, s ) == 2 ||
1793 sscanf( psz, "%d", s ) == 1 )
1795 return (int64_t)((( *h * 60 + *m ) * 60 ) + *s ) * 1000 * 1000
1796 + (int64_t)*f * 10 * 1000;
1798 else return VLC_EGENERIC;
1801 static int ParseRealText( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1803 VLC_UNUSED( i_idx );
1804 demux_sys_t *p_sys = p_demux->p_sys;
1805 text_t *txt = &p_sys->txt;
1807 char psz_end[12]= "", psz_begin[12] = "";
1811 int h1 = 0, m1 = 0, s1 = 0, f1 = 0;
1812 int h2 = 0, m2 = 0, s2 = 0, f2 = 0;
1813 const char *s = TextGetLine( txt );
1816 return VLC_EGENERIC;
1818 psz_text = malloc( strlen( s ) + 1 );
1822 /* Find the good begining. This removes extra spaces at the beginning
1824 char *psz_temp = strcasestr( s, "<time");
1825 if( psz_temp != NULL )
1827 /* Line has begin and end */
1828 if( ( sscanf( psz_temp,
1829 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\" %*[e|E]nd=\"%[^\"]%*[^>]%[^\n\r]",
1830 psz_begin, psz_end, psz_text) != 3 ) &&
1831 /* Line has begin and no end */
1833 "<%*[t|T]ime %*[b|B]egin=\"%[^\"]\"%*[^>]%[^\n\r]",
1834 psz_begin, psz_text ) != 2) )
1835 /* Line is not recognized */
1842 int64_t i_time = ParseRealTime( psz_begin, &h1, &m1, &s1, &f1 );
1845 p_subtitle->i_start = i_time;
1848 i_time = ParseRealTime( psz_end, &h2, &m2, &s2, &f2 );
1851 p_subtitle->i_stop = i_time;
1855 /* Line is not recognized */
1860 /* Get the following Lines */
1863 const char *s = TextGetLine( txt );
1866 return VLC_EGENERIC;
1868 int i_len = strlen( s );
1869 if( i_len == 0 ) break;
1871 if( strcasestr( s, "<time" ) ||
1872 strcasestr( s, "<clear/") )
1874 TextPreviousLine( txt );
1878 int i_old = strlen( psz_text );
1880 psz_text = realloc( psz_text, i_old + i_len + 1 + 1 );
1884 strcat( psz_text, s );
1885 strcat( psz_text, "\n" );
1888 /* Remove the starting ">" that remained after the sscanf */
1889 memmove( &psz_text[0], &psz_text[1], strlen( psz_text ) );
1891 p_subtitle->psz_text = psz_text;
1896 static int ParseDKS( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1898 VLC_UNUSED( i_idx );
1900 demux_sys_t *p_sys = p_demux->p_sys;
1901 text_t *txt = &p_sys->txt;
1908 char *s = TextGetLine( txt );
1911 return VLC_EGENERIC;
1913 psz_text = malloc( strlen( s ) + 1 );
1917 if( sscanf( s, "[%d:%d:%d]%[^\r\n]",
1918 &h1, &m1, &s1, psz_text ) == 4 )
1920 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1921 (int64_t)m1 * 60*1000 +
1922 (int64_t)s1 * 1000 ) * 1000;
1924 char *s = TextGetLine( txt );
1926 return VLC_EGENERIC;
1928 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1929 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1930 (int64_t)m2 * 60*1000 +
1931 (int64_t)s2 * 1000 ) * 1000;
1937 /* replace [br] by \n */
1939 while( ( p = strstr( psz_text, "[br]" ) ) )
1942 memmove( p, &p[3], strlen(&p[3])+1 );
1945 p_subtitle->psz_text = psz_text;
1949 static int ParseSub1( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
1951 VLC_UNUSED( i_idx );
1953 demux_sys_t *p_sys = p_demux->p_sys;
1954 text_t *txt = &p_sys->txt;
1961 char *s = TextGetLine( txt );
1964 return VLC_EGENERIC;
1966 if( sscanf( s, "[%d:%d:%d]", &h1, &m1, &s1 ) == 3 )
1968 p_subtitle->i_start = ( (int64_t)h1 * 3600*1000 +
1969 (int64_t)m1 * 60*1000 +
1970 (int64_t)s1 * 1000 ) * 1000;
1972 char *s = TextGetLine( txt );
1974 return VLC_EGENERIC;
1976 psz_text = strdup( s );
1980 s = TextGetLine( txt );
1982 return VLC_EGENERIC;
1984 if( sscanf( s, "[%d:%d:%d]", &h2, &m2, &s2 ) == 3 )
1985 p_subtitle->i_stop = ( (int64_t)h2 * 3600*1000 +
1986 (int64_t)m2 * 60*1000 +
1987 (int64_t)s2 * 1000 ) * 1000;
1992 p_subtitle->psz_text = psz_text;