avfilter/vf_aspect: change outlink sample aspect ratio instead of inlink

Signed-off-by: Paul B Mahol <onemda@gmail.com>
pull/274/head
Paul B Mahol 7 years ago
parent 4754d70a23
commit f6608f4725
  1. 30
      libavfilter/vf_aspect.c

@ -125,9 +125,11 @@ static int get_aspect_ratio(AVFilterLink *inlink, AVRational *aspect_ratio)
#if CONFIG_SETDAR_FILTER #if CONFIG_SETDAR_FILTER
static int setdar_config_props(AVFilterLink *inlink) static int setdar_config_props(AVFilterLink *outlink)
{ {
AspectContext *s = inlink->dst->priv; AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = ctx->inputs[0];
AspectContext *s = ctx->priv;
AVRational dar; AVRational dar;
AVRational old_dar; AVRational old_dar;
AVRational old_sar = inlink->sample_aspect_ratio; AVRational old_sar = inlink->sample_aspect_ratio;
@ -140,17 +142,17 @@ static int setdar_config_props(AVFilterLink *inlink)
av_reduce(&s->sar.num, &s->sar.den, av_reduce(&s->sar.num, &s->sar.den,
s->dar.num * inlink->h, s->dar.num * inlink->h,
s->dar.den * inlink->w, INT_MAX); s->dar.den * inlink->w, INT_MAX);
inlink->sample_aspect_ratio = s->sar; outlink->sample_aspect_ratio = s->sar;
dar = s->dar; dar = s->dar;
} else { } else {
inlink->sample_aspect_ratio = (AVRational){ 1, 1 }; outlink->sample_aspect_ratio = (AVRational){ 1, 1 };
dar = (AVRational){ inlink->w, inlink->h }; dar = (AVRational){ inlink->w, inlink->h };
} }
compute_dar(&old_dar, old_sar, inlink->w, inlink->h); compute_dar(&old_dar, old_sar, inlink->w, inlink->h);
av_log(inlink->dst, AV_LOG_VERBOSE, "w:%d h:%d dar:%d/%d sar:%d/%d -> dar:%d/%d sar:%d/%d\n", av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d dar:%d/%d sar:%d/%d -> dar:%d/%d sar:%d/%d\n",
inlink->w, inlink->h, old_dar.num, old_dar.den, old_sar.num, old_sar.den, inlink->w, inlink->h, old_dar.num, old_dar.den, old_sar.num, old_sar.den,
dar.num, dar.den, inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den); dar.num, dar.den, outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den);
return 0; return 0;
} }
@ -169,7 +171,6 @@ static const AVFilterPad avfilter_vf_setdar_inputs[] = {
{ {
.name = "default", .name = "default",
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.config_props = setdar_config_props,
.filter_frame = filter_frame, .filter_frame = filter_frame,
}, },
{ NULL } { NULL }
@ -179,6 +180,7 @@ static const AVFilterPad avfilter_vf_setdar_outputs[] = {
{ {
.name = "default", .name = "default",
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.config_props = setdar_config_props,
}, },
{ NULL } { NULL }
}; };
@ -196,9 +198,11 @@ AVFilter ff_vf_setdar = {
#if CONFIG_SETSAR_FILTER #if CONFIG_SETSAR_FILTER
static int setsar_config_props(AVFilterLink *inlink) static int setsar_config_props(AVFilterLink *outlink)
{ {
AspectContext *s = inlink->dst->priv; AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = ctx->inputs[0];
AspectContext *s = ctx->priv;
AVRational old_sar = inlink->sample_aspect_ratio; AVRational old_sar = inlink->sample_aspect_ratio;
AVRational old_dar, dar; AVRational old_dar, dar;
int ret; int ret;
@ -206,13 +210,13 @@ static int setsar_config_props(AVFilterLink *inlink)
if ((ret = get_aspect_ratio(inlink, &s->sar))) if ((ret = get_aspect_ratio(inlink, &s->sar)))
return ret; return ret;
inlink->sample_aspect_ratio = s->sar; outlink->sample_aspect_ratio = s->sar;
compute_dar(&old_dar, old_sar, inlink->w, inlink->h); compute_dar(&old_dar, old_sar, inlink->w, inlink->h);
compute_dar(&dar, s->sar, inlink->w, inlink->h); compute_dar(&dar, s->sar, inlink->w, inlink->h);
av_log(inlink->dst, AV_LOG_VERBOSE, "w:%d h:%d sar:%d/%d dar:%d/%d -> sar:%d/%d dar:%d/%d\n", av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d sar:%d/%d dar:%d/%d -> sar:%d/%d dar:%d/%d\n",
inlink->w, inlink->h, old_sar.num, old_sar.den, old_dar.num, old_dar.den, inlink->w, inlink->h, old_sar.num, old_sar.den, old_dar.num, old_dar.den,
inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den, dar.num, dar.den); outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den, dar.num, dar.den);
return 0; return 0;
} }
@ -231,7 +235,6 @@ static const AVFilterPad avfilter_vf_setsar_inputs[] = {
{ {
.name = "default", .name = "default",
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.config_props = setsar_config_props,
.filter_frame = filter_frame, .filter_frame = filter_frame,
}, },
{ NULL } { NULL }
@ -241,6 +244,7 @@ static const AVFilterPad avfilter_vf_setsar_outputs[] = {
{ {
.name = "default", .name = "default",
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.config_props = setsar_config_props,
}, },
{ NULL } { NULL }
}; };

Loading…
Cancel
Save