[FFmpeg-devel] burn-in timestamp and pts:localtime:offset

Patrick Fischer patrick.fischer at vitec.com
Mon Oct 10 09:40:11 EEST 2016


Hello list,

I'm using drawtext to burn-in the timestamp into a video.
the current way is to use

*drawtext='fontfile=FreeSans.ttf:text=%{localtime\:%T  %d.%m.%Y}'*

but it only works fine with real-time encoding.
I'm receiving a UDP multicast stream and the problem is that the stream
will be buffered, this leads into a slow down timestamp for the first
3-10 sec and after 10 sec it works fine.

so take a look at
*drawtext='fontfile=FreeSans.ttf:text=%{pts\:localtime\:`date +%s`\:%T 
%d.%m.%Y}'*

the date +%s will take the sec since 1970....
the problem is that it can take a few sec until the udp stream will
probed and start to record. So the timestamp is always 3-10 sec in the past.

So i think it would be a nice idea to define the offset with a special
keyword like "now"

*drawtext='fontfile=FreeSans.ttf:text=%{pts\:localtime\:now:%T  %d.%m.%Y}'*

now will calc the offset (in the code it is called delta) at the
receiving of the first frame.

for better understanding i have attached a small diff.
It is a little bit dirty because of the static int64 delta.
By the way the current impl works relay inefficient. It will parse
always the same string for each frame.
So my example only parse the string if the delta is 0.

This will also work fine with no real-time encoding.
What do you think, will this be a good enhancement??

best regards
Patrick



--- FFmpeg-release-3.0_orig/libavfilter/vf_drawtext.c   2016-09-05
02:13:28.000000000 +0200
+++ FFmpeg-release-3.0/libavfilter/vf_drawtext.c 2016-09-22
10:22:55.625648763 +0200
@@ -791,6 +791,7 @@
     return 0;
 }
 
+static int64_t delta = 0;
 static int func_pts(AVFilterContext *ctx, AVBPrint *bp,
                     char *fct, unsigned argc, char **argv, int tag)
 {
@@ -801,10 +802,13 @@
 
     fmt = argc >= 1 ? argv[0] : "flt";
     if (argc >= 2) {
-        int64_t delta;
-        if ((ret = av_parse_time(&delta, argv[1], 1)) < 0) {
-            av_log(ctx, AV_LOG_ERROR, "Invalid delta '%s'\n", argv[1]);
-            return ret;
+        if (0 == delta) {
+            if (!strcmp(argv[1], "now")) {
+                delta = time(NULL)*1000000;
+            } else if ((ret = av_parse_time(&delta, argv[1], 1)) < 0) {
+                av_log(ctx, AV_LOG_ERROR, "Invalid delta '%s'\n", argv[1]);
+                return ret;
+            }
         }
         pts += (double)delta / AV_TIME_BASE;
     }



More information about the ffmpeg-devel mailing list