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.

583 lines
19KB

  1. /*
  2. * Copyright (c) 2017 Paul B Mahol
  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. #include "libavutil/imgutils.h"
  21. #include "libavutil/opt.h"
  22. #include "libavutil/pixdesc.h"
  23. #include "libavcodec/avfft.h"
  24. #include "avfilter.h"
  25. #include "formats.h"
  26. #include "framesync.h"
  27. #include "internal.h"
  28. #include "video.h"
  29. #define MAX_THREADS 16
  30. typedef struct ConvolveContext {
  31. const AVClass *class;
  32. FFFrameSync fs;
  33. FFTContext *fft[4][MAX_THREADS];
  34. FFTContext *ifft[4][MAX_THREADS];
  35. int fft_bits[4];
  36. int fft_len[4];
  37. int planewidth[4];
  38. int planeheight[4];
  39. FFTComplex *fft_hdata[4];
  40. FFTComplex *fft_vdata[4];
  41. FFTComplex *fft_hdata_impulse[4];
  42. FFTComplex *fft_vdata_impulse[4];
  43. int depth;
  44. int planes;
  45. int impulse;
  46. int nb_planes;
  47. int got_impulse[4];
  48. } ConvolveContext;
  49. #define OFFSET(x) offsetof(ConvolveContext, x)
  50. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  51. static const AVOption convolve_options[] = {
  52. { "planes", "set planes to convolve", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=7}, 0, 15, FLAGS },
  53. { "impulse", "when to process impulses", OFFSET(impulse), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "impulse" },
  54. { "first", "process only first impulse, ignore rest", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "impulse" },
  55. { "all", "process all impulses", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "impulse" },
  56. { NULL },
  57. };
  58. FRAMESYNC_DEFINE_CLASS(convolve, ConvolveContext, fs);
  59. static int query_formats(AVFilterContext *ctx)
  60. {
  61. static const enum AVPixelFormat pixel_fmts_fftfilt[] = {
  62. AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
  63. AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P,
  64. AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV420P,
  65. AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
  66. AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
  67. AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
  68. AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
  69. AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV440P12,
  70. AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
  71. AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
  72. AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9,
  73. AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
  74. AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
  75. AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
  76. AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
  77. AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
  78. AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY16,
  79. AV_PIX_FMT_NONE
  80. };
  81. AVFilterFormats *fmts_list = ff_make_format_list(pixel_fmts_fftfilt);
  82. if (!fmts_list)
  83. return AVERROR(ENOMEM);
  84. return ff_set_common_formats(ctx, fmts_list);
  85. }
  86. static int config_input_main(AVFilterLink *inlink)
  87. {
  88. ConvolveContext *s = inlink->dst->priv;
  89. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  90. int fft_bits, i;
  91. s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
  92. s->planewidth[0] = s->planewidth[3] = inlink->w;
  93. s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
  94. s->planeheight[0] = s->planeheight[3] = inlink->h;
  95. s->nb_planes = desc->nb_components;
  96. s->depth = desc->comp[0].depth;
  97. for (i = 0; i < s->nb_planes; i++) {
  98. int w = s->planewidth[i];
  99. int h = s->planeheight[i];
  100. int n = FFMAX(w, h);
  101. for (fft_bits = 1; 1 << fft_bits < n; fft_bits++);
  102. s->fft_bits[i] = fft_bits;
  103. s->fft_len[i] = 1 << s->fft_bits[i];
  104. if (!(s->fft_hdata[i] = av_calloc(s->fft_len[i] + 1, s->fft_len[i] * sizeof(FFTComplex))))
  105. return AVERROR(ENOMEM);
  106. if (!(s->fft_vdata[i] = av_calloc(s->fft_len[i] + 1, s->fft_len[i] * sizeof(FFTComplex))))
  107. return AVERROR(ENOMEM);
  108. if (!(s->fft_hdata_impulse[i] = av_calloc(s->fft_len[i] + 1, s->fft_len[i] * sizeof(FFTComplex))))
  109. return AVERROR(ENOMEM);
  110. if (!(s->fft_vdata_impulse[i] = av_calloc(s->fft_len[i] + 1, s->fft_len[i] * sizeof(FFTComplex))))
  111. return AVERROR(ENOMEM);
  112. }
  113. return 0;
  114. }
  115. static int config_input_impulse(AVFilterLink *inlink)
  116. {
  117. AVFilterContext *ctx = inlink->dst;
  118. if (ctx->inputs[0]->w != ctx->inputs[1]->w ||
  119. ctx->inputs[0]->h != ctx->inputs[1]->h) {
  120. av_log(ctx, AV_LOG_ERROR, "Width and height of input videos must be same.\n");
  121. return AVERROR(EINVAL);
  122. }
  123. if (ctx->inputs[0]->format != ctx->inputs[1]->format) {
  124. av_log(ctx, AV_LOG_ERROR, "Inputs must be of same pixel format.\n");
  125. return AVERROR(EINVAL);
  126. }
  127. return 0;
  128. }
  129. typedef struct ThreadData {
  130. FFTComplex *hdata, *vdata;
  131. int plane, n;
  132. } ThreadData;
  133. static int fft_horizontal(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  134. {
  135. ConvolveContext *s = ctx->priv;
  136. ThreadData *td = arg;
  137. FFTComplex *hdata = td->hdata;
  138. const int plane = td->plane;
  139. const int n = td->n;
  140. int start = (n * jobnr ) / nb_jobs;
  141. int end = (n * (jobnr+1)) / nb_jobs;
  142. int y;
  143. for (y = start; y < end; y++) {
  144. av_fft_permute(s->fft[plane][jobnr], hdata + y * n);
  145. av_fft_calc(s->fft[plane][jobnr], hdata + y * n);
  146. }
  147. return 0;
  148. }
  149. static void get_input(ConvolveContext *s, FFTComplex *fft_hdata,
  150. AVFrame *in, int w, int h, int n, int plane, float scale)
  151. {
  152. const int iw = (n - w) / 2, ih = (n - h) / 2;
  153. int y, x;
  154. if (s->depth == 8) {
  155. for (y = 0; y < h; y++) {
  156. const uint8_t *src = in->data[plane] + in->linesize[plane] * y;
  157. for (x = 0; x < w; x++) {
  158. fft_hdata[(y + ih) * n + iw + x].re = src[x] * scale;
  159. fft_hdata[(y + ih) * n + iw + x].im = 0;
  160. }
  161. for (x = 0; x < iw; x++) {
  162. fft_hdata[(y + ih) * n + x].re = fft_hdata[(y + ih) * n + iw].re;
  163. fft_hdata[(y + ih) * n + x].im = 0;
  164. }
  165. for (x = n - iw; x < n; x++) {
  166. fft_hdata[(y + ih) * n + x].re = fft_hdata[(y + ih) * n + n - iw - 1].re;
  167. fft_hdata[(y + ih) * n + x].im = 0;
  168. }
  169. }
  170. for (y = 0; y < ih; y++) {
  171. for (x = 0; x < n; x++) {
  172. fft_hdata[y * n + x].re = fft_hdata[ih * n + x].re;
  173. fft_hdata[y * n + x].im = 0;
  174. }
  175. }
  176. for (y = n - ih; y < n; y++) {
  177. for (x = 0; x < n; x++) {
  178. fft_hdata[y * n + x].re = fft_hdata[(n - ih - 1) * n + x].re;
  179. fft_hdata[y * n + x].im = 0;
  180. }
  181. }
  182. } else {
  183. for (y = 0; y < h; y++) {
  184. const uint16_t *src = (const uint16_t *)(in->data[plane] + in->linesize[plane] * y);
  185. for (x = 0; x < w; x++) {
  186. fft_hdata[(y + ih) * n + iw + x].re = src[x] * scale;
  187. fft_hdata[(y + ih) * n + iw + x].im = 0;
  188. }
  189. for (x = 0; x < iw; x++) {
  190. fft_hdata[(y + ih) * n + x].re = fft_hdata[(y + ih) * n + iw].re;
  191. fft_hdata[(y + ih) * n + x].im = 0;
  192. }
  193. for (x = n - iw; x < n; x++) {
  194. fft_hdata[(y + ih) * n + x].re = fft_hdata[(y + ih) * n + n - iw - 1].re;
  195. fft_hdata[(y + ih) * n + x].im = 0;
  196. }
  197. }
  198. for (y = 0; y < ih; y++) {
  199. for (x = 0; x < n; x++) {
  200. fft_hdata[y * n + x].re = fft_hdata[ih * n + x].re;
  201. fft_hdata[y * n + x].im = 0;
  202. }
  203. }
  204. for (y = n - ih; y < n; y++) {
  205. for (x = 0; x < n; x++) {
  206. fft_hdata[y * n + x].re = fft_hdata[(n - ih - 1) * n + x].re;
  207. fft_hdata[y * n + x].im = 0;
  208. }
  209. }
  210. }
  211. }
  212. static int fft_vertical(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  213. {
  214. ConvolveContext *s = ctx->priv;
  215. ThreadData *td = arg;
  216. FFTComplex *hdata = td->hdata;
  217. FFTComplex *vdata = td->vdata;
  218. const int plane = td->plane;
  219. const int n = td->n;
  220. int start = (n * jobnr ) / nb_jobs;
  221. int end = (n * (jobnr+1)) / nb_jobs;
  222. int y, x;
  223. for (y = start; y < end; y++) {
  224. for (x = 0; x < n; x++) {
  225. vdata[y * n + x].re = hdata[x * n + y].re;
  226. vdata[y * n + x].im = hdata[x * n + y].im;
  227. }
  228. av_fft_permute(s->fft[plane][jobnr], vdata + y * n);
  229. av_fft_calc(s->fft[plane][jobnr], vdata + y * n);
  230. }
  231. return 0;
  232. }
  233. static int ifft_vertical(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  234. {
  235. ConvolveContext *s = ctx->priv;
  236. ThreadData *td = arg;
  237. FFTComplex *hdata = td->hdata;
  238. FFTComplex *vdata = td->vdata;
  239. const int plane = td->plane;
  240. const int n = td->n;
  241. int start = (n * jobnr ) / nb_jobs;
  242. int end = (n * (jobnr+1)) / nb_jobs;
  243. int y, x;
  244. for (y = start; y < end; y++) {
  245. av_fft_permute(s->ifft[plane][jobnr], vdata + y * n);
  246. av_fft_calc(s->ifft[plane][jobnr], vdata + y * n);
  247. for (x = 0; x < n; x++) {
  248. hdata[x * n + y].re = vdata[y * n + x].re;
  249. hdata[x * n + y].im = vdata[y * n + x].im;
  250. }
  251. }
  252. return 0;
  253. }
  254. static int ifft_horizontal(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  255. {
  256. ConvolveContext *s = ctx->priv;
  257. ThreadData *td = arg;
  258. FFTComplex *hdata = td->hdata;
  259. const int plane = td->plane;
  260. const int n = td->n;
  261. int start = (n * jobnr ) / nb_jobs;
  262. int end = (n * (jobnr+1)) / nb_jobs;
  263. int y;
  264. for (y = start; y < end; y++) {
  265. av_fft_permute(s->ifft[plane][jobnr], hdata + y * n);
  266. av_fft_calc(s->ifft[plane][jobnr], hdata + y * n);
  267. }
  268. return 0;
  269. }
  270. static void get_output(ConvolveContext *s, AVFrame *out,
  271. int w, int h, int n, int plane)
  272. {
  273. FFTComplex *input = s->fft_hdata[plane];
  274. const float scale = 1.f / (n * n);
  275. const int max = (1 << s->depth) - 1;
  276. const int hh = h / 2;
  277. const int hw = w / 2;
  278. int y, x;
  279. if (s->depth == 8) {
  280. for (y = 0; y < hh; y++) {
  281. uint8_t *dst = out->data[plane] + (y + hh) * out->linesize[plane] + hw;
  282. for (x = 0; x < hw; x++)
  283. dst[x] = av_clip_uint8(input[y * n + x].re * scale);
  284. }
  285. for (y = 0; y < hh; y++) {
  286. uint8_t *dst = out->data[plane] + (y + hh) * out->linesize[plane];
  287. for (x = 0; x < hw; x++)
  288. dst[x] = av_clip_uint8(input[y * n + n - hw + x].re * scale);
  289. }
  290. for (y = 0; y < hh; y++) {
  291. uint8_t *dst = out->data[plane] + y * out->linesize[plane] + hw;
  292. for (x = 0; x < hw; x++)
  293. dst[x] = av_clip_uint8(input[(n - hh + y) * n + x].re * scale);
  294. }
  295. for (y = 0; y < hh; y++) {
  296. uint8_t *dst = out->data[plane] + y * out->linesize[plane];
  297. for (x = 0; x < hw; x++)
  298. dst[x] = av_clip_uint8(input[(n - hh + y) * n + n - hw + x].re * scale);
  299. }
  300. } else {
  301. for (y = 0; y < hh; y++) {
  302. uint16_t *dst = (uint16_t *)(out->data[plane] + (y + hh) * out->linesize[plane] + hw * 2);
  303. for (x = 0; x < hw; x++)
  304. dst[x] = av_clip(input[y * n + x].re * scale, 0, max);
  305. }
  306. for (y = 0; y < hh; y++) {
  307. uint16_t *dst = (uint16_t *)(out->data[plane] + (y + hh) * out->linesize[plane]);
  308. for (x = 0; x < hw; x++)
  309. dst[x] = av_clip(input[y * n + n - hw + x].re * scale, 0, max);
  310. }
  311. for (y = 0; y < hh; y++) {
  312. uint16_t *dst = (uint16_t *)(out->data[plane] + y * out->linesize[plane] + hw * 2);
  313. for (x = 0; x < hw; x++)
  314. dst[x] = av_clip(input[(n - hh + y) * n + x].re * scale, 0, max);
  315. }
  316. for (y = 0; y < hh; y++) {
  317. uint16_t *dst = (uint16_t *)(out->data[plane] + y * out->linesize[plane]);
  318. for (x = 0; x < hw; x++)
  319. dst[x] = av_clip(input[(n - hh + y) * n + n - hw + x].re * scale, 0, max);
  320. }
  321. }
  322. }
  323. static int complex_multiply(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  324. {
  325. ThreadData *td = arg;
  326. FFTComplex *input = td->hdata;
  327. FFTComplex *filter = td->vdata;
  328. const int n = td->n;
  329. int start = (n * jobnr ) / nb_jobs;
  330. int end = (n * (jobnr+1)) / nb_jobs;
  331. int y, x;
  332. for (y = start; y < end; y++) {
  333. int yn = y * n;
  334. for (x = 0; x < n; x++) {
  335. FFTSample re, im, ire, iim;
  336. re = input[yn + x].re;
  337. im = input[yn + x].im;
  338. ire = filter[yn + x].re;
  339. iim = filter[yn + x].im;
  340. input[yn + x].re = ire * re - iim * im;
  341. input[yn + x].im = iim * re + ire * im;
  342. }
  343. }
  344. return 0;
  345. }
  346. static int do_convolve(FFFrameSync *fs)
  347. {
  348. AVFilterContext *ctx = fs->parent;
  349. AVFilterLink *outlink = ctx->outputs[0];
  350. ConvolveContext *s = ctx->priv;
  351. AVFrame *mainpic = NULL, *impulsepic = NULL;
  352. int ret, y, x, plane;
  353. ret = ff_framesync_dualinput_get(fs, &mainpic, &impulsepic);
  354. if (ret < 0)
  355. return ret;
  356. if (!impulsepic)
  357. return ff_filter_frame(outlink, mainpic);
  358. for (plane = 0; plane < s->nb_planes; plane++) {
  359. FFTComplex *filter = s->fft_vdata_impulse[plane];
  360. FFTComplex *input = s->fft_vdata[plane];
  361. const int n = s->fft_len[plane];
  362. const int w = s->planewidth[plane];
  363. const int h = s->planeheight[plane];
  364. float total = 0;
  365. ThreadData td;
  366. if (!(s->planes & (1 << plane))) {
  367. continue;
  368. }
  369. td.plane = plane, td.n = n;
  370. get_input(s, s->fft_hdata[plane], mainpic, w, h, n, plane, 1.f);
  371. td.hdata = s->fft_hdata[plane];
  372. td.vdata = s->fft_vdata[plane];
  373. ctx->internal->execute(ctx, fft_horizontal, &td, NULL, FFMIN3(MAX_THREADS, n, ff_filter_get_nb_threads(ctx)));
  374. ctx->internal->execute(ctx, fft_vertical, &td, NULL, FFMIN3(MAX_THREADS, n, ff_filter_get_nb_threads(ctx)));
  375. if ((!s->impulse && !s->got_impulse[plane]) || s->impulse) {
  376. if (s->depth == 8) {
  377. for (y = 0; y < h; y++) {
  378. const uint8_t *src = (const uint8_t *)(impulsepic->data[plane] + y * impulsepic->linesize[plane]) ;
  379. for (x = 0; x < w; x++) {
  380. total += src[x];
  381. }
  382. }
  383. } else {
  384. for (y = 0; y < h; y++) {
  385. const uint16_t *src = (const uint16_t *)(impulsepic->data[plane] + y * impulsepic->linesize[plane]) ;
  386. for (x = 0; x < w; x++) {
  387. total += src[x];
  388. }
  389. }
  390. }
  391. total = FFMAX(1, total);
  392. get_input(s, s->fft_hdata_impulse[plane], impulsepic, w, h, n, plane, 1 / total);
  393. td.hdata = s->fft_hdata_impulse[plane];
  394. td.vdata = s->fft_vdata_impulse[plane];
  395. ctx->internal->execute(ctx, fft_horizontal, &td, NULL, FFMIN3(MAX_THREADS, n, ff_filter_get_nb_threads(ctx)));
  396. ctx->internal->execute(ctx, fft_vertical, &td, NULL, FFMIN3(MAX_THREADS, n, ff_filter_get_nb_threads(ctx)));
  397. s->got_impulse[plane] = 1;
  398. }
  399. td.hdata = input;
  400. td.vdata = filter;
  401. ctx->internal->execute(ctx, complex_multiply, &td, NULL, FFMIN3(MAX_THREADS, n, ff_filter_get_nb_threads(ctx)));
  402. td.hdata = s->fft_hdata[plane];
  403. td.vdata = s->fft_vdata[plane];
  404. ctx->internal->execute(ctx, ifft_vertical, &td, NULL, FFMIN3(MAX_THREADS, n, ff_filter_get_nb_threads(ctx)));
  405. ctx->internal->execute(ctx, ifft_horizontal, &td, NULL, FFMIN3(MAX_THREADS, n, ff_filter_get_nb_threads(ctx)));
  406. get_output(s, mainpic, w, h, n, plane);
  407. }
  408. return ff_filter_frame(outlink, mainpic);
  409. }
  410. static int config_output(AVFilterLink *outlink)
  411. {
  412. AVFilterContext *ctx = outlink->src;
  413. ConvolveContext *s = ctx->priv;
  414. AVFilterLink *mainlink = ctx->inputs[0];
  415. int ret, i, j;
  416. s->fs.on_event = do_convolve;
  417. ret = ff_framesync_init_dualinput(&s->fs, ctx);
  418. if (ret < 0)
  419. return ret;
  420. outlink->w = mainlink->w;
  421. outlink->h = mainlink->h;
  422. outlink->time_base = mainlink->time_base;
  423. outlink->sample_aspect_ratio = mainlink->sample_aspect_ratio;
  424. outlink->frame_rate = mainlink->frame_rate;
  425. if ((ret = ff_framesync_configure(&s->fs)) < 0)
  426. return ret;
  427. for (i = 0; i < s->nb_planes; i++) {
  428. for (j = 0; j < MAX_THREADS; j++) {
  429. s->fft[i][j] = av_fft_init(s->fft_bits[i], 0);
  430. s->ifft[i][j] = av_fft_init(s->fft_bits[i], 1);
  431. if (!s->fft[i][j] || !s->ifft[i][j])
  432. return AVERROR(ENOMEM);
  433. }
  434. }
  435. return 0;
  436. }
  437. static int activate(AVFilterContext *ctx)
  438. {
  439. ConvolveContext *s = ctx->priv;
  440. return ff_framesync_activate(&s->fs);
  441. }
  442. static av_cold void uninit(AVFilterContext *ctx)
  443. {
  444. ConvolveContext *s = ctx->priv;
  445. int i, j;
  446. for (i = 0; i < 4; i++) {
  447. av_freep(&s->fft_hdata[i]);
  448. av_freep(&s->fft_vdata[i]);
  449. av_freep(&s->fft_hdata_impulse[i]);
  450. av_freep(&s->fft_vdata_impulse[i]);
  451. for (j = 0; j < MAX_THREADS; j++) {
  452. av_fft_end(s->fft[i][j]);
  453. av_fft_end(s->ifft[i][j]);
  454. }
  455. }
  456. ff_framesync_uninit(&s->fs);
  457. }
  458. static const AVFilterPad convolve_inputs[] = {
  459. {
  460. .name = "main",
  461. .type = AVMEDIA_TYPE_VIDEO,
  462. .config_props = config_input_main,
  463. },{
  464. .name = "impulse",
  465. .type = AVMEDIA_TYPE_VIDEO,
  466. .config_props = config_input_impulse,
  467. },
  468. { NULL }
  469. };
  470. static const AVFilterPad convolve_outputs[] = {
  471. {
  472. .name = "default",
  473. .type = AVMEDIA_TYPE_VIDEO,
  474. .config_props = config_output,
  475. },
  476. { NULL }
  477. };
  478. AVFilter ff_vf_convolve = {
  479. .name = "convolve",
  480. .description = NULL_IF_CONFIG_SMALL("Convolve first video stream with second video stream."),
  481. .preinit = convolve_framesync_preinit,
  482. .uninit = uninit,
  483. .query_formats = query_formats,
  484. .activate = activate,
  485. .priv_size = sizeof(ConvolveContext),
  486. .priv_class = &convolve_class,
  487. .inputs = convolve_inputs,
  488. .outputs = convolve_outputs,
  489. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
  490. };