This logic only covers the case of yuv420p. Extend this logic to cover *all* vertically subsampled YUV formats, which require the same interlaced scaling logic. Fortunately, we can get away with re-using the same code for both JPEG and MPEG range YUV, because the only difference here is the horizontal alignment. (Which I omit touching for now, to avoid introducing possibly unintended changes in default behavior)
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -518,6 +518,7 @@ static int config_props(AVFilterLink *outlink) · 517 unmodified lines | ||
| 518 | 518 | outlink->src->inputs[0]; |
| 519 | 519 | enum AVPixelFormat outfmt = outlink->format; |
| 520 | 520 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
| 521 | + const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outfmt); | |
| 521 | 522 | ScaleContext *scale = ctx->priv; |
| 522 | 523 | uint8_t *flags_val = NULL; |
| 523 | 524 | int ret; |
| @@ -588,14 +589,15 @@ static int config_props(AVFilterLink *outlink) · 64 unmodified lines | ||
| 588 | 589 | av_opt_set_int(s, "dst_range", |
| 589 | 590 | scale->out_range == AVCOL_RANGE_JPEG, 0); |
| 590 | 591 | |
| 591 | − /* Override YUV420P default settings to have the correct (MPEG-2) chroma positions | |
| 592 | − * MPEG-2 chroma positions are used by convention | |
| 593 | − * XXX: support other 4:2:0 pixel formats */ | |
| 594 | − if (inlink0->format == AV_PIX_FMT_YUV420P && scale->in_v_chr_pos == -513) { | |
| 592 | + /* Override chroma location default settings to have the correct | |
| 593 | + * chroma positions. MPEG chroma positions are used by convention. | |
| 594 | + * Note that this works for both MPEG-1/JPEG and MPEG-2/4 chroma | |
| 595 | + * locations, since they share a vertical alignment */ | |
| 596 | + if (desc->log2_chroma_h == 1 && scale->in_v_chr_pos == -513) { | |
| 595 | 597 | in_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; |
| 596 | 598 | } |
| 597 | 599 | |
| 598 | − if (outlink->format == AV_PIX_FMT_YUV420P && scale->out_v_chr_pos == -513) { | |
| 600 | + if (outdesc->log2_chroma_h == 1 && scale->out_v_chr_pos == -513) { | |
| 599 | 601 | out_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; |
| 600 | 602 | } |
| 601 | 603 | |