From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 2BBAE4BBBA for ; Wed, 23 Jul 2025 13:58:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 4B27F68D96C; Wed, 23 Jul 2025 16:56:58 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 5B33B68D8AF for ; Wed, 23 Jul 2025 16:56:33 +0300 (EEST) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with UTF8SMTP id 09FB4483E8; Wed, 23 Jul 2025 15:56:29 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Jul 2025 15:47:15 +0200 Message-ID: <20250723135626.1390296-13-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250723135626.1390296-1-ffmpeg@haasn.xyz> References: <20250723135626.1390296-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 12/18] fftools/ffmpeg_enc: don't ignore user selected chroma location X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas 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. --- fftools/ffmpeg_enc.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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) -- 2.50.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".