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

Michael Niedermayer michaelni at gmx.at
Fri Aug 9 14:11:17 CEST 2013


On Mon, Aug 05, 2013 at 05:33:47PM +0200, Thilo Borgmann wrote:
> 2/3 rev 2
> 
> -Thilo

>  exif.c |  234 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  exif.h |  169 ++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 403 insertions(+)
> 6ce4a3c306401ddc50635605f04c94566a894c0f  0002-Add-EXIF-metadata-parser-to-libavcodec.patch
> From 1676d82b1eb7312e720f3246a10e5742f36fbe99 Mon Sep 17 00:00:00 2001
> From: Thilo Borgmann <thilo.borgmann at googlemail.com>
> Date: Mon, 5 Aug 2013 17:24:49 +0200
> Subject: [PATCH 2/3] Add EXIF metadata parser to libavcodec.
> 
> ---
>  libavcodec/exif.c |  234 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  libavcodec/exif.h |  169 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 403 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..794abdc
> --- /dev/null
> +++ b/libavcodec/exif.c
> @@ -0,0 +1,234 @@
> +/*
> + * 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);
> +    if (count >= (INT_MAX - 1)/component_len)
> +        return NULL;
> +    ap = av_malloc(component_len * count + 1);
> +    if (!ap)
> +        return NULL;

av_malloc_array()


[...]
> +static int exif_add_long_metadata(int count, const char *name, const char *sep,
> +                                  GetByteContext *gb, int le, AVDictionary **metadata)
> +{
> +    char *ap;
> +    int i;
> +    int32_t *lp;
> +
> +    if (count >= INT_MAX / sizeof(int32_t) || count <= 0)
> +        return AVERROR_INVALIDDATA;
> +    if (bytestream2_get_bytes_left(gb) < count * sizeof(int32_t))
> +        return AVERROR_INVALIDDATA;
> +
> +    lp = av_malloc(count * sizeof(int32_t));
> +    if (!lp)
> +        return AVERROR(ENOMEM);
> +
> +    for (i = 0; i < count; i++) {
> +        lp[i] = ff_tget_long(gb, le);
> +    }
> +    ap = longs2str(lp, count, sep);
> +    av_freep(&lp);
> +    if (!ap)
> +        return AVERROR(ENOMEM);
> +    av_dict_set(metadata, name, ap, AV_DICT_DONT_STRDUP_VAL);
> +    return 0;
> +}
> +
> +
> +
> +static const char *exif_get_tag_name(uint16_t id)
> +{

> +    for (int i = 0; i < EXIF_TAGS; i++) {

int i; outside is more compatible with ancient compilers
FF_ARRAY_ELEMS coudl be used to avoid EXIF_TAGS and haing to update
it when more tags are added

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes
-------------- 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/20130809/1af3b79f/attachment.asc>


More information about the ffmpeg-devel mailing list