vf_perspective.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*
  2. * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
  3. * Copyright (c) 2013 Paul B Mahol
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/avassert.h"
  22. #include "libavutil/eval.h"
  23. #include "libavutil/imgutils.h"
  24. #include "libavutil/pixdesc.h"
  25. #include "libavutil/opt.h"
  26. #include "avfilter.h"
  27. #include "formats.h"
  28. #include "internal.h"
  29. #include "video.h"
  30. #define SUB_PIXEL_BITS 8
  31. #define SUB_PIXELS (1 << SUB_PIXEL_BITS)
  32. #define COEFF_BITS 11
  33. #define LINEAR 0
  34. #define CUBIC 1
  35. typedef struct PerspectiveContext {
  36. const AVClass *class;
  37. char *expr_str[4][2];
  38. double ref[4][2];
  39. int32_t (*pv)[2];
  40. int32_t coeff[SUB_PIXELS][4];
  41. int interpolation;
  42. int linesize[4];
  43. int height[4];
  44. int hsub, vsub;
  45. int nb_planes;
  46. int sense;
  47. int eval_mode;
  48. int (*perspective)(AVFilterContext *ctx,
  49. void *arg, int job, int nb_jobs);
  50. } PerspectiveContext;
  51. #define OFFSET(x) offsetof(PerspectiveContext, x)
  52. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  53. enum PERSPECTIVESense {
  54. PERSPECTIVE_SENSE_SOURCE = 0, ///< coordinates give locations in source of corners of destination.
  55. PERSPECTIVE_SENSE_DESTINATION = 1, ///< coordinates give locations in destination of corners of source.
  56. };
  57. enum EvalMode {
  58. EVAL_MODE_INIT,
  59. EVAL_MODE_FRAME,
  60. EVAL_MODE_NB
  61. };
  62. static const AVOption perspective_options[] = {
  63. { "x0", "set top left x coordinate", OFFSET(expr_str[0][0]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
  64. { "y0", "set top left y coordinate", OFFSET(expr_str[0][1]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
  65. { "x1", "set top right x coordinate", OFFSET(expr_str[1][0]), AV_OPT_TYPE_STRING, {.str="W"}, 0, 0, FLAGS },
  66. { "y1", "set top right y coordinate", OFFSET(expr_str[1][1]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
  67. { "x2", "set bottom left x coordinate", OFFSET(expr_str[2][0]), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, FLAGS },
  68. { "y2", "set bottom left y coordinate", OFFSET(expr_str[2][1]), AV_OPT_TYPE_STRING, {.str="H"}, 0, 0, FLAGS },
  69. { "x3", "set bottom right x coordinate", OFFSET(expr_str[3][0]), AV_OPT_TYPE_STRING, {.str="W"}, 0, 0, FLAGS },
  70. { "y3", "set bottom right y coordinate", OFFSET(expr_str[3][1]), AV_OPT_TYPE_STRING, {.str="H"}, 0, 0, FLAGS },
  71. { "interpolation", "set interpolation", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=LINEAR}, 0, 1, FLAGS, "interpolation" },
  72. { "linear", "", 0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, "interpolation" },
  73. { "cubic", "", 0, AV_OPT_TYPE_CONST, {.i64=CUBIC}, 0, 0, FLAGS, "interpolation" },
  74. { "sense", "specify the sense of the coordinates", OFFSET(sense), AV_OPT_TYPE_INT, {.i64=PERSPECTIVE_SENSE_SOURCE}, 0, 1, FLAGS, "sense"},
  75. { "source", "specify locations in source to send to corners in destination",
  76. 0, AV_OPT_TYPE_CONST, {.i64=PERSPECTIVE_SENSE_SOURCE}, 0, 0, FLAGS, "sense"},
  77. { "destination", "specify locations in destination to send corners of source",
  78. 0, AV_OPT_TYPE_CONST, {.i64=PERSPECTIVE_SENSE_DESTINATION}, 0, 0, FLAGS, "sense"},
  79. { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_INIT}, 0, EVAL_MODE_NB-1, FLAGS, "eval" },
  80. { "init", "eval expressions once during initialization", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_INIT}, .flags = FLAGS, .unit = "eval" },
  81. { "frame", "eval expressions per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = FLAGS, .unit = "eval" },
  82. { NULL }
  83. };
  84. AVFILTER_DEFINE_CLASS(perspective);
  85. static int query_formats(AVFilterContext *ctx)
  86. {
  87. static const enum AVPixelFormat pix_fmts[] = {
  88. AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
  89. AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ422P,AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ411P,
  90. AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
  91. AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE
  92. };
  93. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  94. if (!fmts_list)
  95. return AVERROR(ENOMEM);
  96. return ff_set_common_formats(ctx, fmts_list);
  97. }
  98. static inline double get_coeff(double d)
  99. {
  100. double coeff, A = -0.60;
  101. d = fabs(d);
  102. if (d < 1.0)
  103. coeff = (1.0 - (A + 3.0) * d * d + (A + 2.0) * d * d * d);
  104. else if (d < 2.0)
  105. coeff = (-4.0 * A + 8.0 * A * d - 5.0 * A * d * d + A * d * d * d);
  106. else
  107. coeff = 0.0;
  108. return coeff;
  109. }
  110. static const char *const var_names[] = { "W", "H", "in", "on", NULL };
  111. enum { VAR_W, VAR_H, VAR_IN, VAR_ON, VAR_VARS_NB };
  112. static int calc_persp_luts(AVFilterContext *ctx, AVFilterLink *inlink)
  113. {
  114. PerspectiveContext *s = ctx->priv;
  115. AVFilterLink *outlink = ctx->outputs[0];
  116. double (*ref)[2] = s->ref;
  117. double values[VAR_VARS_NB] = { [VAR_W] = inlink->w, [VAR_H] = inlink->h,
  118. [VAR_IN] = inlink->frame_count_out + 1,
  119. [VAR_ON] = outlink->frame_count_in + 1 };
  120. const int h = values[VAR_H];
  121. const int w = values[VAR_W];
  122. double x0, x1, x2, x3, x4, x5, x6, x7, x8, q;
  123. double t0, t1, t2, t3;
  124. int x, y, i, j, ret;
  125. for (i = 0; i < 4; i++) {
  126. for (j = 0; j < 2; j++) {
  127. if (!s->expr_str[i][j])
  128. return AVERROR(EINVAL);
  129. ret = av_expr_parse_and_eval(&s->ref[i][j], s->expr_str[i][j],
  130. var_names, &values[0],
  131. NULL, NULL, NULL, NULL,
  132. 0, 0, ctx);
  133. if (ret < 0)
  134. return ret;
  135. }
  136. }
  137. switch (s->sense) {
  138. case PERSPECTIVE_SENSE_SOURCE:
  139. x6 = ((ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0]) *
  140. (ref[2][1] - ref[3][1]) -
  141. ( ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1]) *
  142. (ref[2][0] - ref[3][0])) * h;
  143. x7 = ((ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1]) *
  144. (ref[1][0] - ref[3][0]) -
  145. ( ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0]) *
  146. (ref[1][1] - ref[3][1])) * w;
  147. q = ( ref[1][0] - ref[3][0]) * (ref[2][1] - ref[3][1]) -
  148. ( ref[2][0] - ref[3][0]) * (ref[1][1] - ref[3][1]);
  149. x0 = q * (ref[1][0] - ref[0][0]) * h + x6 * ref[1][0];
  150. x1 = q * (ref[2][0] - ref[0][0]) * w + x7 * ref[2][0];
  151. x2 = q * ref[0][0] * w * h;
  152. x3 = q * (ref[1][1] - ref[0][1]) * h + x6 * ref[1][1];
  153. x4 = q * (ref[2][1] - ref[0][1]) * w + x7 * ref[2][1];
  154. x5 = q * ref[0][1] * w * h;
  155. x8 = q * w * h;
  156. break;
  157. case PERSPECTIVE_SENSE_DESTINATION:
  158. t0 = ref[0][0] * (ref[3][1] - ref[1][1]) +
  159. ref[1][0] * (ref[0][1] - ref[3][1]) +
  160. ref[3][0] * (ref[1][1] - ref[0][1]);
  161. t1 = ref[1][0] * (ref[2][1] - ref[3][1]) +
  162. ref[2][0] * (ref[3][1] - ref[1][1]) +
  163. ref[3][0] * (ref[1][1] - ref[2][1]);
  164. t2 = ref[0][0] * (ref[3][1] - ref[2][1]) +
  165. ref[2][0] * (ref[0][1] - ref[3][1]) +
  166. ref[3][0] * (ref[2][1] - ref[0][1]);
  167. t3 = ref[0][0] * (ref[1][1] - ref[2][1]) +
  168. ref[1][0] * (ref[2][1] - ref[0][1]) +
  169. ref[2][0] * (ref[0][1] - ref[1][1]);
  170. x0 = t0 * t1 * w * (ref[2][1] - ref[0][1]);
  171. x1 = t0 * t1 * w * (ref[0][0] - ref[2][0]);
  172. x2 = t0 * t1 * w * (ref[0][1] * ref[2][0] - ref[0][0] * ref[2][1]);
  173. x3 = t1 * t2 * h * (ref[1][1] - ref[0][1]);
  174. x4 = t1 * t2 * h * (ref[0][0] - ref[1][0]);
  175. x5 = t1 * t2 * h * (ref[0][1] * ref[1][0] - ref[0][0] * ref[1][1]);
  176. x6 = t1 * t2 * (ref[1][1] - ref[0][1]) +
  177. t0 * t3 * (ref[2][1] - ref[3][1]);
  178. x7 = t1 * t2 * (ref[0][0] - ref[1][0]) +
  179. t0 * t3 * (ref[3][0] - ref[2][0]);
  180. x8 = t1 * t2 * (ref[0][1] * ref[1][0] - ref[0][0] * ref[1][1]) +
  181. t0 * t3 * (ref[2][0] * ref[3][1] - ref[2][1] * ref[3][0]);
  182. break;
  183. default:
  184. av_assert0(0);
  185. }
  186. for (y = 0; y < h; y++){
  187. for (x = 0; x < w; x++){
  188. int u, v;
  189. u = lrint(SUB_PIXELS * (x0 * x + x1 * y + x2) /
  190. (x6 * x + x7 * y + x8));
  191. v = lrint(SUB_PIXELS * (x3 * x + x4 * y + x5) /
  192. (x6 * x + x7 * y + x8));
  193. s->pv[x + y * w][0] = u;
  194. s->pv[x + y * w][1] = v;
  195. }
  196. }
  197. return 0;
  198. }
  199. static int config_input(AVFilterLink *inlink)
  200. {
  201. AVFilterContext *ctx = inlink->dst;
  202. PerspectiveContext *s = ctx->priv;
  203. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  204. int h = inlink->h;
  205. int w = inlink->w;
  206. int i, j, ret;
  207. s->hsub = desc->log2_chroma_w;
  208. s->vsub = desc->log2_chroma_h;
  209. s->nb_planes = av_pix_fmt_count_planes(inlink->format);
  210. if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
  211. return ret;
  212. s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
  213. s->height[0] = s->height[3] = inlink->h;
  214. s->pv = av_realloc_f(s->pv, w * h, 2 * sizeof(*s->pv));
  215. if (!s->pv)
  216. return AVERROR(ENOMEM);
  217. if (s->eval_mode == EVAL_MODE_INIT) {
  218. if ((ret = calc_persp_luts(ctx, inlink)) < 0) {
  219. return ret;
  220. }
  221. }
  222. for (i = 0; i < SUB_PIXELS; i++){
  223. double d = i / (double)SUB_PIXELS;
  224. double temp[4];
  225. double sum = 0;
  226. for (j = 0; j < 4; j++)
  227. temp[j] = get_coeff(j - d - 1);
  228. for (j = 0; j < 4; j++)
  229. sum += temp[j];
  230. for (j = 0; j < 4; j++)
  231. s->coeff[i][j] = lrint((1 << COEFF_BITS) * temp[j] / sum);
  232. }
  233. return 0;
  234. }
  235. typedef struct ThreadData {
  236. uint8_t *dst;
  237. int dst_linesize;
  238. uint8_t *src;
  239. int src_linesize;
  240. int w, h;
  241. int hsub, vsub;
  242. } ThreadData;
  243. static int resample_cubic(AVFilterContext *ctx, void *arg,
  244. int job, int nb_jobs)
  245. {
  246. PerspectiveContext *s = ctx->priv;
  247. ThreadData *td = arg;
  248. uint8_t *dst = td->dst;
  249. int dst_linesize = td->dst_linesize;
  250. uint8_t *src = td->src;
  251. int src_linesize = td->src_linesize;
  252. int w = td->w;
  253. int h = td->h;
  254. int hsub = td->hsub;
  255. int vsub = td->vsub;
  256. int start = (h * job) / nb_jobs;
  257. int end = (h * (job+1)) / nb_jobs;
  258. const int linesize = s->linesize[0];
  259. int x, y;
  260. for (y = start; y < end; y++) {
  261. int sy = y << vsub;
  262. for (x = 0; x < w; x++) {
  263. int u, v, subU, subV, sum, sx;
  264. sx = x << hsub;
  265. u = s->pv[sx + sy * linesize][0] >> hsub;
  266. v = s->pv[sx + sy * linesize][1] >> vsub;
  267. subU = u & (SUB_PIXELS - 1);
  268. subV = v & (SUB_PIXELS - 1);
  269. u >>= SUB_PIXEL_BITS;
  270. v >>= SUB_PIXEL_BITS;
  271. if (u > 0 && v > 0 && u < w - 2 && v < h - 2){
  272. const int index = u + v*src_linesize;
  273. const int a = s->coeff[subU][0];
  274. const int b = s->coeff[subU][1];
  275. const int c = s->coeff[subU][2];
  276. const int d = s->coeff[subU][3];
  277. sum = s->coeff[subV][0] * (a * src[index - 1 - src_linesize] + b * src[index - 0 - src_linesize] +
  278. c * src[index + 1 - src_linesize] + d * src[index + 2 - src_linesize]) +
  279. s->coeff[subV][1] * (a * src[index - 1 ] + b * src[index - 0 ] +
  280. c * src[index + 1 ] + d * src[index + 2 ]) +
  281. s->coeff[subV][2] * (a * src[index - 1 + src_linesize] + b * src[index - 0 + src_linesize] +
  282. c * src[index + 1 + src_linesize] + d * src[index + 2 + src_linesize]) +
  283. s->coeff[subV][3] * (a * src[index - 1 + 2 * src_linesize] + b * src[index - 0 + 2 * src_linesize] +
  284. c * src[index + 1 + 2 * src_linesize] + d * src[index + 2 + 2 * src_linesize]);
  285. } else {
  286. int dx, dy;
  287. sum = 0;
  288. for (dy = 0; dy < 4; dy++) {
  289. int iy = v + dy - 1;
  290. if (iy < 0)
  291. iy = 0;
  292. else if (iy >= h)
  293. iy = h-1;
  294. for (dx = 0; dx < 4; dx++) {
  295. int ix = u + dx - 1;
  296. if (ix < 0)
  297. ix = 0;
  298. else if (ix >= w)
  299. ix = w - 1;
  300. sum += s->coeff[subU][dx] * s->coeff[subV][dy] * src[ ix + iy * src_linesize];
  301. }
  302. }
  303. }
  304. sum = (sum + (1<<(COEFF_BITS * 2 - 1))) >> (COEFF_BITS * 2);
  305. sum = av_clip_uint8(sum);
  306. dst[x + y * dst_linesize] = sum;
  307. }
  308. }
  309. return 0;
  310. }
  311. static int resample_linear(AVFilterContext *ctx, void *arg,
  312. int job, int nb_jobs)
  313. {
  314. PerspectiveContext *s = ctx->priv;
  315. ThreadData *td = arg;
  316. uint8_t *dst = td->dst;
  317. int dst_linesize = td->dst_linesize;
  318. uint8_t *src = td->src;
  319. int src_linesize = td->src_linesize;
  320. int w = td->w;
  321. int h = td->h;
  322. int hsub = td->hsub;
  323. int vsub = td->vsub;
  324. int start = (h * job) / nb_jobs;
  325. int end = (h * (job+1)) / nb_jobs;
  326. const int linesize = s->linesize[0];
  327. int x, y;
  328. for (y = start; y < end; y++){
  329. int sy = y << vsub;
  330. for (x = 0; x < w; x++){
  331. int u, v, subU, subV, sum, sx, index, subUI, subVI;
  332. sx = x << hsub;
  333. u = s->pv[sx + sy * linesize][0] >> hsub;
  334. v = s->pv[sx + sy * linesize][1] >> vsub;
  335. subU = u & (SUB_PIXELS - 1);
  336. subV = v & (SUB_PIXELS - 1);
  337. u >>= SUB_PIXEL_BITS;
  338. v >>= SUB_PIXEL_BITS;
  339. index = u + v * src_linesize;
  340. subUI = SUB_PIXELS - subU;
  341. subVI = SUB_PIXELS - subV;
  342. if ((unsigned)u < (unsigned)(w - 1)){
  343. if((unsigned)v < (unsigned)(h - 1)){
  344. sum = subVI * (subUI * src[index] + subU * src[index + 1]) +
  345. subV * (subUI * src[index + src_linesize] + subU * src[index + src_linesize + 1]);
  346. sum = (sum + (1 << (SUB_PIXEL_BITS * 2 - 1)))>> (SUB_PIXEL_BITS * 2);
  347. } else {
  348. if (v < 0)
  349. v = 0;
  350. else
  351. v = h - 1;
  352. index = u + v * src_linesize;
  353. sum = subUI * src[index] + subU * src[index + 1];
  354. sum = (sum + (1 << (SUB_PIXEL_BITS - 1))) >> SUB_PIXEL_BITS;
  355. }
  356. } else {
  357. if (u < 0)
  358. u = 0;
  359. else
  360. u = w - 1;
  361. if ((unsigned)v < (unsigned)(h - 1)){
  362. index = u + v * src_linesize;
  363. sum = subVI * src[index] + subV * src[index + src_linesize];
  364. sum = (sum + (1 << (SUB_PIXEL_BITS - 1))) >> SUB_PIXEL_BITS;
  365. } else {
  366. if (v < 0)
  367. v = 0;
  368. else
  369. v = h - 1;
  370. index = u + v * src_linesize;
  371. sum = src[index];
  372. }
  373. }
  374. sum = av_clip_uint8(sum);
  375. dst[x + y * dst_linesize] = sum;
  376. }
  377. }
  378. return 0;
  379. }
  380. static av_cold int init(AVFilterContext *ctx)
  381. {
  382. PerspectiveContext *s = ctx->priv;
  383. switch (s->interpolation) {
  384. case LINEAR: s->perspective = resample_linear; break;
  385. case CUBIC: s->perspective = resample_cubic; break;
  386. }
  387. return 0;
  388. }
  389. static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
  390. {
  391. AVFilterContext *ctx = inlink->dst;
  392. AVFilterLink *outlink = ctx->outputs[0];
  393. PerspectiveContext *s = ctx->priv;
  394. AVFrame *out;
  395. int plane;
  396. int ret;
  397. out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
  398. if (!out) {
  399. av_frame_free(&frame);
  400. return AVERROR(ENOMEM);
  401. }
  402. av_frame_copy_props(out, frame);
  403. if (s->eval_mode == EVAL_MODE_FRAME) {
  404. if ((ret = calc_persp_luts(ctx, inlink)) < 0) {
  405. av_frame_free(&out);
  406. return ret;
  407. }
  408. }
  409. for (plane = 0; plane < s->nb_planes; plane++) {
  410. int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
  411. int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
  412. ThreadData td = {.dst = out->data[plane],
  413. .dst_linesize = out->linesize[plane],
  414. .src = frame->data[plane],
  415. .src_linesize = frame->linesize[plane],
  416. .w = s->linesize[plane],
  417. .h = s->height[plane],
  418. .hsub = hsub,
  419. .vsub = vsub };
  420. ctx->internal->execute(ctx, s->perspective, &td, NULL, FFMIN(td.h, ff_filter_get_nb_threads(ctx)));
  421. }
  422. av_frame_free(&frame);
  423. return ff_filter_frame(outlink, out);
  424. }
  425. static av_cold void uninit(AVFilterContext *ctx)
  426. {
  427. PerspectiveContext *s = ctx->priv;
  428. av_freep(&s->pv);
  429. }
  430. static const AVFilterPad perspective_inputs[] = {
  431. {
  432. .name = "default",
  433. .type = AVMEDIA_TYPE_VIDEO,
  434. .filter_frame = filter_frame,
  435. .config_props = config_input,
  436. },
  437. { NULL }
  438. };
  439. static const AVFilterPad perspective_outputs[] = {
  440. {
  441. .name = "default",
  442. .type = AVMEDIA_TYPE_VIDEO,
  443. },
  444. { NULL }
  445. };
  446. AVFilter ff_vf_perspective = {
  447. .name = "perspective",
  448. .description = NULL_IF_CONFIG_SMALL("Correct the perspective of video."),
  449. .priv_size = sizeof(PerspectiveContext),
  450. .init = init,
  451. .uninit = uninit,
  452. .query_formats = query_formats,
  453. .inputs = perspective_inputs,
  454. .outputs = perspective_outputs,
  455. .priv_class = &perspective_class,
  456. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
  457. };