You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

542 lines
20KB

  1. /*
  2. * Copyright (c) 2007 Bobby Bingham
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * scale video filter
  23. */
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "avfilter.h"
  27. #include "formats.h"
  28. #include "internal.h"
  29. #include "video.h"
  30. #include "libavutil/avstring.h"
  31. #include "libavutil/eval.h"
  32. #include "libavutil/internal.h"
  33. #include "libavutil/mathematics.h"
  34. #include "libavutil/opt.h"
  35. #include "libavutil/parseutils.h"
  36. #include "libavutil/pixdesc.h"
  37. #include "libavutil/imgutils.h"
  38. #include "libavutil/avassert.h"
  39. #include "libswscale/swscale.h"
  40. static const char *const var_names[] = {
  41. "in_w", "iw",
  42. "in_h", "ih",
  43. "out_w", "ow",
  44. "out_h", "oh",
  45. "a",
  46. "sar",
  47. "dar",
  48. "hsub",
  49. "vsub",
  50. NULL
  51. };
  52. enum var_name {
  53. VAR_IN_W, VAR_IW,
  54. VAR_IN_H, VAR_IH,
  55. VAR_OUT_W, VAR_OW,
  56. VAR_OUT_H, VAR_OH,
  57. VAR_A,
  58. VAR_SAR,
  59. VAR_DAR,
  60. VAR_HSUB,
  61. VAR_VSUB,
  62. VARS_NB
  63. };
  64. typedef struct {
  65. const AVClass *class;
  66. struct SwsContext *sws; ///< software scaler context
  67. struct SwsContext *isws[2]; ///< software scaler context for interlaced material
  68. /**
  69. * New dimensions. Special values are:
  70. * 0 = original width/height
  71. * -1 = keep original aspect
  72. */
  73. int w, h;
  74. char *size_str;
  75. unsigned int flags; ///sws flags
  76. int hsub, vsub; ///< chroma subsampling
  77. int slice_y; ///< top of current output slice
  78. int input_is_pal; ///< set to 1 if the input format is paletted
  79. int output_is_pal; ///< set to 1 if the output format is paletted
  80. int interlaced;
  81. char *w_expr; ///< width expression string
  82. char *h_expr; ///< height expression string
  83. char *flags_str;
  84. char *in_color_matrix;
  85. char *out_color_matrix;
  86. int in_range;
  87. int out_range;
  88. int out_h_chr_pos;
  89. int out_v_chr_pos;
  90. int in_h_chr_pos;
  91. int in_v_chr_pos;
  92. } ScaleContext;
  93. static av_cold int init(AVFilterContext *ctx)
  94. {
  95. ScaleContext *scale = ctx->priv;
  96. int ret;
  97. if (scale->size_str && (scale->w_expr || scale->h_expr)) {
  98. av_log(ctx, AV_LOG_ERROR,
  99. "Size and width/height expressions cannot be set at the same time.\n");
  100. return AVERROR(EINVAL);
  101. }
  102. if (scale->w_expr && !scale->h_expr)
  103. FFSWAP(char *, scale->w_expr, scale->size_str);
  104. if (scale->size_str) {
  105. char buf[32];
  106. if ((ret = av_parse_video_size(&scale->w, &scale->h, scale->size_str)) < 0) {
  107. av_log(ctx, AV_LOG_ERROR,
  108. "Invalid size '%s'\n", scale->size_str);
  109. return ret;
  110. }
  111. snprintf(buf, sizeof(buf)-1, "%d", scale->w);
  112. av_opt_set(scale, "w", buf, 0);
  113. snprintf(buf, sizeof(buf)-1, "%d", scale->h);
  114. av_opt_set(scale, "h", buf, 0);
  115. }
  116. if (!scale->w_expr)
  117. av_opt_set(scale, "w", "iw", 0);
  118. if (!scale->h_expr)
  119. av_opt_set(scale, "h", "ih", 0);
  120. av_log(ctx, AV_LOG_VERBOSE, "w:%s h:%s flags:'%s' interl:%d\n",
  121. scale->w_expr, scale->h_expr, (char *)av_x_if_null(scale->flags_str, ""), scale->interlaced);
  122. scale->flags = SWS_BILINEAR;
  123. if (scale->flags_str) {
  124. const AVClass *class = sws_get_class();
  125. const AVOption *o = av_opt_find(&class, "sws_flags", NULL, 0,
  126. AV_OPT_SEARCH_FAKE_OBJ);
  127. int ret = av_opt_eval_flags(&class, o, scale->flags_str, &scale->flags);
  128. if (ret < 0)
  129. return ret;
  130. }
  131. return 0;
  132. }
  133. static av_cold void uninit(AVFilterContext *ctx)
  134. {
  135. ScaleContext *scale = ctx->priv;
  136. sws_freeContext(scale->sws);
  137. sws_freeContext(scale->isws[0]);
  138. sws_freeContext(scale->isws[1]);
  139. scale->sws = NULL;
  140. }
  141. static int query_formats(AVFilterContext *ctx)
  142. {
  143. AVFilterFormats *formats;
  144. enum AVPixelFormat pix_fmt;
  145. int ret;
  146. if (ctx->inputs[0]) {
  147. formats = NULL;
  148. for (pix_fmt = 0; pix_fmt < AV_PIX_FMT_NB; pix_fmt++)
  149. if ((sws_isSupportedInput(pix_fmt) ||
  150. sws_isSupportedEndiannessConversion(pix_fmt))
  151. && (ret = ff_add_format(&formats, pix_fmt)) < 0) {
  152. ff_formats_unref(&formats);
  153. return ret;
  154. }
  155. ff_formats_ref(formats, &ctx->inputs[0]->out_formats);
  156. }
  157. if (ctx->outputs[0]) {
  158. formats = NULL;
  159. for (pix_fmt = 0; pix_fmt < AV_PIX_FMT_NB; pix_fmt++)
  160. if ((sws_isSupportedOutput(pix_fmt) || pix_fmt == AV_PIX_FMT_PAL8 ||
  161. sws_isSupportedEndiannessConversion(pix_fmt))
  162. && (ret = ff_add_format(&formats, pix_fmt)) < 0) {
  163. ff_formats_unref(&formats);
  164. return ret;
  165. }
  166. ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
  167. }
  168. return 0;
  169. }
  170. static const int *parse_yuv_type(const char *s, enum AVColorSpace colorspace)
  171. {
  172. if (!s)
  173. s = "bt601";
  174. if (s && strstr(s, "bt709")) {
  175. colorspace = AVCOL_SPC_BT709;
  176. } else if (s && strstr(s, "fcc")) {
  177. colorspace = AVCOL_SPC_FCC;
  178. } else if (s && strstr(s, "smpte240m")) {
  179. colorspace = AVCOL_SPC_SMPTE240M;
  180. } else if (s && (strstr(s, "bt601") || strstr(s, "bt470") || strstr(s, "smpte170m"))) {
  181. colorspace = AVCOL_SPC_BT470BG;
  182. }
  183. if (colorspace < 1 || colorspace > 7) {
  184. colorspace = AVCOL_SPC_BT470BG;
  185. }
  186. return sws_getCoefficients(colorspace);
  187. }
  188. static int config_props(AVFilterLink *outlink)
  189. {
  190. AVFilterContext *ctx = outlink->src;
  191. AVFilterLink *inlink = outlink->src->inputs[0];
  192. enum AVPixelFormat outfmt = outlink->format;
  193. ScaleContext *scale = ctx->priv;
  194. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  195. int64_t w, h;
  196. double var_values[VARS_NB], res;
  197. char *expr;
  198. int ret;
  199. var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;
  200. var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
  201. var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
  202. var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
  203. var_values[VAR_A] = (double) inlink->w / inlink->h;
  204. var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
  205. (double) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
  206. var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
  207. var_values[VAR_HSUB] = 1 << desc->log2_chroma_w;
  208. var_values[VAR_VSUB] = 1 << desc->log2_chroma_h;
  209. /* evaluate width and height */
  210. av_expr_parse_and_eval(&res, (expr = scale->w_expr),
  211. var_names, var_values,
  212. NULL, NULL, NULL, NULL, NULL, 0, ctx);
  213. scale->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;
  214. if ((ret = av_expr_parse_and_eval(&res, (expr = scale->h_expr),
  215. var_names, var_values,
  216. NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
  217. goto fail;
  218. scale->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;
  219. /* evaluate again the width, as it may depend on the output height */
  220. if ((ret = av_expr_parse_and_eval(&res, (expr = scale->w_expr),
  221. var_names, var_values,
  222. NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)
  223. goto fail;
  224. scale->w = res;
  225. w = scale->w;
  226. h = scale->h;
  227. /* sanity check params */
  228. if (w < -1 || h < -1) {
  229. av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n");
  230. return AVERROR(EINVAL);
  231. }
  232. if (w == -1 && h == -1)
  233. scale->w = scale->h = 0;
  234. if (!(w = scale->w))
  235. w = inlink->w;
  236. if (!(h = scale->h))
  237. h = inlink->h;
  238. if (w == -1)
  239. w = av_rescale(h, inlink->w, inlink->h);
  240. if (h == -1)
  241. h = av_rescale(w, inlink->h, inlink->w);
  242. if (w > INT_MAX || h > INT_MAX ||
  243. (h * inlink->w) > INT_MAX ||
  244. (w * inlink->h) > INT_MAX)
  245. av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
  246. outlink->w = w;
  247. outlink->h = h;
  248. /* TODO: make algorithm configurable */
  249. scale->input_is_pal = desc->flags & AV_PIX_FMT_FLAG_PAL ||
  250. desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL;
  251. if (outfmt == AV_PIX_FMT_PAL8) outfmt = AV_PIX_FMT_BGR8;
  252. scale->output_is_pal = av_pix_fmt_desc_get(outfmt)->flags & AV_PIX_FMT_FLAG_PAL ||
  253. av_pix_fmt_desc_get(outfmt)->flags & AV_PIX_FMT_FLAG_PSEUDOPAL;
  254. if (scale->sws)
  255. sws_freeContext(scale->sws);
  256. if (scale->isws[0])
  257. sws_freeContext(scale->isws[0]);
  258. if (scale->isws[1])
  259. sws_freeContext(scale->isws[1]);
  260. scale->isws[0] = scale->isws[1] = scale->sws = NULL;
  261. if (inlink->w == outlink->w && inlink->h == outlink->h &&
  262. inlink->format == outlink->format)
  263. ;
  264. else {
  265. struct SwsContext **swscs[3] = {&scale->sws, &scale->isws[0], &scale->isws[1]};
  266. int i;
  267. for (i = 0; i < 3; i++) {
  268. struct SwsContext **s = swscs[i];
  269. *s = sws_alloc_context();
  270. if (!*s)
  271. return AVERROR(ENOMEM);
  272. av_opt_set_int(*s, "srcw", inlink ->w, 0);
  273. av_opt_set_int(*s, "srch", inlink ->h >> !!i, 0);
  274. av_opt_set_int(*s, "src_format", inlink->format, 0);
  275. av_opt_set_int(*s, "dstw", outlink->w, 0);
  276. av_opt_set_int(*s, "dsth", outlink->h >> !!i, 0);
  277. av_opt_set_int(*s, "dst_format", outfmt, 0);
  278. av_opt_set_int(*s, "sws_flags", scale->flags, 0);
  279. av_opt_set_int(*s, "src_h_chr_pos", scale->in_h_chr_pos, 0);
  280. av_opt_set_int(*s, "src_v_chr_pos", scale->in_v_chr_pos, 0);
  281. av_opt_set_int(*s, "dst_h_chr_pos", scale->out_h_chr_pos, 0);
  282. av_opt_set_int(*s, "dst_v_chr_pos", scale->out_v_chr_pos, 0);
  283. if ((ret = sws_init_context(*s, NULL, NULL)) < 0)
  284. return ret;
  285. if (!scale->interlaced)
  286. break;
  287. }
  288. }
  289. if (inlink->sample_aspect_ratio.num){
  290. outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio);
  291. } else
  292. outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
  293. av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d fmt:%s sar:%d/%d flags:0x%0x\n",
  294. inlink ->w, inlink ->h, av_get_pix_fmt_name( inlink->format),
  295. inlink->sample_aspect_ratio.num, inlink->sample_aspect_ratio.den,
  296. outlink->w, outlink->h, av_get_pix_fmt_name(outlink->format),
  297. outlink->sample_aspect_ratio.num, outlink->sample_aspect_ratio.den,
  298. scale->flags);
  299. return 0;
  300. fail:
  301. av_log(NULL, AV_LOG_ERROR,
  302. "Error when evaluating the expression '%s'.\n"
  303. "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
  304. expr, scale->w_expr, scale->h_expr);
  305. return ret;
  306. }
  307. static int scale_slice(AVFilterLink *link, AVFrame *out_buf, AVFrame *cur_pic, struct SwsContext *sws, int y, int h, int mul, int field)
  308. {
  309. ScaleContext *scale = link->dst->priv;
  310. const uint8_t *in[4];
  311. uint8_t *out[4];
  312. int in_stride[4],out_stride[4];
  313. int i;
  314. for(i=0; i<4; i++){
  315. int vsub= ((i+1)&2) ? scale->vsub : 0;
  316. in_stride[i] = cur_pic->linesize[i] * mul;
  317. out_stride[i] = out_buf->linesize[i] * mul;
  318. in[i] = cur_pic->data[i] + ((y>>vsub)+field) * cur_pic->linesize[i];
  319. out[i] = out_buf->data[i] + field * out_buf->linesize[i];
  320. }
  321. if(scale->input_is_pal)
  322. in[1] = cur_pic->data[1];
  323. if(scale->output_is_pal)
  324. out[1] = out_buf->data[1];
  325. return sws_scale(sws, in, in_stride, y/mul, h,
  326. out,out_stride);
  327. }
  328. static int filter_frame(AVFilterLink *link, AVFrame *in)
  329. {
  330. ScaleContext *scale = link->dst->priv;
  331. AVFilterLink *outlink = link->dst->outputs[0];
  332. AVFrame *out;
  333. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
  334. char buf[32];
  335. int in_range;
  336. if( in->width != link->w
  337. || in->height != link->h
  338. || in->format != link->format) {
  339. int ret;
  340. snprintf(buf, sizeof(buf)-1, "%d", outlink->w);
  341. av_opt_set(scale, "w", buf, 0);
  342. snprintf(buf, sizeof(buf)-1, "%d", outlink->h);
  343. av_opt_set(scale, "h", buf, 0);
  344. link->dst->inputs[0]->format = in->format;
  345. link->dst->inputs[0]->w = in->width;
  346. link->dst->inputs[0]->h = in->height;
  347. if ((ret = config_props(outlink)) < 0)
  348. return ret;
  349. }
  350. if (!scale->sws)
  351. return ff_filter_frame(outlink, in);
  352. scale->hsub = desc->log2_chroma_w;
  353. scale->vsub = desc->log2_chroma_h;
  354. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  355. if (!out) {
  356. av_frame_free(&in);
  357. return AVERROR(ENOMEM);
  358. }
  359. av_frame_copy_props(out, in);
  360. out->width = outlink->w;
  361. out->height = outlink->h;
  362. if(scale->output_is_pal)
  363. avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);
  364. in_range = av_frame_get_color_range(in);
  365. if ( scale->in_color_matrix
  366. || scale->out_color_matrix
  367. || scale-> in_range != AVCOL_RANGE_UNSPECIFIED
  368. || in_range != AVCOL_RANGE_UNSPECIFIED
  369. || scale->out_range != AVCOL_RANGE_UNSPECIFIED) {
  370. int in_full, out_full, brightness, contrast, saturation;
  371. const int *inv_table, *table;
  372. sws_getColorspaceDetails(scale->sws, (int **)&inv_table, &in_full,
  373. (int **)&table, &out_full,
  374. &brightness, &contrast, &saturation);
  375. if (scale->in_color_matrix)
  376. inv_table = parse_yuv_type(scale->in_color_matrix, av_frame_get_colorspace(in));
  377. if (scale->out_color_matrix)
  378. table = parse_yuv_type(scale->out_color_matrix, AVCOL_SPC_UNSPECIFIED);
  379. if (scale-> in_range != AVCOL_RANGE_UNSPECIFIED)
  380. in_full = (scale-> in_range == AVCOL_RANGE_JPEG);
  381. else if (in_range != AVCOL_RANGE_UNSPECIFIED)
  382. in_full = (in_range == AVCOL_RANGE_JPEG);
  383. if (scale->out_range != AVCOL_RANGE_UNSPECIFIED)
  384. out_full = (scale->out_range == AVCOL_RANGE_JPEG);
  385. sws_setColorspaceDetails(scale->sws, inv_table, in_full,
  386. table, out_full,
  387. brightness, contrast, saturation);
  388. if (scale->isws[0])
  389. sws_setColorspaceDetails(scale->isws[0], inv_table, in_full,
  390. table, out_full,
  391. brightness, contrast, saturation);
  392. if (scale->isws[1])
  393. sws_setColorspaceDetails(scale->isws[1], inv_table, in_full,
  394. table, out_full,
  395. brightness, contrast, saturation);
  396. }
  397. av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den,
  398. (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
  399. (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
  400. INT_MAX);
  401. if(scale->interlaced>0 || (scale->interlaced<0 && in->interlaced_frame)){
  402. scale_slice(link, out, in, scale->isws[0], 0, (link->h+1)/2, 2, 0);
  403. scale_slice(link, out, in, scale->isws[1], 0, link->h /2, 2, 1);
  404. }else{
  405. scale_slice(link, out, in, scale->sws, 0, link->h, 1, 0);
  406. }
  407. av_frame_free(&in);
  408. return ff_filter_frame(outlink, out);
  409. }
  410. #define OFFSET(x) offsetof(ScaleContext, x)
  411. #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  412. static const AVOption scale_options[] = {
  413. { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
  414. { "width", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
  415. { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
  416. { "height","Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, .flags = FLAGS },
  417. { "flags", "Flags to pass to libswscale", OFFSET(flags_str), AV_OPT_TYPE_STRING, { .str = "bilinear" }, .flags = FLAGS },
  418. { "interl", "set interlacing", OFFSET(interlaced), AV_OPT_TYPE_INT, {.i64 = 0 }, -1, 1, FLAGS },
  419. { "size", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
  420. { "s", "set video size", OFFSET(size_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
  421. { "in_color_matrix", "set input YCbCr type", OFFSET(in_color_matrix), AV_OPT_TYPE_STRING, { .str = "auto" }, .flags = FLAGS },
  422. { "out_color_matrix", "set output YCbCr type", OFFSET(out_color_matrix), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
  423. { "in_range", "set input color range", OFFSET( in_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 2, FLAGS, "range" },
  424. { "out_range", "set output color range", OFFSET(out_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 2, FLAGS, "range" },
  425. { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_UNSPECIFIED }, 0, 0, FLAGS, "range" },
  426. { "full", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range" },
  427. { "jpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range" },
  428. { "mpeg", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range" },
  429. { "tv", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_JPEG}, 0, 0, FLAGS, "range" },
  430. { "pc", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_RANGE_MPEG}, 0, 0, FLAGS, "range" },
  431. { "in_v_chr_pos", "input vertical chroma position in luma grid/256" , OFFSET(in_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -1}, -1, 512, FLAGS },
  432. { "in_h_chr_pos", "input horizontal chroma position in luma grid/256", OFFSET(in_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -1}, -1, 512, FLAGS },
  433. { "out_v_chr_pos", "output vertical chroma position in luma grid/256" , OFFSET(out_v_chr_pos), AV_OPT_TYPE_INT, { .i64 = -1}, -1, 512, FLAGS },
  434. { "out_h_chr_pos", "output horizontal chroma position in luma grid/256", OFFSET(out_h_chr_pos), AV_OPT_TYPE_INT, { .i64 = -1}, -1, 512, FLAGS },
  435. { NULL },
  436. };
  437. AVFILTER_DEFINE_CLASS(scale);
  438. static const AVFilterPad avfilter_vf_scale_inputs[] = {
  439. {
  440. .name = "default",
  441. .type = AVMEDIA_TYPE_VIDEO,
  442. .filter_frame = filter_frame,
  443. },
  444. { NULL }
  445. };
  446. static const AVFilterPad avfilter_vf_scale_outputs[] = {
  447. {
  448. .name = "default",
  449. .type = AVMEDIA_TYPE_VIDEO,
  450. .config_props = config_props,
  451. },
  452. { NULL }
  453. };
  454. AVFilter avfilter_vf_scale = {
  455. .name = "scale",
  456. .description = NULL_IF_CONFIG_SMALL("Scale the input video to width:height size and/or convert the image format."),
  457. .init = init,
  458. .uninit = uninit,
  459. .query_formats = query_formats,
  460. .priv_size = sizeof(ScaleContext),
  461. .priv_class = &scale_class,
  462. .inputs = avfilter_vf_scale_inputs,
  463. .outputs = avfilter_vf_scale_outputs,
  464. };