You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avfilter/vf_libplacebo: correctly update SAR to reflect scaled result
This aligns the behavior of vf_libplacebo with other filters in the vf_scale family, that forward any change in the SAR as a result of changing the output resolution to the output frame / link, and updates the ff_scale_adjust_dimensions() call to continue working as intended. The new behavior reflects the documentation of vf_libplacebo, which described this behavior despite that not being the way the filter worked up to this point. As an aside, also fixes a bug where the AVFrame SAR was inconsistent with the AVFilterLink SAR when the s->nb_inputs > 1 condition was met.
This commit is contained in:
@ -186,6 +186,7 @@ typedef struct LibplaceboContext {
|
|||||||
float corner_rounding;
|
float corner_rounding;
|
||||||
int force_original_aspect_ratio;
|
int force_original_aspect_ratio;
|
||||||
int force_divisible_by;
|
int force_divisible_by;
|
||||||
|
int reset_sar;
|
||||||
int normalize_sar;
|
int normalize_sar;
|
||||||
int apply_filmgrain;
|
int apply_filmgrain;
|
||||||
int apply_dovi;
|
int apply_dovi;
|
||||||
@ -929,6 +930,15 @@ static int output_frame(AVFilterContext *ctx, int64_t pts)
|
|||||||
if (s->apply_filmgrain)
|
if (s->apply_filmgrain)
|
||||||
av_frame_remove_side_data(out, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
|
av_frame_remove_side_data(out, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
|
||||||
|
|
||||||
|
if (s->reset_sar) {
|
||||||
|
out->sample_aspect_ratio = ref->sample_aspect_ratio;
|
||||||
|
} else {
|
||||||
|
const AVRational ar_ref = { ref->width, ref->height };
|
||||||
|
const AVRational ar_out = { out->width, out->height };
|
||||||
|
const AVRational stretch = av_div_q(ar_ref, ar_out);
|
||||||
|
out->sample_aspect_ratio = av_mul_q(ref->sample_aspect_ratio, stretch);
|
||||||
|
}
|
||||||
|
|
||||||
/* Map, render and unmap output frame */
|
/* Map, render and unmap output frame */
|
||||||
if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
|
if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
|
||||||
ok = pl_map_avframe_ex(s->gpu, &target, pl_avframe_params(
|
ok = pl_map_avframe_ex(s->gpu, &target, pl_avframe_params(
|
||||||
@ -1288,18 +1298,27 @@ static int libplacebo_config_output(AVFilterLink *outlink)
|
|||||||
RET(ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
|
RET(ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
|
||||||
&outlink->w, &outlink->h));
|
&outlink->w, &outlink->h));
|
||||||
|
|
||||||
|
s->reset_sar = s->normalize_sar || s->nb_inputs > 1;
|
||||||
|
double sar_in = inlink->sample_aspect_ratio.num ?
|
||||||
|
av_q2d(inlink->sample_aspect_ratio) : 1.0;
|
||||||
|
|
||||||
ff_scale_adjust_dimensions(inlink, &outlink->w, &outlink->h,
|
ff_scale_adjust_dimensions(inlink, &outlink->w, &outlink->h,
|
||||||
s->force_original_aspect_ratio,
|
s->force_original_aspect_ratio,
|
||||||
s->force_divisible_by, 1.f);
|
s->force_divisible_by,
|
||||||
|
s->reset_sar ? sar_in : 1.0);
|
||||||
|
|
||||||
if (s->normalize_sar || s->nb_inputs > 1) {
|
if (s->reset_sar) {
|
||||||
/* SAR is normalized, or we have multiple inputs, set out to 1:1 */
|
/* SAR is normalized, or we have multiple inputs, set out to 1:1 */
|
||||||
outlink->sample_aspect_ratio = (AVRational){ 1, 1 };
|
outlink->sample_aspect_ratio = (AVRational){ 1, 1 };
|
||||||
} else {
|
} else if (inlink->sample_aspect_ratio.num) {
|
||||||
/* This is consistent with other scale_* filters, which only
|
/* This is consistent with other scale_* filters, which only
|
||||||
* set the outlink SAR to be equal to the scale SAR iff the input SAR
|
* set the outlink SAR to be equal to the scale SAR iff the input SAR
|
||||||
* was set to something nonzero */
|
* was set to something nonzero */
|
||||||
if (inlink->sample_aspect_ratio.num)
|
const AVRational ar_in = { inlink->w, inlink->h };
|
||||||
|
const AVRational ar_out = { outlink->w, outlink->h };
|
||||||
|
const AVRational stretch = av_div_q(ar_in, ar_out);
|
||||||
|
outlink->sample_aspect_ratio = av_mul_q(inlink->sample_aspect_ratio, stretch);
|
||||||
|
} else {
|
||||||
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
|
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user