[vlc-commits] demux: subtitle: add support for SBV (fix #15180)

Francois Cartegnie git at videolan.org
Thu Aug 6 16:38:50 CEST 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Aug  6 16:33:19 2015 +0200| [3e8235d458272059bc3bc8466767bae47ad3df7f] | committer: Francois Cartegnie

demux: subtitle: add support for SBV (fix #15180)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3e8235d458272059bc3bc8466767bae47ad3df7f
---

 NEWS                     |    1 +
 modules/demux/subtitle.c |   62 ++++++++++++++++++++++++++++++++--------------
 src/input/subtitles.c    |    2 +-
 3 files changed, 45 insertions(+), 20 deletions(-)

diff --git a/NEWS b/NEWS
index a7bf588..7428421 100644
--- a/NEWS
+++ b/NEWS
@@ -57,6 +57,7 @@ Demuxers:
  * Support Daala in Ogg
  * Important rework of the MP4 demuxer, including fragments
  * Support EIA-608 subtitles in MP4/mov
+ * Support SBV subtitles
  * Support WMV and WMAV in MP4/mov, aka Flip4Mac files
  * Support bitmap audio channel reordering in MP4/mov
  * Support AlbumArtist and DiscNumber metadata
diff --git a/modules/demux/subtitle.c b/modules/demux/subtitle.c
index c53573e..68aae24 100644
--- a/modules/demux/subtitle.c
+++ b/modules/demux/subtitle.c
@@ -63,7 +63,7 @@ static const char *const ppsz_sub_type[] =
     "auto", "microdvd", "subrip", "subviewer", "ssa1",
     "ssa2-4", "ass", "vplayer", "sami", "dvdsubtitle", "mpl2",
     "aqt", "pjs", "mpsub", "jacosub", "psb", "realtext", "dks",
-    "subviewer1","vtt"
+    "subviewer1", "vtt", "sbv"
 };
 
 vlc_module_begin ()
@@ -113,7 +113,8 @@ enum
     SUB_TYPE_DKS,
     SUB_TYPE_SUBVIEW1, /* SUBVIEWER 1 - mplayer calls it subrip09,
                          and Gnome subtitles SubViewer 1.0 */
-    SUB_TYPE_VTT
+    SUB_TYPE_VTT,
+    SUB_TYPE_SBV
 };
 
 typedef struct
@@ -185,7 +186,7 @@ static int  ParsePSB        ( demux_t *, subtitle_t *, int );
 static int  ParseRealText   ( demux_t *, subtitle_t *, int );
 static int  ParseDKS        ( demux_t *, subtitle_t *, int );
 static int  ParseSubViewer1 ( demux_t *, subtitle_t *, int );
-static int  ParseVTT        ( demux_t *, subtitle_t *, int );
+static int  ParseCommonVTTSBV( demux_t *, subtitle_t *, int );
 
 static const struct
 {
@@ -213,7 +214,8 @@ static const struct
     { "realtext",   SUB_TYPE_RT,          "RealText",    ParseRealText },
     { "dks",        SUB_TYPE_DKS,         "DKS",         ParseDKS },
     { "subviewer1", SUB_TYPE_SUBVIEW1,    "Subviewer 1", ParseSubViewer1 },
-    { "text/vtt",   SUB_TYPE_VTT,         "WebVTT",      ParseVTT },
+    { "text/vtt",   SUB_TYPE_VTT,         "WebVTT",      ParseCommonVTTSBV },
+    { "sbv",        SUB_TYPE_SBV,         "SBV",         ParseCommonVTTSBV },
     { NULL,         SUB_TYPE_UNKNOWN,     "Unknown",     NULL }
 };
 /* When adding support for more formats, be sure to add their file extension
@@ -397,6 +399,13 @@ static int Open ( vlc_object_t *p_this )
                 p_sys->i_type = SUB_TYPE_JACOSUB;
                 break;
             }
+            else if( sscanf( s, "%d:%d:%d.%d,%d:%d:%d.%d",
+                                 &i_dummy, &i_dummy, &i_dummy, &i_dummy,
+                                 &i_dummy, &i_dummy, &i_dummy, &i_dummy ) == 8 )
+            {
+                p_sys->i_type = SUB_TYPE_SBV;
+                break;
+            }
             else if( sscanf( s, "%d:%d:%d:", &i_dummy, &i_dummy, &i_dummy ) == 3 ||
                      sscanf( s, "%d:%d:%d ", &i_dummy, &i_dummy, &i_dummy ) == 3 )
             {
@@ -2162,11 +2171,11 @@ static int ParseSubViewer1( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx
 
     return VLC_SUCCESS;
 }
-/*Parsing WebVTT */
-static int  ParseVTT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
+
+/* Common code for VTT/SBV since they just differ in timestamps */
+static int ParseCommonVTTSBV( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
 {
     VLC_UNUSED( i_idx );
-
     demux_sys_t *p_sys = p_demux->p_sys;
     text_t      *txt = &p_sys->txt;
     char        *psz_text;
@@ -2180,18 +2189,33 @@ static int  ParseVTT( demux_t *p_demux, subtitle_t *p_subtitle, int i_idx )
         if( !s )
             return VLC_EGENERIC;
 
-        if( sscanf( s,"%d:%d:%d.%d --> %d:%d:%d.%d",
-                    &h1, &m1, &s1, &d1,
-                    &h2, &m2, &s2, &d2 ) == 8 ||
-            sscanf( s,"%d:%d:%d.%d --> %d:%d.%d",
-                    &h1, &m1, &s1, &d1,
-                         &m2, &s2, &d2 ) == 7 ||
-            sscanf( s,"%d:%d.%d --> %d:%d:%d.%d",
-                         &m1, &s1, &d1,
-                    &h2, &m2, &s2, &d2 ) == 7 ||
-            sscanf( s,"%d:%d.%d --> %d:%d.%d",
-                         &m1, &s1, &d1,
-                         &m2, &s2, &d2 ) == 6 )
+        bool b_matched = false;
+
+        if( p_sys->i_type == SUB_TYPE_VTT )
+        {
+            b_matched =
+            ( sscanf( s,"%d:%d:%d.%d --> %d:%d:%d.%d",
+                        &h1, &m1, &s1, &d1,
+                        &h2, &m2, &s2, &d2 ) == 8 ||
+                sscanf( s,"%d:%d:%d.%d --> %d:%d.%d",
+                        &h1, &m1, &s1, &d1,
+                             &m2, &s2, &d2 ) == 7 ||
+                sscanf( s,"%d:%d.%d --> %d:%d:%d.%d",
+                             &m1, &s1, &d1,
+                        &h2, &m2, &s2, &d2 ) == 7 ||
+                sscanf( s,"%d:%d.%d --> %d:%d.%d",
+                             &m1, &s1, &d1,
+                             &m2, &s2, &d2 ) == 6 );
+        }
+        else if( p_sys->i_type == SUB_TYPE_SBV )
+        {
+            b_matched =
+            ( sscanf( s,"%d:%d:%d.%d,%d:%d:%d.%d",
+                        &h1, &m1, &s1, &d1,
+                        &h2, &m2, &s2, &d2 ) == 8 );
+        }
+
+        if( b_matched )
         {
             p_subtitle->i_start = ( (int64_t)h1 * 3600 * 1000 +
                                     (int64_t)m1 * 60 * 1000 +
diff --git a/src/input/subtitles.c b/src/input/subtitles.c
index 35b5f4c..7c22720 100644
--- a/src/input/subtitles.c
+++ b/src/input/subtitles.c
@@ -57,7 +57,7 @@ static const char sub_exts[][6] = {
     "usf", "jss",  "cdg",
     "psb", "mpsub","mpl2",
     "pjs", "dks", "stl",
-    "vtt",""
+    "vtt", "sbv", ""
 };
 
 static void strcpy_trim( char *d, const char *s )



More information about the vlc-commits mailing list