[FFmpeg-devel] [PATCH] Add support for drawing PTS in HHMMSSms format to vf_drawtext
Nicolas George
george at nsup.org
Fri Apr 25 14:04:38 CEST 2014
Le quintidi 5 floréal, an CCXXII, hjiodjf 97xgw46 a écrit :
> Thank you for pointing this out. I've simplified my patch and
> converted it to use an expansion function.
Thanks. A few more comments.
> From 3fb6b22d59b5216717907f591e1b57f0bad80c7d Mon Sep 17 00:00:00 2001
> From: tue46wsdgxfjrt <jfbvxt at gmail.com>
> Date: Wed, 19 Mar 2014 13:26:11 -0700
> Subject: [PATCH 2/2] Add support for drawing wall clock timestamps to
> vf_drawtext.
>
> ---
> doc/filters.texi | 3 +++
> libavfilter/vf_drawtext.c | 25 +++++++++++++++++++++++++
> 2 files changed, 28 insertions(+)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index e943923..6c437e0 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -3852,6 +3852,9 @@ A 1 character description of the current picture type.
> @item pts
> The timestamp of the current frame, in seconds, with microsecond accuracy.
>
> + at item timestamp
> +The timestamp of the current frame as HH:MM:SS.ms, with millisecond accuracy.
Maybe "HH:MM:SS.mmm", to make more obvious that millisecond means three
digits.
> +
> @end table
>
> @subsection Examples
> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
> index 280abb8..973f811 100644
> --- a/libavfilter/vf_drawtext.c
> +++ b/libavfilter/vf_drawtext.c
> @@ -700,6 +700,30 @@ static int func_pts(AVFilterContext *ctx, AVBPrint *bp,
> return 0;
> }
>
> +static int func_timestamp(AVFilterContext *ctx, AVBPrint *bp,
> + char *fct, unsigned argc, char **argv, int tag)
> +{
> + DrawTextContext *s = ctx->priv;
> + int64_t ts = 0;
> + int hh, mm, ss, ms;
> +
> + if (argc > 0) {
> + ts += round(atof(argv[0]) * 1000);
> + }
I assume this means that %{timestamp:42} will shift the timestamps by 42
seconds, but it is not explained in the doc. And it is a bit strange to have
that feature for timestamp and not pts.
Also, maybe use av_parse_time(), that would avoid floats completely.
> + ts += round(s->var_values[VAR_T] * 1000);
The rest of the code seems to handle the NOPTS case, so I suppose it should
be handled here too.
> +
> + hh = ts / (3600 * 1000);
> + ts = ts % (3600 * 1000);
> + mm = ts / (60 * 1000);
> + ts = ts % (60 * 1000);
> + ss = ts / 1000;
> + ts = ts % 1000;
> + ms = ts;
> +
> + av_bprintf(bp, "%02d:%02d:%02d.%03d", hh, mm, ss, ms);
Also, negative case is not handled gracefully.
> + return 0;
> +}
> +
> static int func_frame_num(AVFilterContext *ctx, AVBPrint *bp,
> char *fct, unsigned argc, char **argv, int tag)
> {
> @@ -773,6 +797,7 @@ static const struct drawtext_function {
> { "e", 1, 1, 0, func_eval_expr },
> { "pict_type", 0, 0, 0, func_pict_type },
> { "pts", 0, 0, 0, func_pts },
> + { "timestamp", 0, 1, 0, func_timestamp },
I find the name "timestamp" a big vague, but I have no better proposal than
"hmspts".
> { "gmtime", 0, 1, 'G', func_strftime },
> { "localtime", 0, 1, 'L', func_strftime },
> { "frame_num", 0, 0, 0, func_frame_num },
I have an alternate proposal. Please comment. And tel me if you want to be
co-credited.
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-lavfi-drawtext-allow-to-format-pts-as-HH-MM-SS.mmm.patch
Type: text/x-diff
Size: 3193 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140425/0688c932/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140425/0688c932/attachment.asc>
More information about the ffmpeg-devel
mailing list