[FFmpeg-devel] [PATCH v2 4/8] avfilter/swscale: always fix interlaced chroma location
Niklas Haas
ffmpeg at haasn.xyz
Thu Jul 4 17:31:00 EEST 2024
From: Niklas Haas <git at 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
More information about the ffmpeg-devel
mailing list