Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH 3/6] avfilter/swscale: always fix interlaced chroma location
Date: Thu,  4 Jul 2024 13:51:59 +0200
Message-ID: <20240704115202.1235954-3-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20240704115202.1235954-1-ffmpeg@haasn.xyz>

From: Niklas Haas <git@haasn.dev>

The current logic only fixes it when the user does not explicitly
specify the chroma location. However, this does not make a lot of sense.
Since there is no way to specify this property per-field, it effectively
*prevents* the user from being able to correctly scale interlaced frames
with top-aligned chroma.

It makes more sense to consider the user setting in the progressive case
only, and automatically adapt it to the correct interlaced field
positions, following the details of the MPEG specification.
---
 libavfilter/vf_scale.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 841075193e..0b6701673f 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -709,12 +709,18 @@ static int config_props(AVFilterLink *outlink)
              * chroma positions. MPEG chroma positions are used by convention.
              * Note that this works for both MPEG-1/JPEG and MPEG-2/4 chroma
              * locations, since they share a vertical alignment */
-            if (desc->log2_chroma_h == 1 && scale->in_v_chr_pos == -513) {
-                in_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192;
+            if (desc->log2_chroma_h == 1) {
+                if (in_v_chr_pos == -513)
+                    in_v_chr_pos = 128; /* explicitly default missing info */
+                in_v_chr_pos += 256 * (i == 2); /* offset by one luma row for odd rows */
+                in_v_chr_pos >>= i > 0; /* double luma row distance */
             }
 
-            if (outdesc->log2_chroma_h == 1 && scale->out_v_chr_pos == -513) {
-                out_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192;
+            if (outdesc->log2_chroma_h == 1) {
+                if (out_v_chr_pos == -513)
+                    out_v_chr_pos = 128;
+                out_v_chr_pos += 256 * (i == 2);
+                out_v_chr_pos >>= i > 0;
             }
 
             av_opt_set_int(s, "src_h_chr_pos", scale->in_h_chr_pos, 0);
-- 
2.45.2

_______________________________________________
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".

  parent reply	other threads:[~2024-07-04 11:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-04 11:51 [FFmpeg-devel] [PATCH 1/6] swscale: document SWS_FULL_CHR_H_* flags Niklas Haas
2024-07-04 11:51 ` [FFmpeg-devel] [PATCH 2/6] avfilter/vf_setparams: allow setting chroma location Niklas Haas
2024-07-04 15:09   ` Paul B Mahol
2024-07-04 11:51 ` Niklas Haas [this message]
2024-07-04 11:52 ` [FFmpeg-devel] [PATCH 4/6] avfilter/vf_scale: add in/out_chroma_loc Niklas Haas
2024-07-04 12:52   ` Niklas Haas
2024-07-04 11:52 ` [FFmpeg-devel] [PATCH 5/6] avfilter/vf_zscale: remove unused fields Niklas Haas
2024-07-04 11:52 ` [FFmpeg-devel] [PATCH 6/6] fate/scalechroma: switch to standard chroma location Niklas Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240704115202.1235954-3-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git