[FFmpeg-devel] [PATCH] avidec: export date as metadata

Michael Niedermayer michaelni
Wed Nov 17 01:00:28 CET 2010


On Wed, Nov 17, 2010 at 12:40:26AM +0100, Aurelien Jacobs wrote:
> Hi,
> 
> Attached patch export the date stored in AVI files as a metadata.
> 
> Aurel
>  avidec.c |   29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 6bf2471b5811100ac2aeb54d957b20d662a784f6  avi_date.diff
> diff --git a/libavformat/avidec.c b/libavformat/avidec.c
> index 2d38191..3f2db9f 100644
> --- a/libavformat/avidec.c
> +++ b/libavformat/avidec.c
> @@ -22,6 +22,7 @@
>  //#define DEBUG
>  //#define DEBUG_SEEK
>  
> +#include <strings.h>
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/bswap.h"
>  #include "libavcodec/bytestream.h"
> @@ -282,6 +283,26 @@ static void avi_read_info(AVFormatContext *s, uint64_t end)
>      }
>  }
>  
> +static const char months[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
> +                                    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
> +
> +static void avi_metadata_date(AVMetadata **metadata, char *date)
> +{

> +    if (HAVE_STRTOK_R) {

maybe strcspn() would make this unneeded ?
or sscanf() could be used


    
> +        char *saveptr, *part[5] = {0}, buffer[64];
> +        int i;
> +        /* parse standard AVI date format (ie. "Mon Mar 10 15:04:43 2003") */
> +        for (i=0; i<5; i++, date=NULL)
> +            part[i] = strtok_r(date, " \t\r\n", &saveptr);
> +        for (i=0; i<12; i++)
> +            if (part[4] && !strcasecmp(part[1], months[i])) {
> +                snprintf(buffer, sizeof(buffer), "%s-%.2d-%.2d %s",
> +                         part[4], i+1, atoi(part[2]), part[3]);
> +                av_metadata_set2(metadata, "date", buffer, 0);
> +            }
> +    }
> +}

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101117/000984eb/attachment.pgp>



More information about the ffmpeg-devel mailing list