From d8345e8267ed91984f928ff065688c111829f176 Mon Sep 17 00:00:00 2001
From: basos g <noxelia 4t gmail d0t c0m>
Date: Tue, 10 Mar 2009 19:19:17 +0000
Subject: [PATCH 17/17] Vout Snapshot :: Add snapshot-strftime libvlc parameter. Some cleaning

Added a new libvlc parameter to specify exaclty the snapshot filename
format when on non-sequential mode. This string is the format string
that will be passed to strftime. It is an advanced option. With this
one can have more control on the final snapshot file name and especially
its length.

Also fixed the minor seq number to be an one digit of 1/10 second instead
of 3 digits
---
 src/libvlc-module.c          |    6 ++++++
 src/video_output/vout_intf.c |   22 ++++++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 7fb56cf..9ce3ae4 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -471,6 +471,10 @@ static const char *const ppsz_pos_descriptions[] =
 #define SNAP_PREFIX_LONGTEXT N_( \
     "Video snapshot file prefix" )
 
+#define SNAP_STRFTIME_TEXT N_("Video snapshot main file name part (non-sequential)" )
+#define SNAP_STRFTIME_LONGTEXT N_( \
+    "Main file name part that is fed to strftime when in non-sequential mode" )
+
 #define SNAP_FORMAT_TEXT N_("Video snapshot format")
 #define SNAP_FORMAT_LONGTEXT N_( \
     "Image format which will be used to store the video snapshots" )
@@ -1591,6 +1595,8 @@ vlc_module_begin ()
                    SNAP_PATH_LONGTEXT, false )
     add_string( "snapshot-prefix", "vlcsnap-", NULL, SNAP_PREFIX_TEXT,
                    SNAP_PREFIX_LONGTEXT, false )
+    add_string( "snapshot-strftime", "%Y-%m-%d-%Hh%Mm%Ss", NULL, SNAP_STRFTIME_TEXT,
+                   SNAP_STRFTIME_LONGTEXT, true )
     add_string( "snapshot-format", "png", NULL, SNAP_FORMAT_TEXT,
                    SNAP_FORMAT_LONGTEXT, false )
         change_string_list( ppsz_snap_formats, NULL, 0 )
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 465fb0c..dfb146e 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -241,6 +241,7 @@ void vout_IntfInit( vout_thread_t *p_vout )
     /* Create a few object variables we'll need later on */
     var_Create( p_vout, "snapshot-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "snapshot-prefix", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_vout, "snapshot-strftime", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "snapshot-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "snapshot-preview", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "snapshot-sequential",
@@ -648,15 +649,20 @@ static int VoutWriteSnapshot( vout_thread_t *p_vout, char **ppsz_filename,
             }
             else
             {
-                /* suffix with the last decimal digit in 10s of seconds resolution
-                 * FIXME gni ? */
-                const int i_id = (p_image->i_pts / (100*1000)) & 0xFF;
+                /* suffix with a decimal digit (0~9) in 10s of seconds resolution to distinguish
+                   snapshots taken with minimun period 100 msecs ( = 1 * 1/10 sec )
+                 */
+                int i_id = (p_image->i_pts / (100*1000)) & 0xF ;
+                i_id = i_id > 9 ? (i_id & 0x7) - 2 : i_id ;
                 char psz_curtime[128];
-
-                if( !strftime( psz_curtime, sizeof(psz_curtime), "%Y-%m-%d-%Hh%Mm%Ss", &curtime ) )
-                    strcpy( psz_curtime, "error" );
-
-                if( asprintf( &psz_filename, "%s" DIR_SEP "%s%s%1u.%s",
+                char* psz_strftime =
+                    var_GetString( p_vout, "snapshot-strftime" ) ;
+                psz_filename = NULL ;
+                if( !psz_strftime ||
+                    !strftime( psz_curtime, sizeof(psz_curtime), psz_strftime, &curtime ) )
+                    msg_Warn( p_vout, "Error in snapshot-strftime format string or could not get time" );
+                else
+                    if ( asprintf( &psz_filename, "%s" DIR_SEP "%s%s%1u.%s",
                               psz_path, psz_prefix, psz_curtime, i_id, psz_format ) < 0 )
                     psz_filename = NULL;
             }
-- 
1.6.1.3

