[FFmpeg-devel] [Read EXIF metadata 2/3] Add EXIF metadata parser to libavcodec.
Thilo Borgmann
thilo.borgmann at mail.de
Mon Aug 12 19:28:34 CEST 2013
Am 12.08.13 18:56, schrieb Thilo Borgmann:
> Am 12.08.13 18:03, schrieb Michael Niedermayer:
>> On Mon, Aug 12, 2013 at 05:26:08PM +0200, Thilo Borgmann wrote:
>>> 2/3 rev 8
>>>
>>> -Thilo
>>
>>> exif.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++
>>> exif.h | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>> 2 files changed, 298 insertions(+)
>>> c1043583606bf4275ab73da2db24215d530de13e 0002-Add-EXIF-metadata-parser-to-libavcodec.patch
>>> From 2e8f9c027f126815976a9605a3d007ed19ae26fa Mon Sep 17 00:00:00 2001
>>> From: Thilo Borgmann <thilo.borgmann at googlemail.com>
>>> Date: Mon, 12 Aug 2013 17:16:43 +0200
>>> Subject: [PATCH 2/3] Add EXIF metadata parser to libavcodec.
>>>
>>> ---
>>> libavcodec/exif.c | 129 +++++++++++++++++++++++++++++++++++++++++
>>> libavcodec/exif.h | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>> 2 files changed, 298 insertions(+)
>>> 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..27f4260
>>> --- /dev/null
>>> +++ b/libavcodec/exif.c
>>> @@ -0,0 +1,129 @@
>>> +/*
>>> + * 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 const char *exif_get_tag_name(uint16_t id)
>>> +{
>>> + int i;
>>> +
>>> + for (i = 0; i < FF_ARRAY_ELEMS(tag_list); i++) {
>>> + if (tag_list[i].id == id)
>>> + return tag_list[i].name;
>>> + }
>>> +
>>> + return NULL;
>>> +}
>>> +
>>> +
>>> +static int exif_add_metadata(AVCodecContext *avctx, 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 ff_tadd_rational_metadata(count, name, sep, gb, le, metadata);
>>> + case TIFF_SLONG :
>>> + case TIFF_LONG : return ff_tadd_long_metadata(count, name, sep, gb, le, metadata);
>>> + default:
>>> + avpriv_request_sample(avctx, "TIFF tag type (%u)", type);
>>> + return 0;
>>> + };
>>> +}
>>> +
>>> +
>>
>>> +static int exif_decode_tag(AVCodecContext *avctx, GetByteContext *gbytes, int le,
>>> + unsigned *child_ifds, AVDictionary **metadata)
>>> +{
>>> + int ret, cur_pos;
>>> + unsigned id, count;
>>> + enum TiffTypes type;
>>> +
>>> + ff_tread_tag(gbytes, le, &id, &type, &count, &cur_pos);
>>> +
>>> + // read count values and add it metadata
>>> + // store metadata or proceed with next IFD
>>> + ret = ff_tis_ifd(id);
>>> + if (ret) {
>>> + if (!child_ifds[ret - 1]) {
>>> + child_ifds[ret - 1] = 1;
>>> + ret = ff_exif_decode_ifd(avctx, gbytes, le, child_ifds, metadata);
>>> + }
>
>> i think its simpler to check the recursion depth and would then also
>> be able to handle duplicate tags
>
> I understand how a recursion depth could stop endless recursion but not how that
> would prevent reading duplicated IFDs?
well ok, it would prevent it not knowing what is going on....
-Thilo
More information about the ffmpeg-devel
mailing list