[FFmpeg-cvslog] [ffmpeg] branch master updated. e29a99a975 fftools/ffmpeg_enc: don't ignore user selected chroma location

ffmpeg-git at ffmpeg.org ffmpeg-git at ffmpeg.org
Mon Aug 11 10:53:13 EEST 2025


The branch, master has been updated
       via  e29a99a975b722463c19d53f67e32f12f6dfe445 (commit)
      from  3bf8bf965fb69f873e52d34a85d1ecb722a9fe7f (commit)


- Log -----------------------------------------------------------------
commit e29a99a975b722463c19d53f67e32f12f6dfe445
Author:     Niklas Haas <git at haasn.dev>
AuthorDate: Wed Jul 23 15:09:01 2025 +0200
Commit:     Niklas Haas <git at haasn.dev>
CommitDate: Mon Aug 11 09:38:38 2025 +0200

    fftools/ffmpeg_enc: don't ignore user selected chroma location
    
    This code always ignored the user-provided enc_ctx->chroma_sample_location
    in favor of the location tagged on the frame. This leads to a very (IMHO)
    unexpected outcome where -chroma_sample_location works differently from the
    related options like -colorspace and -color_range, the latter of which
    override the frame properties as a consequence of being configured on the
    filter graph output.
    
    The discrepancy comes from the fact that the chroma sample location does not
    itself participate in filter graph negotiation.
    
    Solve the situation by only overriding the enc_ctx option if it was left
    unspecified by the user, and otherwise printing a warning if the requested
    parameter does not match the frame parameter.

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index a46af4dce1..4568c15073 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -266,11 +266,26 @@ int enc_open(void *opaque, const AVFrame *frame)
             enc_ctx->bits_per_raw_sample = FFMIN(fd->bits_per_raw_sample,
                                                  av_pix_fmt_desc_get(enc_ctx->pix_fmt)->comp[0].depth);
 
+        /**
+         * The video color properties should always be in sync with the user-
+         * requested values, since we forward them to the filter graph.
+         */
         enc_ctx->color_range            = frame->color_range;
         enc_ctx->color_primaries        = frame->color_primaries;
         enc_ctx->color_trc              = frame->color_trc;
         enc_ctx->colorspace             = frame->colorspace;
-        enc_ctx->chroma_sample_location = frame->chroma_location;
+
+        /* Video properties which are not part of filter graph negotiation */
+        if (enc_ctx->chroma_sample_location == AVCHROMA_LOC_UNSPECIFIED) {
+            enc_ctx->chroma_sample_location = frame->chroma_location;
+        } else if (enc_ctx->chroma_sample_location != frame->chroma_location &&
+                   frame->chroma_location != AVCHROMA_LOC_UNSPECIFIED) {
+            av_log(e, AV_LOG_WARNING,
+                   "Requested chroma sample location '%s' does not match the "
+                   "frame tagged sample location '%s'; result may be incorrect.\n",
+                   av_chroma_location_name(enc_ctx->chroma_sample_location),
+                   av_chroma_location_name(frame->chroma_location));
+        }
 
         if (enc_ctx->flags & (AV_CODEC_FLAG_INTERLACED_DCT | AV_CODEC_FLAG_INTERLACED_ME) ||
             (frame->flags & AV_FRAME_FLAG_INTERLACED)

-----------------------------------------------------------------------

Summary of changes:
 fftools/ffmpeg_enc.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)


hooks/post-receive
-- 



More information about the ffmpeg-cvslog mailing list