static int config_props_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; TransContext *trans = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[outlink->format]; trans->hsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_w; trans->vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h; av_image_fill_max_pixsteps(trans->pixsteps, NULL, pixdesc); outlink->w = inlink->h; outlink->h = inlink->w; if (inlink->sample_aspect_ratio.num){ outlink->sample_aspect_ratio = av_div_q((AVRational){1,1}, inlink->sample_aspect_ratio); } else outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; av_log(ctx, AV_LOG_INFO, "w:%d h:%d dir:%d -> w:%d h:%d rotation:%s vflip:%d\n", inlink->w, inlink->h, trans->dir, outlink->w, outlink->h, trans->dir == 1 || trans->dir == 3 ? "clockwise" : "counterclockwise", trans->dir == 0 || trans->dir == 3); return 0; }
static int config_props(AVFilterLink *inlink) { FlipContext *s = inlink->dst->priv; const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); s->hsub = pix_desc->log2_chroma_w; s->vsub = pix_desc->log2_chroma_h; return 0; }
static int config_input_main(AVFilterLink *inlink) { OverlayContext *over = inlink->dst->priv; const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format]; av_image_fill_max_pixsteps(over->max_plane_step, NULL, pix_desc); over->hsub = pix_desc->log2_chroma_w; over->vsub = pix_desc->log2_chroma_h; return 0; }
static int config_props_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; TransContext *trans = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; const AVPixFmtDescriptor *desc_out = av_pix_fmt_desc_get(outlink->format); const AVPixFmtDescriptor *desc_in = av_pix_fmt_desc_get(inlink->format); if (trans->dir&4) { av_log(ctx, AV_LOG_WARNING, "dir values greater than 3 are deprecated, use the passthrough option instead\n"); trans->dir &= 3; trans->passthrough = TRANSPOSE_PT_TYPE_LANDSCAPE; } if ((inlink->w >= inlink->h && trans->passthrough == TRANSPOSE_PT_TYPE_LANDSCAPE) || (inlink->w <= inlink->h && trans->passthrough == TRANSPOSE_PT_TYPE_PORTRAIT)) { av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d (passthrough mode)\n", inlink->w, inlink->h, inlink->w, inlink->h); return 0; } else { trans->passthrough = TRANSPOSE_PT_TYPE_NONE; } trans->hsub = desc_in->log2_chroma_w; trans->vsub = desc_in->log2_chroma_h; av_image_fill_max_pixsteps(trans->pixsteps, NULL, desc_out); outlink->w = inlink->h; outlink->h = inlink->w; if (inlink->sample_aspect_ratio.num) { #ifdef IDE_COMPILE AVRational tmp; tmp.num = 1; tmp.den = 1; outlink->sample_aspect_ratio = av_div_q(tmp, inlink->sample_aspect_ratio); #else outlink->sample_aspect_ratio = av_div_q((AVRational) { 1, 1 }, inlink->sample_aspect_ratio); #endif } else outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d dir:%d -> w:%d h:%d rotation:%s vflip:%d\n", inlink->w, inlink->h, trans->dir, outlink->w, outlink->h, trans->dir == 1 || trans->dir == 3 ? "clockwise" : "counterclockwise", trans->dir == 0 || trans->dir == 3); return 0; }
static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; CropDetectContext *cd = ctx->priv; av_image_fill_max_pixsteps(cd->max_pixsteps, NULL, &av_pix_fmt_descriptors[inlink->format]); cd->x1 = inlink->w - 1; cd->y1 = inlink->h - 1; cd->x2 = 0; cd->y2 = 0; return 0; }
static int config_props(AVFilterLink *inlink) { FlipContext *s = inlink->dst->priv; const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); const int hsub = pix_desc->log2_chroma_w; const int vsub = pix_desc->log2_chroma_h; av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); s->planewidth[0] = s->planewidth[3] = inlink->w; s->planewidth[1] = s->planewidth[2] = FF_CEIL_RSHIFT(inlink->w, hsub); s->planeheight[0] = s->planeheight[3] = inlink->h; s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, vsub); return 0; }
static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; CropDetectContext *s = ctx->priv; av_image_fill_max_pixsteps(s->max_pixsteps, NULL, av_pix_fmt_desc_get(inlink->format)); s->x1 = inlink->w - 1; s->y1 = inlink->h - 1; s->x2 = 0; s->y2 = 0; return 0; }
static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; CropDetectContext *s = ctx->priv; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); av_image_fill_max_pixsteps(s->max_pixsteps, NULL, desc); if (s->limit < 1.0) s->limit *= (1 << (desc->comp[0].depth_minus1 + 1)) - 1; s->x1 = inlink->w - 1; s->y1 = inlink->h - 1; s->x2 = 0; s->y2 = 0; return 0; }
static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; SwapRectContext *s = ctx->priv; if (!s->w || !s->h || !s->x1 || !s->y1 || !s->x2 || !s->y2) return AVERROR(EINVAL); s->desc = av_pix_fmt_desc_get(inlink->format); av_image_fill_max_pixsteps(s->pixsteps, NULL, s->desc); s->nb_planes = av_pix_fmt_count_planes(inlink->format); s->temp = av_malloc_array(inlink->w, s->pixsteps[0]); if (!s->temp) return AVERROR(ENOMEM); return 0; }
static int config_input(AVFilterLink *link) { AVFilterContext *ctx = link->dst; CropContext *crop = ctx->priv; const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[link->format]; int ret; const char *expr; double res; crop->var_values[VAR_IN_W] = crop->var_values[VAR_IW] = ctx->inputs[0]->w; crop->var_values[VAR_IN_H] = crop->var_values[VAR_IH] = ctx->inputs[0]->h; crop->var_values[VAR_A] = (float) link->w / link->h; crop->var_values[VAR_SAR] = link->sample_aspect_ratio.num ? av_q2d(link->sample_aspect_ratio) : 1; crop->var_values[VAR_DAR] = crop->var_values[VAR_A] * crop->var_values[VAR_SAR]; crop->var_values[VAR_HSUB] = 1<<pix_desc->log2_chroma_w; crop->var_values[VAR_VSUB] = 1<<pix_desc->log2_chroma_h; crop->var_values[VAR_X] = NAN; crop->var_values[VAR_Y] = NAN; crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = NAN; crop->var_values[VAR_OUT_H] = crop->var_values[VAR_OH] = NAN; crop->var_values[VAR_N] = 0; crop->var_values[VAR_T] = NAN; crop->var_values[VAR_POS] = NAN; av_image_fill_max_pixsteps(crop->max_step, NULL, pix_desc); crop->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w; crop->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h; if ((ret = av_expr_parse_and_eval(&res, (expr = crop->ow_expr), var_names, crop->var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr; crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = crop->oh_expr), var_names, crop->var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr; crop->var_values[VAR_OUT_H] = crop->var_values[VAR_OH] = res; /* evaluate again ow as it may depend on oh */ if ((ret = av_expr_parse_and_eval(&res, (expr = crop->ow_expr), var_names, crop->var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr; crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = res; if (normalize_double(&crop->w, crop->var_values[VAR_OUT_W]) < 0 || normalize_double(&crop->h, crop->var_values[VAR_OUT_H]) < 0) { av_log(ctx, AV_LOG_ERROR, "Too big value or invalid expression for out_w/ow or out_h/oh. " "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n", crop->ow_expr, crop->oh_expr); return AVERROR(EINVAL); } crop->w &= ~((1 << crop->hsub) - 1); crop->h &= ~((1 << crop->vsub) - 1); if ((ret = av_expr_parse(&crop->x_pexpr, crop->x_expr, var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0 || (ret = av_expr_parse(&crop->y_pexpr, crop->y_expr, var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) return AVERROR(EINVAL); if (crop->keep_aspect) { AVRational dar = av_mul_q(link->sample_aspect_ratio, (AVRational){ link->w, link->h }); av_reduce(&crop->out_sar.num, &crop->out_sar.den, dar.num * crop->h, dar.den * crop->w, INT_MAX); } else crop->out_sar = link->sample_aspect_ratio; av_log(ctx, AV_LOG_INFO, "w:%d h:%d sar:%d/%d -> w:%d h:%d sar:%d/%d\n", link->w, link->h, link->sample_aspect_ratio.num, link->sample_aspect_ratio.den, crop->w, crop->h, crop->out_sar.num, crop->out_sar.den); if (crop->w <= 0 || crop->h <= 0 || crop->w > link->w || crop->h > link->h) { av_log(ctx, AV_LOG_ERROR, "Invalid too big or non positive size for width '%d' or height '%d'\n", crop->w, crop->h); return AVERROR(EINVAL); } /* set default, required in the case the first computed value for x/y is NAN */ crop->x = (link->w - crop->w) / 2; crop->y = (link->h - crop->h) / 2; crop->x &= ~((1 << crop->hsub) - 1); crop->y &= ~((1 << crop->vsub) - 1); return 0; fail_expr: av_log(NULL, AV_LOG_ERROR, "Error when evaluating the expression '%s'\n", expr); return ret; }
static int config_props_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; TransContext *s = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; const AVPixFmtDescriptor *desc_out = av_pix_fmt_desc_get(outlink->format); const AVPixFmtDescriptor *desc_in = av_pix_fmt_desc_get(inlink->format); if (s->dir&4) { av_log(ctx, AV_LOG_WARNING, "dir values greater than 3 are deprecated, use the passthrough option instead\n"); s->dir &= 3; s->passthrough = TRANSPOSE_PT_TYPE_LANDSCAPE; } if ((inlink->w >= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_LANDSCAPE) || (inlink->w <= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_PORTRAIT)) { av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d (passthrough mode)\n", inlink->w, inlink->h, inlink->w, inlink->h); return 0; } else { s->passthrough = TRANSPOSE_PT_TYPE_NONE; } s->hsub = desc_in->log2_chroma_w; s->vsub = desc_in->log2_chroma_h; s->planes = av_pix_fmt_count_planes(outlink->format); av_assert0(desc_in->nb_components == desc_out->nb_components); av_image_fill_max_pixsteps(s->pixsteps, NULL, desc_out); outlink->w = inlink->h; outlink->h = inlink->w; if (inlink->sample_aspect_ratio.num) outlink->sample_aspect_ratio = av_div_q((AVRational) { 1, 1 }, inlink->sample_aspect_ratio); else outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; switch (s->pixsteps[0]) { case 1: s->transpose_block = transpose_block_8_c; s->transpose_8x8 = transpose_8x8_8_c; break; case 2: s->transpose_block = transpose_block_16_c; s->transpose_8x8 = transpose_8x8_16_c; break; case 3: s->transpose_block = transpose_block_24_c; s->transpose_8x8 = transpose_8x8_24_c; break; case 4: s->transpose_block = transpose_block_32_c; s->transpose_8x8 = transpose_8x8_32_c; break; case 6: s->transpose_block = transpose_block_48_c; s->transpose_8x8 = transpose_8x8_48_c; break; case 8: s->transpose_block = transpose_block_64_c; s->transpose_8x8 = transpose_8x8_64_c; break; } av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d dir:%d -> w:%d h:%d rotation:%s vflip:%d\n", inlink->w, inlink->h, s->dir, outlink->w, outlink->h, s->dir == 1 || s->dir == 3 ? "clockwise" : "counterclockwise", s->dir == 0 || s->dir == 3); return 0; }
static int config_input(AVFilterLink *link) { AVFilterContext *ctx = link->dst; CropContext *s = ctx->priv; const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(link->format); int ret; const char *expr; double res; s->var_values[VAR_E] = M_E; s->var_values[VAR_PHI] = M_PHI; s->var_values[VAR_PI] = M_PI; s->var_values[VAR_IN_W] = s->var_values[VAR_IW] = ctx->inputs[0]->w; s->var_values[VAR_IN_H] = s->var_values[VAR_IH] = ctx->inputs[0]->h; s->var_values[VAR_X] = NAN; s->var_values[VAR_Y] = NAN; s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = NAN; s->var_values[VAR_OUT_H] = s->var_values[VAR_OH] = NAN; s->var_values[VAR_N] = 0; s->var_values[VAR_T] = NAN; av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); s->hsub = pix_desc->log2_chroma_w; s->vsub = pix_desc->log2_chroma_h; if ((ret = av_expr_parse_and_eval(&res, (expr = s->ow_expr), var_names, s->var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr; s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = s->oh_expr), var_names, s->var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr; s->var_values[VAR_OUT_H] = s->var_values[VAR_OH] = res; /* evaluate again ow as it may depend on oh */ if ((ret = av_expr_parse_and_eval(&res, (expr = s->ow_expr), var_names, s->var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr; s->var_values[VAR_OUT_W] = s->var_values[VAR_OW] = res; if (normalize_double(&s->w, s->var_values[VAR_OUT_W]) < 0 || normalize_double(&s->h, s->var_values[VAR_OUT_H]) < 0) { av_log(ctx, AV_LOG_ERROR, "Too big value or invalid expression for out_w/ow or out_h/oh. " "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n", s->ow_expr, s->oh_expr); return AVERROR(EINVAL); } s->w &= ~((1 << s->hsub) - 1); s->h &= ~((1 << s->vsub) - 1); av_expr_free(s->x_pexpr); av_expr_free(s->y_pexpr); s->x_pexpr = s->y_pexpr = NULL; if ((ret = av_expr_parse(&s->x_pexpr, s->x_expr, var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0 || (ret = av_expr_parse(&s->y_pexpr, s->y_expr, var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) return AVERROR(EINVAL); av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d\n", link->w, link->h, s->w, s->h); if (s->w <= 0 || s->h <= 0 || s->w > link->w || s->h > link->h) { av_log(ctx, AV_LOG_ERROR, "Invalid too big or non positive size for width '%d' or height '%d'\n", s->w, s->h); return AVERROR(EINVAL); } /* set default, required in the case the first computed value for x/y is NAN */ s->x = (link->w - s->w) / 2; s->y = (link->h - s->h) / 2; s->x &= ~((1 << s->hsub) - 1); s->y &= ~((1 << s->vsub) - 1); return 0; fail_expr: av_log(NULL, AV_LOG_ERROR, "Error when evaluating the expression '%s'\n", expr); return ret; }