On Tue, Aug 19, 2025 at 06:33:03PM +0300, [email protected] wrote:
> The branch, master has been updated
>        via  4c3f94f2651ce4d6834fbef10e5c287f25720ac9 (commit)
>        via  fe496b0308f1911138698b92bbafac582fa455d7 (commit)
>        via  535a07d14e16eb2930d2b1e16605eafa95959139 (commit) <----- we are 
> here
>        via  8132ee046d1a03c5913759c50fce7beda8d3d627 (commit)
>        via  5d4f873ff31f86f9ae1927f37ca0fcb78da70512 (commit)
>        via  1e816ebefee0ef479fa76bd2a1fb9ec5d5e807df (commit)
>        via  93a8091015978c44462626409af71789080bbef4 (commit)
>        via  303f60684f25ce63951480ef0f759acf41aac938 (commit)
>        via  5caaadee7954f2014d9e0a17d1edfb961893bcf1 (commit)
>        via  d3190a64c366a79091fe47fddf93c09a7d988802 (commit)
>        via  44af3829796427b89c4b76b56652cc5932ada616 (commit)
>        via  f5ad1c910c168d05cb01315773ab0bd094c9372f (commit)
>        via  e3aa1154aab2656c91ce61915f79516d9b563b61 (commit)
>        via  c6cc2115f45ac26ae42442f8796996eb410f4028 (commit)
>        via  52dba25661305e3c4a6209d46aea43cd327c960e (commit)
>        via  bfb17d26306592c85cf0c4e909099c621177b062 (commit)
>        via  ba2ea285e0f270a0a885b414cafaace6a89b9a91 (commit)
>        via  ad77345a5d14862f4701e5ad422b03b14934a5b9 (commit)
>        via  bb90b262d6d23f1bca3587a48abc15b951cbbf05 (commit)
>        via  a99fff4e2d4058c57599ba0b968862af82bdad5b (commit)
>       from  a6b5a382dd7ecdd27c5d0ebba688e1db409d18fd (commit)


> commit 535a07d14e16eb2930d2b1e16605eafa95959139
> Author:     Leo Izen <[email protected]>
> AuthorDate: Fri Jul 25 11:56:36 2025 -0400
> Commit:     Leo Izen <[email protected]>
> CommitDate: Tue Aug 19 11:26:48 2025 -0400
> 
>     avcodec/exif: add ff_exif_sanitize_ifd
>     
>     This commit takes some of the sanitize code used by ff_exif_get_buffer
>     and exposes it as an ff_ API, so encoders who wish to modify the
>     sanitized IFD before calling av_exif_write can do so.
>     
>     Signed-off-by: Leo Izen <[email protected]>
> 
> diff --git a/libavcodec/exif.c b/libavcodec/exif.c
> index 15bbe7749b..48959eb9b3 100644
> --- a/libavcodec/exif.c
> +++ b/libavcodec/exif.c
> @@ -1307,13 +1307,10 @@ int av_exif_orientation_to_matrix(int32_t *matrix, 
> int orientation)
>      return 0;
>  }
>  
> -int ff_exif_get_buffer(void *logctx, const AVFrame *frame, AVBufferRef 
> **buffer_ptr, enum AVExifHeaderMode header_mode)
> +int ff_exif_sanitize_ifd(void *logctx, const AVFrame *frame, AVExifMetadata 
> *ifd)
>  {
>      int ret = 0;
> -    AVBufferRef *buffer = NULL;
> -    AVFrameSideData *sd_exif = NULL;
>      AVFrameSideData *sd_orient = NULL;
> -    AVExifMetadata ifd = { 0 };
>      AVExifEntry *or = NULL;
>      AVExifEntry *iw = NULL;
>      AVExifEntry *ih = NULL;
> @@ -1324,28 +1321,15 @@ int ff_exif_get_buffer(void *logctx, const AVFrame 
> *frame, AVBufferRef **buffer_
>      uint64_t h = frame->height;
>      int rewrite = 0;
>  
> -    if (!buffer_ptr || *buffer_ptr)
> -        return AVERROR(EINVAL);
> -
> -    sd_exif = av_frame_get_side_data(frame, AV_FRAME_DATA_EXIF);
>      sd_orient = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX);
>  
> -    if (!sd_exif && !sd_orient)
> -        return 0;
> -
>      if (sd_orient)
>          orientation = av_exif_matrix_to_orientation((int32_t *) 
> sd_orient->data);
>      if (orientation != 1)
>          av_log(logctx, AV_LOG_DEBUG, "matrix contains nontrivial EXIF 
> orientation: %" PRIu64 "\n", orientation);
>  
> -    if (sd_exif) {
> -        ret = av_exif_parse_buffer(logctx, sd_exif->data, sd_exif->size, 
> &ifd, AV_EXIF_TIFF_HEADER);
> -        if (ret < 0)
> -            goto end;
> -    }
> -
> -    for (size_t i = 0; i < ifd.count; i++) {
> -        AVExifEntry *entry = &ifd.entries[i];
> +    for (size_t i = 0; i < ifd->count; i++) {
> +        AVExifEntry *entry = &ifd->entries[i];
>          if (entry->id == ORIENTATION_TAG && entry->count > 0 && entry->type 
> == AV_TIFF_SHORT) {
>              or = entry;
>              continue;
> @@ -1396,26 +1380,26 @@ int ff_exif_get_buffer(void *logctx, const AVFrame 
> *frame, AVBufferRef **buffer_
>      }
>      if (!or && orientation != 1) {
>          rewrite = 1;
> -        ret = av_exif_set_entry(logctx, &ifd, ORIENTATION_TAG, 
> AV_TIFF_SHORT, 1, NULL, 0, &orientation);
> +        ret = av_exif_set_entry(logctx, ifd, ORIENTATION_TAG, AV_TIFF_SHORT, 
> 1, NULL, 0, &orientation);
>          if (ret < 0)
>              goto end;
>      }
>      if (!iw && w) {
>          rewrite = 1;
> -        ret = av_exif_set_entry(logctx, &ifd, IMAGE_WIDTH_TAG, AV_TIFF_LONG, 
> 1, NULL, 0, &w);
> +        ret = av_exif_set_entry(logctx, ifd, IMAGE_WIDTH_TAG, AV_TIFF_LONG, 
> 1, NULL, 0, &w);
>          if (ret < 0)
>              goto end;
>      }
>      if (!ih && h) {
>          rewrite = 1;
> -        ret = av_exif_set_entry(logctx, &ifd, IMAGE_LENGTH_TAG, 
> AV_TIFF_LONG, 1, NULL, 0, &h);
> +        ret = av_exif_set_entry(logctx, ifd, IMAGE_LENGTH_TAG, AV_TIFF_LONG, 
> 1, NULL, 0, &h);
>          if (ret < 0)
>              goto end;
>      }
>      if (!pw && w && w < 0xFFFFu || !ph && h && h < 0xFFFFu) {
>          AVExifMetadata *exif;
>          AVExifEntry *exif_entry;
> -        int exif_found = av_exif_get_entry(logctx, &ifd, EXIFIFD_TAG, 0, 
> &exif_entry);
> +        int exif_found = av_exif_get_entry(logctx, ifd, EXIFIFD_TAG, 0, 
> &exif_entry);
>          rewrite = 1;
>          if (exif_found < 0)
>              goto end;
> @@ -1423,12 +1407,12 @@ int ff_exif_get_buffer(void *logctx, const AVFrame 
> *frame, AVBufferRef **buffer_
>              exif = &exif_entry->value.ifd;
>          } else {
>              AVExifMetadata exif_new = { 0 };
> -            ret = av_exif_set_entry(logctx, &ifd, EXIFIFD_TAG, AV_TIFF_IFD, 
> 1, NULL, 0, &exif_new);
> +            ret = av_exif_set_entry(logctx, ifd, EXIFIFD_TAG, AV_TIFF_IFD, 
> 1, NULL, 0, &exif_new);
>              if (ret < 0) {
>                  av_exif_free(&exif_new);
>                  goto end;
>              }
> -            exif = &ifd.entries[ifd.count - 1].value.ifd;
> +            exif = &ifd->entries[ifd->count - 1].value.ifd;
>          }
>          if (!pw && w && w < 0xFFFFu) {
>              ret = av_exif_set_entry(logctx, exif, PIXEL_X_TAG, 
> AV_TIFF_SHORT, 1, NULL, 0, &w);
> @@ -1442,6 +1426,37 @@ int ff_exif_get_buffer(void *logctx, const AVFrame 
> *frame, AVBufferRef **buffer_
>          }
>      }
>  
> +    return rewrite;
> +
> +end:
> +    return ret;
> +}
> +

> +int ff_exif_get_buffer(void *logctx, const AVFrame *frame, AVBufferRef 
> **buffer_ptr, enum AVExifHeaderMode header_mode)
> +{
> +    AVFrameSideData *sd_exif = NULL;
> +    AVBufferRef *buffer = NULL;
> +    AVExifMetadata ifd = { 0 };
> +    int ret = 0;
> +    int rewrite = 0;
> +
> +    if (!buffer_ptr || *buffer_ptr)
> +        return AVERROR(EINVAL);
> +
> +    sd_exif = av_frame_get_side_data(frame, AV_FRAME_DATA_EXIF);
> +    if (!sd_exif)
> +        return 0;

ff_exif_get_buffer() now returns immediately when AV_FRAME_DATA_EXIF is absent,
so it no longer synthesizes EXIF from a display matrix alone,
even though the old code path did and the header comment still says it collects 
"other side data types" too.



> +
> +    ret = av_exif_parse_buffer(logctx, sd_exif->data, sd_exif->size, &ifd, 
> AV_EXIF_TIFF_HEADER);
> +    if (ret < 0)
> +        goto end;
> +
> +    rewrite = ff_exif_sanitize_ifd(logctx, frame, &ifd);
> +    if (rewrite < 0) {
> +        ret = rewrite;
> +        goto end;
> +    }
> +
>      if (rewrite) {
>          ret = av_exif_write(logctx, &ifd, &buffer, header_mode);
>          if (ret < 0)
> @@ -1456,6 +1471,9 @@ int ff_exif_get_buffer(void *logctx, const AVFrame 
> *frame, AVBufferRef **buffer_
>          }
>      }
>  
> +    av_exif_free(&ifd);
> +    return rewrite;

this changes the return value. Which is not documented in neither
documentation nor commit message

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato

Attachment: signature.asc
Description: PGP signature

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to