FFmpeg
exif_internal.h
Go to the documentation of this file.
1 /*
2  * EXIF metadata parser - internal functions
3  * Copyright (c) 2013 Thilo Borgmann <thilo.borgmann _at_ mail.de>
4  * Copyright (c) 2024-2025 Leo Izen <leo.izen@gmail.com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * EXIF metadata parser - internal functions
26  * @author Thilo Borgmann <thilo.borgmann _at_ mail.de>
27  * @author Leo Izen <leo.izen@gmail.com>
28  */
29 
30 #ifndef AVCODEC_EXIF_INTERNAL_H
31 #define AVCODEC_EXIF_INTERNAL_H
32 
33 #include "libavutil/buffer.h"
34 #include "libavutil/frame.h"
35 
36 #include "exif.h"
37 
38 /**
39  * Compares values in the IFD with data in the provided AVFrame and sets the values
40  * in that IFD to match the ones in that AVFrame. This is mostly useful for an
41  * encoder that wishes to use ff_exif_get_buffer, but would prefer to modify the
42  * IFD after it is sanitized and call av_exif_write afterward.
43  */
44 int ff_exif_sanitize_ifd(void *logctx, const AVFrame *frame, AVExifMetadata *ifd);
45 
46 /**
47  * Gets all relevant side data, collects it into an IFD, and writes it into the
48  * corresponding buffer pointer. This includes both AV_FRAME_DATA_EXIF and other
49  * side data types that are included in the frame data, such as possibly an
50  * instance of AV_FRAME_DATA_DISPLAYMATRIX. It also sets width and height tags
51  * to match those of the AVFrame if they are different.
52  * The *buffer argument must be NULL before calling.
53  *
54  * On success, a positive number is returned, and the buffer becomes owned by the caller.
55  * A negative AVERROR return value means that an error occurred.
56  * A zero return value means that there was no EXIF data to write.
57  * In both the negative and zero cases, *buffer will be NULL.
58  */
59 int ff_exif_get_buffer(void *logctx, const AVFrame *frame, AVBufferRef **buffer, enum AVExifHeaderMode header_mode);
60 
61 struct AVCodecContext;
62 /**
63  * Attach the data buffer to the frame. This is mostly a wrapper for
64  * av_side_data_new_from_buffer, but it checks if the orientation tag is
65  * present in the provided EXIF buffer. If it is, it zeroes it out and
66  * attaches that information as an AV_FRAME_DATA_DISPLAYMATRIX instead
67  * of including it in the AV_FRAME_DATA_EXIF side data buffer.
68  *
69  * *buf is ALWAYS consumed by this function and NULL written in its place, even
70  * on failure.
71  */
73  enum AVExifHeaderMode header_mode);
74 
75 /**
76  * Attach an already-parsed EXIF metadata struct to the frame as a side data
77  * buffer. It writes the EXIF IFD into the buffer and attaches the buffer to
78  * the frame.
79  *
80  * If the metadata struct contains an orientation tag, it will be zeroed before
81  * writing, and instead, an AV_FRAME_DATA_DISPLAYMATRIX will be attached in
82  * addition to the AV_FRAME_DATA_EXIF side data.
83  */
85  const struct AVExifMetadata *ifd);
86 
87 #endif /* AVCODEC_EXIF_INTERNAL_H */
ff_decode_exif_attach_buffer
int ff_decode_exif_attach_buffer(struct AVCodecContext *avctx, AVFrame *frame, AVBufferRef **buf, enum AVExifHeaderMode header_mode)
Attach the data buffer to the frame.
Definition: decode.c:2492
AVExifMetadata
Definition: exif.h:75
AVExifHeaderMode
AVExifHeaderMode
Definition: exif.h:57
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
ff_exif_sanitize_ifd
int ff_exif_sanitize_ifd(void *logctx, const AVFrame *frame, AVExifMetadata *ifd)
Compares values in the IFD with data in the provided AVFrame and sets the values in that IFD to match...
Definition: exif.c:1364
ff_decode_exif_attach_ifd
int ff_decode_exif_attach_ifd(struct AVCodecContext *avctx, AVFrame *frame, const struct AVExifMetadata *ifd)
Attach an already-parsed EXIF metadata struct to the frame as a side data buffer.
frame.h
buffer.h
exif.h
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
AVCodecContext
main external API structure.
Definition: avcodec.h:443
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
ff_exif_get_buffer
int ff_exif_get_buffer(void *logctx, const AVFrame *frame, AVBufferRef **buffer, enum AVExifHeaderMode header_mode)
Gets all relevant side data, collects it into an IFD, and writes it into the corresponding buffer poi...
Definition: exif.c:1493