[vlc-commits] [Git][videolan/vlc][master] 6 commits: demux: subtitle: check mpsub timing line early

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Mar 7 13:07:18 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
dcb0dfcc by Steve Lhomme at 2025-03-07T12:45:54+00:00
demux: subtitle: check mpsub timing line early

Most of the time that's the first line we will get.
If not the line can contain different things other than a FORMAT setting.

And calling vlc_strtof_c without checking the lines contains 2 values
was bound to use 0 if the line did not actually contain numbers.

- - - - -
8e78d792 by Steve Lhomme at 2025-03-07T12:45:54+00:00
demux: subtitle: skip mpsub comment and empty lines early

- - - - -
5fa5916a by Steve Lhomme at 2025-03-07T12:45:54+00:00
demux: subtitle: check for the "FORMAT=" string once

- - - - -
3c4cff54 by Steve Lhomme at 2025-03-07T12:45:54+00:00
demux: subtitle: simplify "FORMAT=TIME*" check

- - - - -
107de58d by Steve Lhomme at 2025-03-07T12:45:54+00:00
demux: subtitle: don't break when using FPS in mpsub

We still need to look for the wait & duration values after that.

- - - - -
a2c27695 by Steve Lhomme at 2025-03-07T12:45:54+00:00
demux: subtitle: check the FORMAT= value is a number in mpsub

We don't need vlc_strtof_c() since we already have the float value.
We also don't need to check what is after the number (a comment for example).
As long as it's a number it should be FPS. Anything else other than
"FORMAT=TIME" is bogus. So we don't need to get the remaining part of the string.

- - - - -


1 changed file:

- modules/demux/subtitle.c


Changes:

=====================================
modules/demux/subtitle.c
=====================================
@@ -1729,54 +1729,48 @@ static int ParseMPSub( vlc_object_t *p_obj, subs_properties_t *p_props,
 
     for( ;; )
     {
-        char p_dummy;
-        char *psz_temp;
-
         const char *s = TextGetLine( txt );
         if( !s )
         {
             return VLC_EGENERIC;
         }
 
-        if( strstr( s, "FORMAT" ) )
-        {
-            if( sscanf (s, "FORMAT=TIM%c", &p_dummy ) == 1 && p_dummy == 'E')
-            {
-                p_props->mpsub.i_factor = 100;
-                break;
-            }
-
-            psz_temp = malloc( strlen(s) );
-            if( !psz_temp )
-            {
-                return VLC_ENOMEM;
-            }
-
-            if( sscanf( s, "FORMAT=%[^\r\n]", psz_temp ) )
-            {
-                float f_fps = vlc_strtof_c( psz_temp, NULL );
-
-                if( f_fps > 0.f && var_GetFloat( p_obj, "sub-original-fps" ) <= 0.f )
-                    var_SetFloat( p_obj, "sub-original-fps", f_fps );
-
-                p_props->mpsub.i_factor = 1;
-                free( psz_temp );
-                break;
-            }
-            free( psz_temp );
-        }
+        if ( *s =='#' || *s == '\0' )
+            continue;
 
         /* Data Lines */
-        float f1 = vlc_strtof_c( s, &psz_temp );
-        if( *psz_temp )
+        float wait, duration;
+        if( sscanf( s, "%f %f", &wait, &duration ) == 2 )
         {
-            float f2 = vlc_strtof_c( psz_temp, NULL );
+            float f1 = wait;
+            float f2 = duration;
             p_props->mpsub.f_total += f1 * p_props->mpsub.i_factor;
             p_subtitle->i_start = VLC_TICK_0 + llroundf(10000.f * p_props->mpsub.f_total);
             p_props->mpsub.f_total += f2 * p_props->mpsub.i_factor;
             p_subtitle->i_stop = VLC_TICK_0 + llroundf(10000.f * p_props->mpsub.f_total);
             break;
         }
+
+        if( !strncmp( s, "FORMAT=", strlen("FORMAT=") ) )
+        {
+            const char *psz_format = s + strlen( "FORMAT=" );
+            if( !strncmp( psz_format, "TIME", strlen("TIME") ) && (psz_format[4] == '\0' || psz_format[4] == ' ') )
+            {
+                // FORMAT=TIME may be followed by a comment
+                p_props->mpsub.i_factor = 100;
+            }
+            else
+            {
+                float f_fps;
+                if( sscanf( psz_format, "%f", &f_fps ) == 1 )
+                {
+                    if( f_fps > 0.f && var_GetFloat( p_obj, "sub-original-fps" ) <= 0.f )
+                        var_SetFloat( p_obj, "sub-original-fps", f_fps );
+
+                    p_props->mpsub.i_factor = 1;
+                }
+            }
+        }
     }
 
     char *psz_text = NULL;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/07a9e3c865d0c165c21099a84dde9fad0d996739...a2c276959052b592fb37eeed0968ffeac02f0014

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/07a9e3c865d0c165c21099a84dde9fad0d996739...a2c276959052b592fb37eeed0968ffeac02f0014
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list