[FFmpeg-devel] [PATCH 3/3] avcodec/pngenc: write eXIf chunks

Leo Izen leo.izen at gmail.com
Thu Feb 15 10:19:00 EET 2024


On 2/14/24 13:53, Andreas Rheinhardt wrote:
> Leo Izen:
>> Write EXIF metadata exposed AV_FRAME_DATA_EXIF as an eXIf chunk
>> to PNG files, if present.
>>
>> Signed-off-by: Leo Izen <leo.izen at gmail.com>
>> ---
>>   libavcodec/pngenc.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
>> index 50689cb50c..a302c879da 100644
>> --- a/libavcodec/pngenc.c
>> +++ b/libavcodec/pngenc.c
>> @@ -413,6 +413,10 @@ static int encode_headers(AVCodecContext *avctx, const AVFrame *pict)
>>           }
>>       }
>>   
>> +    side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_EXIF);
>> +    if (side_data)
>> +        png_write_chunk(&s->bytestream, MKTAG('e', 'X', 'I', 'f'), side_data->data, FFMIN(side_data->size, INT_MAX));
>> +
>>       side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE);
>>       if ((ret = png_write_iccp(s, side_data)))
>>           return ret;
> 
> If I see this correctly, then these patches can lead to a situation
> where an input packet has rotation metadata in exif which gets exported
> twice -- as displaymatrix and as exif metadata side data. If the user
> changes the displaymatrix (e.g. applies the transformation to the image
> data and removes the displaymatrix side data before reencoding), the
> exif data (that the user would probably not be aware of) would still be
> there and get propagated into the output, corrupting it.
> 

Hm. This is true, but it's also currently how the mjpeg decoder 
functions (i.e. it attaches displaymatrix side data).

There are no encoders that currently save EXIF metadata, so there's no 
precedent.

How do you suggest this be reconciled?

- Leo Izen (Traneptora)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20240215/c6ad4821/attachment.sig>


More information about the ffmpeg-devel mailing list