網頁

2022年8月1日 星期一

VLC 3.0.17.4 之 LIBVLC 新增錄影功能

參考 Add new API to libvlc to record the current media to either an application-specified file or a file automatically created by vlc

建立 git patch
$ sudo git diff HEAD
$ sudo git status
$ sudo git diff HEAD include/vlc/libvlc_events.h
$ sudo git add include/vlc/libvlc_events.h
$ sudo git diff HEAD include/vlc/libvlc_media_player.h
$ sudo git add include/vlc/libvlc_media_player.h
$ sudo git diff HEAD lib/event.c
$ sudo git add lib/event.c
$ sudo git diff HEAD lib/libvlc.sym
$ sudo git add lib/libvlc.sym
$ sudo git diff HEAD lib/media_player.c
$ sudo git add lib/media_player.c
$ sudo git diff HEAD modules/logger/file.c
$ sudo git add modules/logger/file.c
$ sudo git diff HEAD modules/spu/marq.c
$ sudo git add modules/spu/marq.c
$ sudo git diff HEAD modules/stream_out/record.c
$ sudo git add modules/stream_out/record.c
$ sudo git diff HEAD src/input/input.c
$ sudo git add src/input/input.c
$ sudo git diff HEAD src/input/var.c
$ sudo git add src/input/var.c
$ sudo git diff HEAD src/text/strings.c
$ sudo git add src/text/strings.c
$ sudo git diff HEAD src/video_output/vout_subpictures.c
$ sudo git add src/video_output/vout_subpictures.c

$ sudo git commit -m "add record function"
$ sudo git format-patch -1 -o ../patch
$ sudo git apply ../patch/0001-libvlc-add-record-function.patch

$ sudo git log
$ sudo git checkout c650ce1a4e352c

=======
From 6917e3862fdbd2ae7b411ca6d15ce15644b4e5c8 Mon Sep 17 00:00:00 2001
From: root <ingrenn@yahoo.com.tw>
Date: Thu, 4 Aug 2022 11:33:50 +0800
Subject: [PATCH] libvlc add record function

---
 include/vlc/libvlc_events.h         |  10 +++
 include/vlc/libvlc_media_player.h   | 115 ++++++++++++++++++++++++++++
 lib/event.c                         |   3 +
 lib/libvlc.sym                      |   4 +
 lib/media_player.c                  | 114 ++++++++++++++++++++++++++-
 modules/logger/file.c               |  13 +++-
 modules/spu/marq.c                  |   1 +
 modules/stream_out/record.c         |  20 +++++
 src/input/input.c                   |   8 +-
 src/input/var.c                     |   3 +
 src/text/strings.c                  |  56 +++++++++++++-
 src/video_output/vout_subpictures.c |   4 +-
 12 files changed, 344 insertions(+), 7 deletions(-)

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index f8b0e9b5b2..0e2b4d668b 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -86,6 +86,8 @@ enum libvlc_event_e {
     libvlc_MediaPlayerAudioVolume,
     libvlc_MediaPlayerAudioDevice,
     libvlc_MediaPlayerChapterChanged,
+    libvlc_MediaPlayerRecordableChanged,
+    libvlc_MediaPlayerRecordingFinished,
 
     libvlc_MediaListItemAdded=0x200,
     libvlc_MediaListWillAddItem,
@@ -283,6 +285,14 @@ typedef struct libvlc_event_t
         {
             libvlc_renderer_item_t *item;
         } renderer_discoverer_item_deleted;
+        struct
+        {
+            int new_recordable;
+        } media_player_recordable_changed;
+        struct
+        {
+            char *psz_filename;
+        } media_player_recording_finished;
     } u; /**< Type-dependent event description */
 } libvlc_event_t;
 
diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index c431c235e9..1f664b86a6 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -2082,6 +2082,121 @@ LIBVLC_API int libvlc_media_player_set_role(libvlc_media_player_t *p_mi,
 
 /** @} audio */
 
+/**
+ * Can the media player record the current media?
+ *
+ * Media must be buffering or playing before it can be recorded.
+ *
+ * The media player event manager will emit a libvlc_MediaPlayerRecordableChanged event
+ * when the recordable state changes after starting media playback. The event data will
+ * describe the new recordable state, so invocation of this API method is not strictly
+ * necessary to determine when recording can be started.
+ *
+ * A libvlc_MediaPlayerRecordableChanged event will not be emitted if the media is
+ * stopped (notified by a libvlc_MediaPlayerStoppedEvent) or finishes normally (notified
+ * by a libvlc_MediaPlayerFinished event).
+ *
+ * A calling application should therefore register an event callback for those events
+ * so that it may query the new recordable state and manage recording at the appropriate
+ * time.
+ *
+ * \param p_mi media player
+ * \return true if the media player can record, false if it can not
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API bool libvlc_media_player_is_recordable( libvlc_media_player_t *p_mi );
+
+/**
+ * Is the current media being recorded?
+ *
+ * \param p_mi media player
+ * \return true if recording, false if not
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API bool libvlc_media_player_is_recording( libvlc_media_player_t *p_mi );
+
+/**
+ * Start recording the current media.
+ *
+ * Media must be buffering or playing before it can be recorded. A calling application
+ * can begin recording immediately on receipt of a libvlc_MediaPlayerRecordableChanged
+ * event sent via the media player event manager (if recording is possible for the
+ * currently playing media), and any time thereafter until the media stops.
+ *
+ * Media will be saved to the file path denoted by the psz_filename parameter if it is
+ * supplied. Any such supplied filename should not include a file extension as the
+ * correct file extension will automatically be appended when the file is created. This
+ * filename may denote a full path name, but each directory in the path must already
+ * exist or recording will silently fail. If the calling application chooses to specify
+ * the filename then it is the responsibility of that application to take account of
+ * this and itself make sure any needed directories are created.
+ *
+ * Alternatively, a calling application need not supply a filename and so instead let
+ * vlc automatically generate a unique filename. This will cause vlc to create a new
+ * file in the appropriate media directory for the user - for example "~/Videos". The
+ * actual filename used will be sent in an event when the recording is complete.
+ *
+ * When recording has finished and the new file has been completely saved, a
+ * libvlc_MediaPlayerRecordingFinished event will be sent via the media player event
+ * manager. The event data will contain the filename of the newly recorded file - this
+ * will either be the filename as specified by the calling application or a filename
+ * generated by vlc if the application did not supply a filename. In either case, this
+ * filename will include the automatically appended file extension.
+ *
+ * The saved media file will not be immediately available or visible until recording
+ * has completely finished and the libvlc_MediaPlayerRecordingFinished event has been
+ * received, or the media has stopped or finished normally.
+ *
+ * Recording can be stopped and started on-the-fly once the recordable state is set;
+ * each time recording is stopped and restarted a new file will be created so a calling
+ * application should take care to provide unique filenames, or defer to vlc to create
+ * unique filenames.
+ *
+ * Recording will be stopped when the media stops playing, and must be explicitly
+ * started again to restart recording, i.e. the recording state is not automatically
+ * preserved when playing media subsequently.
+ *
+ * Media player functionailty such as next/previous chapter, set time or position and
+ * so on are ineffective when recording is enabled. However, pausing the media is
+ * possible and will pause the recording; unpausing the media will resume playback and
+ * recording.
+ *
+ * Recording of the primary media or sub-items is possible.
+ *
+ * \param p_mi media player
+ * \param psz_filename name of the file to save the media to, not including any file extension,
+ *                     or NULL if vlc should generate the filename automatically
+ * \return 0 if recording was started, -1 on error
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API int libvlc_media_player_record_start( libvlc_media_player_t *p_mi, const char *psz_filename );
+
+/**
+ * Stop recording the current media.
+ *
+ * This method requests that the recording stop, and will return immediately. Recording
+ * will not stop immediately.
+ *
+ * When the recording actually stops some short time later and the new file has
+ * finished being written, a libvlc_MediaPlayerRecordingFinished event will be sent via
+ * the media player event manager. The newly recorded file will not be visible or
+ * available until after this event has been sent.
+ *
+ * The event data will contain the full name of the file that was created. The filename
+ * will either be that as was specified by the calling application on invoking
+ * libvlc_media_player_record_start(), or the filename that vlc automatically generated
+ * if the calling application did not supply its own filename. In either case the
+ * filename will contain the automatically appended file extension.
+ *
+ * There is no need to invoke this method to stop the recording if the media is stopped
+ * or finishes playing normally.
+ *
+ * \param p_mi media player
+ * \return 0 if recording was stopped, -1 on error
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API int libvlc_media_player_record_stop( libvlc_media_player_t *p_mi );
+
 /** @} media_player */
 
 # ifdef __cplusplus
diff --git a/lib/event.c b/lib/event.c
index f027754181..dba8a55a86 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -173,6 +173,9 @@ static const event_name_t event_list[] = {
     DEF(MediaPlayerAudioVolume)
     DEF(MediaPlayerAudioDevice)
     DEF(MediaPlayerChapterChanged)
+    DEF(MediaPlayerRecordableChanged)
+    DEF(MediaPlayerRecordingFinished)
+
 
     DEF(MediaListItemAdded)
     DEF(MediaListWillAddItem)
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index 482d95f6f1..dbcc49a7ad 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -175,6 +175,8 @@ libvlc_media_player_get_title
 libvlc_media_player_get_title_count
 libvlc_media_player_get_xwindow
 libvlc_media_player_has_vout
+libvlc_media_player_is_recordable
+libvlc_media_player_is_recording
 libvlc_media_player_is_seekable
 libvlc_media_player_is_playing
 libvlc_media_player_new
@@ -184,6 +186,8 @@ libvlc_media_player_set_pause
 libvlc_media_player_pause
 libvlc_media_player_play
 libvlc_media_player_previous_chapter
+libvlc_media_player_record_start
+libvlc_media_player_record_stop
 libvlc_media_player_release
 libvlc_media_player_retain
 libvlc_media_player_set_agl
diff --git a/lib/media_player.c b/lib/media_player.c
index fda1091cc8..43ac2d8154 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -54,6 +54,11 @@ input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval,
                         void * p_userdata );
 static int
+input_recordable_changed( vlc_object_t *p_this, char const *psz_cmd,
+                          vlc_value_t oldval, vlc_value_t newval,
+                          void *p_userdata );
+
+static int
 input_scrambled_changed( vlc_object_t * p_this, char const * psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval,
                         void * p_userdata );
@@ -89,6 +94,10 @@ static int
 snapshot_was_taken( vlc_object_t *p_this, char const *psz_cmd,
                     vlc_value_t oldval, vlc_value_t newval, void *p_data );
 
+static int
+file_recording_finished( vlc_object_t *p_this, char const *psz_cmd,
+                         vlc_value_t oldval, vlc_value_t newval, void *p_data );
+
 static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi );
 
 /*
@@ -174,6 +183,8 @@ static void release_input_thread( libvlc_media_player_t *p_mi )
                      input_seekable_changed, p_mi );
     var_DelCallback( p_input_thread, "can-pause",
                     input_pausable_changed, p_mi );
+    var_DelCallback( p_input_thread, "can-record",
+                     input_recordable_changed, p_mi );
     var_DelCallback( p_input_thread, "program-scrambled",
                     input_scrambled_changed, p_mi );
     var_DelCallback( p_input_thread, "intf-event",
@@ -271,6 +282,25 @@ input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
     return VLC_SUCCESS;
 }
 
+static int
+input_recordable_changed( vlc_object_t *p_this, char const *psz_cmd,
+                          vlc_value_t oldval, vlc_value_t newval,
+                          void *p_userdata )
+{
+    VLC_UNUSED(p_this);
+    VLC_UNUSED(psz_cmd);
+    VLC_UNUSED(oldval);
+
+    libvlc_media_player_t *p_mi = p_userdata;
+    libvlc_event_t event;
+
+    event.type = libvlc_MediaPlayerRecordableChanged;
+    event.u.media_player_recordable_changed.new_recordable = newval.b_bool;
+
+    libvlc_event_send( &p_mi->event_manager, &event );
+    return VLC_SUCCESS;
+}
+
 static int
 input_scrambled_changed( vlc_object_t * p_this, char const * psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval,
@@ -529,6 +559,23 @@ static int snapshot_was_taken(vlc_object_t *p_this, char const *psz_cmd,
     return VLC_SUCCESS;
 }
 
+static int file_recording_finished(vlc_object_t *p_this, char const *psz_cmd,
+                                   vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    VLC_UNUSED(p_this);
+    VLC_UNUSED(psz_cmd);
+    VLC_UNUSED(oldval);
+
+    libvlc_media_player_t *p_mi = p_data;
+    libvlc_event_t event;
+
+    event.type = libvlc_MediaPlayerRecordingFinished;
+    event.u.media_player_recording_finished.psz_filename = newval.psz_string;
+
+    libvlc_event_send( &p_mi->event_manager, &event);
+    return VLC_SUCCESS;
+}
+
 static int corks_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
                          vlc_value_t cur, void *opaque)
 {
@@ -620,6 +667,10 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     /* Input */
     var_Create (mp, "rate", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT);
     var_Create (mp, "sout", VLC_VAR_STRING);
+    char *psz = var_GetNonEmptyString( instance->p_libvlc_int, "sout" );
+    if (psz) {
+        var_SetString(mp, "sout", psz);
+    }
     var_Create (mp, "demux-filter", VLC_VAR_STRING);
 
     /* Video */
@@ -713,6 +764,8 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     var_Create (mp, "amem-set-volume", VLC_VAR_ADDRESS);
     var_Create (mp, "amem-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
     var_Create (mp, "amem-rate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "recording-finished", VLC_VAR_STRING);
+    var_AddCallback (mp, "recording-finished", file_recording_finished, mp);
     var_Create (mp, "amem-channels", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
 
     /* Video Title */
@@ -807,7 +860,8 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
     /* Detach Callback from the main libvlc object */
     var_DelCallback( p_mi->obj.libvlc,
                      "snapshot-file", snapshot_was_taken, p_mi );
-
+    var_DelCallback( p_mi, "recording-finished", file_recording_finished, p_mi );
+                     
     /* Detach callback from the media player / input manager object */
     var_DelCallback( p_mi, "volume", volume_changed, NULL );
     var_DelCallback( p_mi, "mute", mute_changed, NULL );
@@ -997,6 +1051,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
 
     var_AddCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
     var_AddCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
+    var_AddCallback( p_input_thread, "can-record", input_recordable_changed, p_mi );
     var_AddCallback( p_input_thread, "program-scrambled", input_scrambled_changed, p_mi );
     var_AddCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
     add_es_callbacks( p_input_thread, p_mi );
@@ -1006,6 +1061,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
         unlock_input(p_mi);
         del_es_callbacks( p_input_thread, p_mi );
         var_DelCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
+        var_DelCallback( p_input_thread, "can-record", input_recordable_changed, p_mi );
         var_DelCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
         var_DelCallback( p_input_thread, "program-scrambled", input_scrambled_changed, p_mi );
         var_DelCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
@@ -1932,6 +1988,62 @@ void libvlc_media_player_next_frame( libvlc_media_player_t *p_mi )
     }
 }
 
+bool libvlc_media_player_is_recordable( libvlc_media_player_t *p_mi )
+{
+    input_thread_t *p_input_thread;
+    bool b_can_record;
+
+    p_input_thread = libvlc_get_input_thread( p_mi );
+    if( !p_input_thread )
+        return false;
+
+    b_can_record = var_GetBool( p_input_thread, "can-record" );
+
+    vlc_object_release( p_input_thread );
+    return b_can_record;
+}
+bool libvlc_media_player_is_recording( libvlc_media_player_t *p_mi )
+{
+    input_thread_t *p_input_thread;
+    bool b_record;
+
+    p_input_thread = libvlc_get_input_thread( p_mi );
+    if( !p_input_thread )
+        return false;
+
+    b_record = var_GetBool( p_input_thread, "record" );
+
+    vlc_object_release( p_input_thread );
+    return b_record;
+}
+int libvlc_media_player_record_start( libvlc_media_player_t *p_mi, const char* psz_filename )
+{
+    input_thread_t *p_input_thread;
+
+    p_input_thread = libvlc_get_input_thread( p_mi );
+    if( !p_input_thread )
+        return -1;
+
+    var_SetString( p_input_thread, "input-record-path", psz_filename );
+    var_SetBool( p_input_thread, "record", true );
+
+    vlc_object_release( p_input_thread );
+    return 0;
+}
+int libvlc_media_player_record_stop( libvlc_media_player_t *p_mi )
+{
+    input_thread_t *p_input_thread;
+
+    p_input_thread = libvlc_get_input_thread( p_mi );
+    if( !p_input_thread )
+        return -1;
+
+    var_SetBool( p_input_thread, "record", false );
+
+    vlc_object_release( p_input_thread );
+    return 0;
+}
+
 /**
  * Private lookup table to get subpicture alignment flag values corresponding
  * to a libvlc_position_t enumerated value.
diff --git a/modules/logger/file.c b/modules/logger/file.c
index 6b6dfd2973..80b1bb6066 100644
--- a/modules/logger/file.c
+++ b/modules/logger/file.c
@@ -58,8 +58,19 @@ static void LogText(void *opaque, int type, const vlc_log_t *meta,
     if (sys->verbosity < type)
         return;
 
+    struct timespec ts;
+    struct tm curtime;
+    char tmBuf[128];
+    timespec_get(&ts, TIME_UTC);
+    if (localtime_r(&ts.tv_sec, &curtime) == NULL) {
+        gmtime_r(&ts.tv_sec, &curtime);
+    }
+    if (strftime(tmBuf, sizeof(tmBuf), "%M%S", &curtime) == 0) {
+        strcpy(tmBuf, "no time");
+    }
+    
     flockfile(stream);
-    fprintf(stream, "%s%s: ", meta->psz_module, msg_type[type]);
+    fprintf(stream, "%s.%03d %s%s: ", tmBuf, (int)(ts.tv_nsec / 1000000), meta->psz_module, msg_type[type]);
     vfprintf(stream, format, ap);
     putc_unlocked('\n', stream);
     funlockfile(stream);
diff --git a/modules/spu/marq.c b/modules/spu/marq.c
index 516838ef63..ea7534ab74 100644
--- a/modules/spu/marq.c
+++ b/modules/spu/marq.c
@@ -287,6 +287,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         }
     }
 
+    //msg_Dbg( p_filter, "mark: %s", p_sys->format );
     char *msg = vlc_strftime( p_sys->format ? p_sys->format : "" );
     if( unlikely( msg == NULL ) )
         goto out;
diff --git a/modules/stream_out/record.c b/modules/stream_out/record.c
index be10bb98c4..8f43e72261 100644
--- a/modules/stream_out/record.c
+++ b/modules/stream_out/record.c
@@ -110,6 +110,8 @@ struct sout_stream_sys_t
     int              i_id;
     sout_stream_id_sys_t **id;
     mtime_t     i_dts_start;
+    
+    char *psz_record_file;
 };
 
 static void OutputStart( sout_stream_t *p_stream );
@@ -157,6 +159,8 @@ static int Open( vlc_object_t *p_this )
     p_sys->b_drop = false;
     p_sys->i_dts_start = 0;
     TAB_INIT( p_sys->i_id, p_sys->id );
+    
+    p_sys->psz_record_file = NULL;
 
     return VLC_SUCCESS;
 }
@@ -172,6 +176,19 @@ static void Close( vlc_object_t * p_this )
     if( p_sys->p_out )
         sout_StreamChainDelete( p_sys->p_out, p_sys->p_out );
 
+    if( p_sys->psz_record_file ) {
+        for( vlc_object_t *p_mp = p_stream->obj.parent; p_mp; p_mp = p_mp->obj.parent )
+        {
+            if( var_Type( p_mp, "recording-finished" ) )
+            {
+                var_SetString( p_mp, "recording-finished", p_sys->psz_record_file );
+                break;
+            }
+        }
+
+        free( p_sys->psz_record_file );
+    }
+    
     TAB_CLEAN( p_sys->i_id, p_sys->id );
     free( p_sys->psz_prefix );
     free( p_sys );
@@ -357,7 +374,10 @@ static int OutputNew( sout_stream_t *p_stream,
     }
 
     if( psz_file && psz_extension )
+    {
+        p_sys->psz_record_file = strdup( psz_file );
         var_SetString( p_stream->obj.libvlc, "record-file", psz_file );
+    }
 
     free( psz_file );
     free( psz_output );
diff --git a/src/input/input.c b/src/input/input.c
index 04e5b3bb72..114d8bb1f0 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -3554,9 +3554,13 @@ char *input_CreateFilename(input_thread_t *input, const char *dir,
 
     filename_sanitize(filename);
 
+    //if (((ext != NULL)
+    //        ? asprintf(&path, "%s"DIR_SEP"%s.%s", dir, filename, ext)
+    //        : asprintf(&path, "%s"DIR_SEP"%s", dir, filename)) < 0)
+    //    path = NULL;
     if (((ext != NULL)
-            ? asprintf(&path, "%s"DIR_SEP"%s.%s", dir, filename, ext)
-            : asprintf(&path, "%s"DIR_SEP"%s", dir, filename)) < 0)
+            ? asprintf(&path, "%s.%s", dir, ext)
+            : asprintf(&path, "%s", dir)) < 0)
         path = NULL;
 
     free(filename);
diff --git a/src/input/var.c b/src/input/var.c
index 631b571c19..46a889d1e1 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -202,6 +202,9 @@ void input_ControlVarInit ( input_thread_t *p_input )
 
     var_Create( p_input, "spu-choice", VLC_VAR_INTEGER );
     var_SetInteger( p_input, "spu-choice", -1 );
+    
+    /* ES Out */
+    var_Create( p_input, "input-record-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
 
     /* Special read only objects variables for intf */
     var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
diff --git a/src/text/strings.c b/src/text/strings.c
index a15541afba..a936e5649c 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -481,7 +481,7 @@ char *vlc_b64_decode( const char *psz_src )
     return p_dst;
 }
 
-char *vlc_strftime( const char *tformat )
+char *vlc_strftime_old( const char *tformat )
 {
     time_t curtime;
     struct tm loctime;
@@ -511,6 +511,60 @@ char *vlc_strftime( const char *tformat )
     vlc_assert_unreachable ();
 }
 
+char *vlc_strftime( const char *tformat )
+{
+    struct timespec ts;
+    struct tm loctime;
+
+    if (strcmp (tformat, "") == 0)
+        return strdup (""); /* corner case w.r.t. strftime() return value */
+
+    /* Get the current time.  */
+    timespec_get(&ts, TIME_UTC);
+
+    /* Convert it to local time representation.  */
+    if (localtime_r(&ts.tv_sec, &loctime) == NULL) {
+        gmtime_r(&ts.tv_sec, &loctime);
+    }
+    size_t len = strlen(tformat);
+    char *nFormat = malloc(len + 32);
+    BOOL noMs = TRUE;
+    size_t i = 0, j = 0;
+    for (; i < len; i++, j++) {
+        if (tformat[i] == '%' && tformat[i+1] == 'l') {
+            char ms[32];
+            sprintf(ms, "%03d", (int)(ts.tv_nsec / 1000000));
+            nFormat[j] = 0;
+            strcat(nFormat, ms);
+            strcat(nFormat, &(tformat[i+2]));
+            noMs = FALSE;
+            break;
+        } else {
+            nFormat[j] = tformat[i];
+        }
+    }
+    if (noMs) nFormat[i] = 0;
+    for (size_t buflen = strlen (nFormat) + 32;; buflen += 32)
+    {
+        char *str = malloc (buflen);
+        if (str == NULL) {
+            free(nFormat);
+            return NULL;
+        }
+
+        size_t len = strftime (str, buflen, nFormat, &loctime);
+        if (len > 0)
+        {
+            char *ret = realloc (str, len + 1);
+            free(nFormat);
+            return ret ? ret : str; /* <- this cannot fail */
+        }
+        free (str);
+    }
+    free(nFormat);
+    vlc_assert_unreachable ();
+}
+
 static void write_duration(struct vlc_memstream *stream, int64_t duration)
 {
     lldiv_t d;
diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index 7dbeee3a2a..d998fd4f70 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -1064,8 +1064,8 @@ static subpicture_t *SpuRenderSubpictures(spu_t *spu,
                 msg_Err(spu, "original picture size %dx%d is unsupported",
                          subpic->i_original_picture_width,
                          subpic->i_original_picture_height);
-            else
-                msg_Warn(spu, "original picture size is undefined");
+            //else
+            //    msg_Warn(spu, "original picture size is undefined");
 
             subpic->i_original_picture_width  = fmt_src->i_visible_width;
             subpic->i_original_picture_height = fmt_src->i_visible_height;
-- 
2.17.1