[FFmpeg-devel] [Read EXIF metadata 2/3] Add EXIF metadata parser to libavcodec.

Michael Niedermayer michaelni at gmx.at
Sat Aug 10 00:52:35 CEST 2013


On Fri, Aug 09, 2013 at 04:41:32PM +0200, Thilo Borgmann wrote:
> 2/3 rev 3
> 
> -Thilo

>  exif.c |  228 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  exif.h |  168 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 396 insertions(+)
> 1eb48624a546b2df5084c2f1270a6fc9f6a1217b  0002-Add-EXIF-metadata-parser-to-libavcodec.patch
> From 1b2045a2a0d5754fa02dc5e7729ad7bc19998670 Mon Sep 17 00:00:00 2001
> From: Thilo Borgmann <thilo.borgmann at googlemail.com>
> Date: Fri, 9 Aug 2013 16:33:43 +0200
> Subject: [PATCH 2/3] Add EXIF metadata parser to libavcodec.
> 
> ---
>  libavcodec/exif.c |  228 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  libavcodec/exif.h |  168 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 396 insertions(+), 0 deletions(-)
>  create mode 100644 libavcodec/exif.c
>  create mode 100644 libavcodec/exif.h
> 
> diff --git a/libavcodec/exif.c b/libavcodec/exif.c
> new file mode 100644
> index 0000000..776c094
> --- /dev/null
> +++ b/libavcodec/exif.c
> @@ -0,0 +1,228 @@
> +/*
> + * EXIF metadata parser
> + * Copyright (c) 2013 Thilo Borgmann <thilo.borgmann _at_ googlemail.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @file
> + * EXIF metadata parser
> + * @author Thilo Borgmann <thilo.borgmann _at_ googlemail.com>
> + */
> +
> +#include "exif.h"
> +
> +
> +static char *rationals2str(int *rp, int count, const char *sep)
> +{
> +    int i;
> +    char *ap, *ap0;
> +    uint64_t component_len;
> +    if (!sep) sep = ", ";
> +    component_len = 20LL+1LL+20LL + strlen(sep);
> +    ap    = av_malloc_array(count + 1, component_len);
> +    ap0   = ap;
> +    ap[0] = '\0';
> +    for (i = 0; i < count; i++) {
> +        unsigned l = snprintf(ap, component_len, "%i:%i%s", rp[2*i + 0], rp[2*i + 1], sep);
> +        if (l >= component_len) {
> +            av_free(ap0);
> +            return NULL;
> +        }
> +        ap += l;
> +    }
> +    ap0[strlen(ap0) - strlen(sep)] = '\0';
> +    return ap0;
> +}
> +
> +
> +static char *longs2str(int32_t *lp, int count, const char *sep)
> +{
> +    int i;
> +    char *ap, *ap0;
> +    uint64_t component_len;
> +    if (!sep) sep = ", ";
> +    component_len = 11LL + strlen(sep);
> +    ap    = av_malloc_array(count + 1, component_len);
> +    ap0   = ap;
> +    ap[0] = '\0';
> +    for (i = 0; i < count; i++) {
> +        unsigned l = snprintf(ap, component_len, "%i%s", lp[i], sep);
> +        if (l >= component_len) {
> +            av_free(ap0);
> +            return NULL;
> +        }
> +        ap += l;
> +    }
> +    ap0[strlen(ap0) - strlen(sep)] = '\0';
> +    return ap0;
> +}
> +
> +
> +static int exif_add_rational_metadata(int count, const char *name, const char *sep,
> +                                      GetByteContext *gb, int le, AVDictionary **metadata)
> +{
> +    char *ap;
> +    int i;
> +    int32_t *rp;
> +
> +    if (count >= INT_MAX / sizeof(int64_t) || count <= 0)
> +        return AVERROR_INVALIDDATA;
> +    if (bytestream2_get_bytes_left(gb) < count * sizeof(int64_t))
> +        return AVERROR_INVALIDDATA;
> +
> +    rp = av_malloc(2 * count * sizeof(int32_t));

av_malloc_array

but maybe thes functions would be simplier with bprint
(note, ignore this suggestion if its not simpler with bprint)

[...]

> +static int exif_add_metadata(int count, int type, const char *name, const char *sep,
> +                             GetByteContext *gb, int le, AVDictionary **metadata)
> +{
> +    switch(type) {
> +    case TIFF_DOUBLE   : return ff_tadd_doubles_metadata(count, name, sep, gb, le, metadata);
> +    case TIFF_SHORT    : return ff_tadd_shorts_metadata(count, name, sep, gb, le, metadata);
> +    case TIFF_BYTE:
> +    case TIFF_UNDEFINED:
> +    case TIFF_STRING   : return ff_tadd_string_metadata(count, name, gb, le, metadata);
> +    case TIFF_SRATIONAL:
> +    case TIFF_RATIONAL : return exif_add_rational_metadata(count, name, sep, gb, le, metadata);
> +    case TIFF_SLONG    :
> +    case TIFF_LONG     : return exif_add_long_metadata(count, name, sep, gb, le, metadata);
> +    default            : return AVERROR_INVALIDDATA;
> +    };
> +}

wouldnz it be cleaner to put all the tiff functions in the same
place even if some are currently only used by exif ?

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many things microsoft did are stupid, but not doing something just because
microsoft did it is even more stupid. If everything ms did were stupid they
would be bankrupt already.
-------------- 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/20130810/514d9b28/attachment.asc>


More information about the ffmpeg-devel mailing list