[vlc-devel] [PATCH] Naming patterns for HLS segments

Łukasz Korbel korbel85 at gmail.com
Tue Apr 17 20:37:13 CEST 2012


I followed your suggestion and extend formatSegmentPath function by
date/time formatting using strftime().

--- a/modules/access_output/livehttp.c
+++ b/modules/access_output/livehttp.c
@@ -75,7 +75,8 @@ static void Close( vlc_object_t * );

 #define INDEXURL_TEXT N_("Full URL to put in index file")
 #define INDEXURL_LONGTEXT N_("Full URL to put in index file. "\
-                          "Use #'s to represent segment number")
+                          "Use #'s to represent segment number. "\
+                          "Use strftime() specifiers for date/time values.")

 #define DELSEGS_TEXT N_("Delete segments")
 #define DELSEGS_LONGTEXT N_("Delete segments when they are no longer needed")
@@ -210,6 +211,28 @@ static char *formatSegmentPath( sout_access_out_t
*p_access, char *psz_path, uin
     if ( ! ( psz_result  = str_format( p_access, psz_path ) ) )
         return NULL;

+    // Apply time formating to segment name if string contains any
time specifiers
+    if ( strcspn( psz_result, '%' ) < strlen( psz_result ) )
+    {
+        time_t now;
+        struct tm * timeinfo;
+        int len;
+        char *psz_tmp;
+
+        time( &now );
+        timeinfo = localtime( &now );
+        // Its hard to determine output final lenght
+        // Assuming twice the lenght of format string is enough
+        len = 2 * strlen( psz_result );
+        psz_tmp = malloc( len * sizeof( char ) );
+        if ( strftime( psz_tmp, len, psz_result, timeinfo ) > 0 )
+        {
+            free( psz_result );
+            psz_result = psz_tmp;
+        }
+    }
+
+    // Replace placeholders with actual segment number
     psz_firstNumSign = psz_result + strcspn( psz_result,
SEG_NUMBER_PLACEHOLDER );
     if ( *psz_firstNumSign ) {
         char *psz_newResult;
@@ -218,7 +241,7 @@ static char *formatSegmentPath( sout_access_out_t
*p_access, char *psz_path, uin

         *psz_firstNumSign = '\0';
         ret = asprintf( &psz_newResult, "%s%0*d%s", psz_result,
i_cnt, i_seg, psz_firstNumSign + i_cnt );
-        free ( psz_result );
+        free( psz_result );
         if ( ret < 0 )
             return NULL;
         psz_result = psz_newResult;
-- 

Best regards,
Łukasz Korbel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-livehttp.c-formatSegmentPath-added-date-time-formatt.patch
Type: application/octet-stream
Size: 2627 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20120417/18f74c28/attachment.obj>


More information about the vlc-devel mailing list