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

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Feb 14 20:53:22 EET 2024


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.

- Andreas



More information about the ffmpeg-devel mailing list