[FFmpeg-cvslog] vf_drawtext: make strftime work without localtime_r()

Michael Niedermayer git at videolan.org
Mon Sep 5 19:02:02 CEST 2011


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Mon Sep  5 05:16:44 2011 +0200| [038a465efc737b331e39869b3f31a4997b6ee12d] | committer: Michael Niedermayer

vf_drawtext: make strftime work without localtime_r()
modern OS should have localtime_r() or return thread locals on localtime() hopefully

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=038a465efc737b331e39869b3f31a4997b6ee12d
---

 libavfilter/vf_drawtext.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index a2a7724..b368621 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -318,10 +318,6 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
     }
     dtext->tabsize *= glyph->advance;
 
-#if !HAVE_LOCALTIME_R
-    av_log(ctx, AV_LOG_WARNING, "strftime() expansion unavailable!\n");
-#endif
-
     return 0;
 }
 
@@ -574,7 +570,6 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
     Glyph *glyph = NULL, *prev_glyph = NULL;
     Glyph dummy = { 0 };
 
-#if HAVE_LOCALTIME_R
     time_t now = time(0);
     struct tm ltime;
     uint8_t *buf = dtext->expanded_text;
@@ -588,7 +583,12 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
         buf = av_malloc(buf_size);
     }
 
+#if HAVE_LOCALTIME_R
     localtime_r(&now, &ltime);
+#else
+    if(strchr(dtext->text, '%'))
+        ltime= *localtime(&now);
+#endif
 
     do {
         *buf = 1;
@@ -601,7 +601,6 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
         return AVERROR(ENOMEM);
     text = dtext->expanded_text = buf;
     dtext->expanded_text_size = buf_size;
-#endif
     if ((len = strlen(text)) > dtext->nb_positions) {
         if (!(dtext->positions =
               av_realloc(dtext->positions, len*sizeof(*dtext->positions))))



More information about the ffmpeg-cvslog mailing list