[FFmpeg-devel] [PATCH ] libavformat/utils : add timestamp option in av_get_frame_filename
Nicolas George
nicolas.george at normalesup.org
Sun Oct 21 10:14:15 CEST 2012
Le nonidi 29 vendémiaire, an CCXXI, Tom Fonck a écrit :
> I added an option to use the current time in the filename output
> instead of a counter.
>
> If you think it isn't useful for others (or the code is bad), no problem.
It is probably useful, indded. Thanks for the patch.
>
> Regards,
>
> Tom
>
> >From 71bb60aee7513e0fb22f6252aec85a7fe572f915 Mon Sep 17 00:00:00 2001
> From: Tom Fonck <tomf at besite.be>
> Date: Sat, 20 Oct 2012 14:32:05 +0200
> Subject: [PATCH 1/1] libavformat/utils : add timestamp option in av_get_frame_filename
>
> ---
> libavformat/utils.c | 16 ++++++++++++++++
> 1 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index be1be00..4477b06 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -21,6 +21,7 @@
>
> /* #define DEBUG */
>
> +#include <sys/time.h>
> #include "avformat.h"
> #include "avio_internal.h"
> #include "internal.h"
> @@ -3409,6 +3410,8 @@ int av_get_frame_filename(char *buf, int buf_size,
> const char *p;
> char *q, buf1[20], c;
> int nd, len, percentd_found;
> + const struct timeval tim;
> + long int timestamp;
long is almost never an adequate type. In this particular case, it is not:
on 32 bits architectures, long is almost always 32 bits, and your
computations will overflow immediately.
>
> q = buf;
> p = path;
> @@ -3429,6 +3432,19 @@ int av_get_frame_filename(char *buf, int buf_size,
> switch(c) {
> case '%':
> goto addchar;
> + case 't':
> + if (percentd_found)
> + goto fail;
> + percentd_found = 1;
> + gettimeofday(&tim, NULL);
> + timestamp = (tim.tv_sec * 1000000) + tim.tv_usec;
There is an av_gettime that already does that, without the portability
issues.
But I fail to see the use of that: a frame name based on the frame timestamp
(PTS) seems useful, but based on the physical time the frame happens to
arrive to the muxer I do not see.
> + snprintf(buf1, sizeof(buf1), "%lu", timestamp);
> + len = strlen(buf1);
> + if ((q - buf + len) > buf_size - 1)
> + goto fail;
> + memcpy(q, buf1, len);
> + q += len;
> + break;
> case 'd':
> if (percentd_found)
> goto fail;
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121021/1fc98f19/attachment.asc>
More information about the ffmpeg-devel
mailing list