vf_bwdif.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /*
  2. * BobWeaver Deinterlacing Filter
  3. * Copyright (C) 2016 Thomas Mundt <loudmax@yahoo.de>
  4. *
  5. * Based on YADIF (Yet Another Deinterlacing Filter)
  6. * Copyright (C) 2006-2011 Michael Niedermayer <michaelni@gmx.at>
  7. * 2010 James Darnley <james.darnley@gmail.com>
  8. *
  9. * With use of Weston 3 Field Deinterlacing Filter algorithm
  10. * Copyright (C) 2012 British Broadcasting Corporation, All Rights Reserved
  11. * Author of de-interlace algorithm: Jim Easterbrook for BBC R&D
  12. * Based on the process described by Martin Weston for BBC R&D
  13. *
  14. * This file is part of FFmpeg.
  15. *
  16. * FFmpeg is free software; you can redistribute it and/or
  17. * modify it under the terms of the GNU Lesser General Public
  18. * License as published by the Free Software Foundation; either
  19. * version 2.1 of the License, or (at your option) any later version.
  20. *
  21. * FFmpeg is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. * Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public
  27. * License along with FFmpeg; if not, write to the Free Software
  28. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  29. */
  30. #include "libavutil/avassert.h"
  31. #include "libavutil/common.h"
  32. #include "libavutil/opt.h"
  33. #include "libavutil/pixdesc.h"
  34. #include "libavutil/imgutils.h"
  35. #include "avfilter.h"
  36. #include "formats.h"
  37. #include "internal.h"
  38. #include "video.h"
  39. #include "bwdif.h"
  40. /*
  41. * Filter coefficients coef_lf and coef_hf taken from BBC PH-2071 (Weston 3 Field Deinterlacer).
  42. * Used when there is spatial and temporal interpolation.
  43. * Filter coefficients coef_sp are used when there is spatial interpolation only.
  44. * Adjusted for matching visual sharpness impression of spatial and temporal interpolation.
  45. */
  46. static const uint16_t coef_lf[2] = { 4309, 213 };
  47. static const uint16_t coef_hf[3] = { 5570, 3801, 1016 };
  48. static const uint16_t coef_sp[2] = { 5077, 981 };
  49. typedef struct ThreadData {
  50. AVFrame *frame;
  51. int plane;
  52. int w, h;
  53. int parity;
  54. int tff;
  55. } ThreadData;
  56. #define FILTER_INTRA() \
  57. for (x = 0; x < w; x++) { \
  58. interpol = (coef_sp[0] * (cur[mrefs] + cur[prefs]) - coef_sp[1] * (cur[mrefs3] + cur[prefs3])) >> 13; \
  59. dst[0] = av_clip(interpol, 0, clip_max); \
  60. \
  61. dst++; \
  62. cur++; \
  63. }
  64. #define FILTER1() \
  65. for (x = 0; x < w; x++) { \
  66. int c = cur[mrefs]; \
  67. int d = (prev2[0] + next2[0]) >> 1; \
  68. int e = cur[prefs]; \
  69. int temporal_diff0 = FFABS(prev2[0] - next2[0]); \
  70. int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e)) >> 1; \
  71. int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e)) >> 1; \
  72. int diff = FFMAX3(temporal_diff0 >> 1, temporal_diff1, temporal_diff2); \
  73. \
  74. if (!diff) { \
  75. dst[0] = d; \
  76. } else {
  77. #define SPAT_CHECK() \
  78. int b = ((prev2[mrefs2] + next2[mrefs2]) >> 1) - c; \
  79. int f = ((prev2[prefs2] + next2[prefs2]) >> 1) - e; \
  80. int dc = d - c; \
  81. int de = d - e; \
  82. int max = FFMAX3(de, dc, FFMIN(b, f)); \
  83. int min = FFMIN3(de, dc, FFMAX(b, f)); \
  84. diff = FFMAX3(diff, min, -max);
  85. #define FILTER_LINE() \
  86. SPAT_CHECK() \
  87. if (FFABS(c - e) > temporal_diff0) { \
  88. interpol = (((coef_hf[0] * (prev2[0] + next2[0]) \
  89. - coef_hf[1] * (prev2[mrefs2] + next2[mrefs2] + prev2[prefs2] + next2[prefs2]) \
  90. + coef_hf[2] * (prev2[mrefs4] + next2[mrefs4] + prev2[prefs4] + next2[prefs4])) >> 2) \
  91. + coef_lf[0] * (c + e) - coef_lf[1] * (cur[mrefs3] + cur[prefs3])) >> 13; \
  92. } else { \
  93. interpol = (coef_sp[0] * (c + e) - coef_sp[1] * (cur[mrefs3] + cur[prefs3])) >> 13; \
  94. }
  95. #define FILTER_EDGE() \
  96. if (spat) { \
  97. SPAT_CHECK() \
  98. } \
  99. interpol = (c + e) >> 1;
  100. #define FILTER2() \
  101. if (interpol > d + diff) \
  102. interpol = d + diff; \
  103. else if (interpol < d - diff) \
  104. interpol = d - diff; \
  105. \
  106. dst[0] = av_clip(interpol, 0, clip_max); \
  107. } \
  108. \
  109. dst++; \
  110. cur++; \
  111. prev++; \
  112. next++; \
  113. prev2++; \
  114. next2++; \
  115. }
  116. static void filter_intra(void *dst1, void *cur1, int w, int prefs, int mrefs,
  117. int prefs3, int mrefs3, int parity, int clip_max)
  118. {
  119. uint8_t *dst = dst1;
  120. uint8_t *cur = cur1;
  121. int interpol, x;
  122. FILTER_INTRA()
  123. }
  124. static void filter_line_c(void *dst1, void *prev1, void *cur1, void *next1,
  125. int w, int prefs, int mrefs, int prefs2, int mrefs2,
  126. int prefs3, int mrefs3, int prefs4, int mrefs4,
  127. int parity, int clip_max)
  128. {
  129. uint8_t *dst = dst1;
  130. uint8_t *prev = prev1;
  131. uint8_t *cur = cur1;
  132. uint8_t *next = next1;
  133. uint8_t *prev2 = parity ? prev : cur ;
  134. uint8_t *next2 = parity ? cur : next;
  135. int interpol, x;
  136. FILTER1()
  137. FILTER_LINE()
  138. FILTER2()
  139. }
  140. static void filter_edge(void *dst1, void *prev1, void *cur1, void *next1,
  141. int w, int prefs, int mrefs, int prefs2, int mrefs2,
  142. int parity, int clip_max, int spat)
  143. {
  144. uint8_t *dst = dst1;
  145. uint8_t *prev = prev1;
  146. uint8_t *cur = cur1;
  147. uint8_t *next = next1;
  148. uint8_t *prev2 = parity ? prev : cur ;
  149. uint8_t *next2 = parity ? cur : next;
  150. int interpol, x;
  151. FILTER1()
  152. FILTER_EDGE()
  153. FILTER2()
  154. }
  155. static void filter_intra_16bit(void *dst1, void *cur1, int w, int prefs, int mrefs,
  156. int prefs3, int mrefs3, int parity, int clip_max)
  157. {
  158. uint16_t *dst = dst1;
  159. uint16_t *cur = cur1;
  160. int interpol, x;
  161. FILTER_INTRA()
  162. }
  163. static void filter_line_c_16bit(void *dst1, void *prev1, void *cur1, void *next1,
  164. int w, int prefs, int mrefs, int prefs2, int mrefs2,
  165. int prefs3, int mrefs3, int prefs4, int mrefs4,
  166. int parity, int clip_max)
  167. {
  168. uint16_t *dst = dst1;
  169. uint16_t *prev = prev1;
  170. uint16_t *cur = cur1;
  171. uint16_t *next = next1;
  172. uint16_t *prev2 = parity ? prev : cur ;
  173. uint16_t *next2 = parity ? cur : next;
  174. int interpol, x;
  175. FILTER1()
  176. FILTER_LINE()
  177. FILTER2()
  178. }
  179. static void filter_edge_16bit(void *dst1, void *prev1, void *cur1, void *next1,
  180. int w, int prefs, int mrefs, int prefs2, int mrefs2,
  181. int parity, int clip_max, int spat)
  182. {
  183. uint16_t *dst = dst1;
  184. uint16_t *prev = prev1;
  185. uint16_t *cur = cur1;
  186. uint16_t *next = next1;
  187. uint16_t *prev2 = parity ? prev : cur ;
  188. uint16_t *next2 = parity ? cur : next;
  189. int interpol, x;
  190. FILTER1()
  191. FILTER_EDGE()
  192. FILTER2()
  193. }
  194. static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
  195. {
  196. BWDIFContext *s = ctx->priv;
  197. ThreadData *td = arg;
  198. int linesize = s->cur->linesize[td->plane];
  199. int clip_max = (1 << (s->csp->comp[td->plane].depth)) - 1;
  200. int df = (s->csp->comp[td->plane].depth + 7) / 8;
  201. int refs = linesize / df;
  202. int slice_start = (td->h * jobnr ) / nb_jobs;
  203. int slice_end = (td->h * (jobnr+1)) / nb_jobs;
  204. int y;
  205. for (y = slice_start; y < slice_end; y++) {
  206. if ((y ^ td->parity) & 1) {
  207. uint8_t *prev = &s->prev->data[td->plane][y * linesize];
  208. uint8_t *cur = &s->cur ->data[td->plane][y * linesize];
  209. uint8_t *next = &s->next->data[td->plane][y * linesize];
  210. uint8_t *dst = &td->frame->data[td->plane][y * td->frame->linesize[td->plane]];
  211. if (!s->inter_field) {
  212. s->filter_intra(dst, cur, td->w, (y + df) < td->h ? refs : -refs,
  213. y > (df - 1) ? -refs : refs,
  214. (y + 3*df) < td->h ? 3 * refs : -refs,
  215. y > (3*df - 1) ? -3 * refs : refs,
  216. td->parity ^ td->tff, clip_max);
  217. } else if ((y < 4) || ((y + 5) > td->h)) {
  218. s->filter_edge(dst, prev, cur, next, td->w,
  219. (y + df) < td->h ? refs : -refs,
  220. y > (df - 1) ? -refs : refs,
  221. refs << 1, -(refs << 1),
  222. td->parity ^ td->tff, clip_max,
  223. (y < 2) || ((y + 3) > td->h) ? 0 : 1);
  224. } else {
  225. s->filter_line(dst, prev, cur, next, td->w,
  226. refs, -refs, refs << 1, -(refs << 1),
  227. 3 * refs, -3 * refs, refs << 2, -(refs << 2),
  228. td->parity ^ td->tff, clip_max);
  229. }
  230. } else {
  231. memcpy(&td->frame->data[td->plane][y * td->frame->linesize[td->plane]],
  232. &s->cur->data[td->plane][y * linesize], td->w * df);
  233. }
  234. }
  235. return 0;
  236. }
  237. static void filter(AVFilterContext *ctx, AVFrame *dstpic,
  238. int parity, int tff)
  239. {
  240. BWDIFContext *bwdif = ctx->priv;
  241. ThreadData td = { .frame = dstpic, .parity = parity, .tff = tff };
  242. int i;
  243. for (i = 0; i < bwdif->csp->nb_components; i++) {
  244. int w = dstpic->width;
  245. int h = dstpic->height;
  246. if (i == 1 || i == 2) {
  247. w = AV_CEIL_RSHIFT(w, bwdif->csp->log2_chroma_w);
  248. h = AV_CEIL_RSHIFT(h, bwdif->csp->log2_chroma_h);
  249. }
  250. td.w = w;
  251. td.h = h;
  252. td.plane = i;
  253. ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(h, ctx->graph->nb_threads));
  254. }
  255. if (!bwdif->inter_field) {
  256. bwdif->inter_field = 1;
  257. }
  258. emms_c();
  259. }
  260. static int return_frame(AVFilterContext *ctx, int is_second)
  261. {
  262. BWDIFContext *bwdif = ctx->priv;
  263. AVFilterLink *link = ctx->outputs[0];
  264. int tff, ret;
  265. if (bwdif->parity == -1) {
  266. tff = bwdif->cur->interlaced_frame ?
  267. bwdif->cur->top_field_first : 1;
  268. } else {
  269. tff = bwdif->parity ^ 1;
  270. }
  271. if (is_second) {
  272. bwdif->out = ff_get_video_buffer(link, link->w, link->h);
  273. if (!bwdif->out)
  274. return AVERROR(ENOMEM);
  275. av_frame_copy_props(bwdif->out, bwdif->cur);
  276. bwdif->out->interlaced_frame = 0;
  277. if (bwdif->inter_field < 0)
  278. bwdif->inter_field = 0;
  279. }
  280. filter(ctx, bwdif->out, tff ^ !is_second, tff);
  281. if (is_second) {
  282. int64_t cur_pts = bwdif->cur->pts;
  283. int64_t next_pts = bwdif->next->pts;
  284. if (next_pts != AV_NOPTS_VALUE && cur_pts != AV_NOPTS_VALUE) {
  285. bwdif->out->pts = cur_pts + next_pts;
  286. } else {
  287. bwdif->out->pts = AV_NOPTS_VALUE;
  288. }
  289. }
  290. ret = ff_filter_frame(ctx->outputs[0], bwdif->out);
  291. bwdif->frame_pending = (bwdif->mode&1) && !is_second;
  292. return ret;
  293. }
  294. static int checkstride(BWDIFContext *bwdif, const AVFrame *a, const AVFrame *b)
  295. {
  296. int i;
  297. for (i = 0; i < bwdif->csp->nb_components; i++)
  298. if (a->linesize[i] != b->linesize[i])
  299. return 1;
  300. return 0;
  301. }
  302. static void fixstride(AVFilterLink *link, AVFrame *f)
  303. {
  304. AVFrame *dst = ff_default_get_video_buffer(link, f->width, f->height);
  305. if(!dst)
  306. return;
  307. av_frame_copy_props(dst, f);
  308. av_image_copy(dst->data, dst->linesize,
  309. (const uint8_t **)f->data, f->linesize,
  310. dst->format, dst->width, dst->height);
  311. av_frame_unref(f);
  312. av_frame_move_ref(f, dst);
  313. av_frame_free(&dst);
  314. }
  315. static int filter_frame(AVFilterLink *link, AVFrame *frame)
  316. {
  317. AVFilterContext *ctx = link->dst;
  318. BWDIFContext *bwdif = ctx->priv;
  319. av_assert0(frame);
  320. if (bwdif->frame_pending)
  321. return_frame(ctx, 1);
  322. if (bwdif->prev)
  323. av_frame_free(&bwdif->prev);
  324. bwdif->prev = bwdif->cur;
  325. bwdif->cur = bwdif->next;
  326. bwdif->next = frame;
  327. if (!bwdif->cur) {
  328. bwdif->cur = av_frame_clone(bwdif->next);
  329. if (!bwdif->cur)
  330. return AVERROR(ENOMEM);
  331. bwdif->inter_field = 0;
  332. }
  333. if (checkstride(bwdif, bwdif->next, bwdif->cur)) {
  334. av_log(ctx, AV_LOG_VERBOSE, "Reallocating frame due to differing stride\n");
  335. fixstride(link, bwdif->next);
  336. }
  337. if (checkstride(bwdif, bwdif->next, bwdif->cur))
  338. fixstride(link, bwdif->cur);
  339. if (bwdif->prev && checkstride(bwdif, bwdif->next, bwdif->prev))
  340. fixstride(link, bwdif->prev);
  341. if (checkstride(bwdif, bwdif->next, bwdif->cur) || (bwdif->prev && checkstride(bwdif, bwdif->next, bwdif->prev))) {
  342. av_log(ctx, AV_LOG_ERROR, "Failed to reallocate frame\n");
  343. return -1;
  344. }
  345. if (!bwdif->prev)
  346. return 0;
  347. if ((bwdif->deint && !bwdif->cur->interlaced_frame) ||
  348. ctx->is_disabled ||
  349. (bwdif->deint && !bwdif->prev->interlaced_frame && bwdif->prev->repeat_pict) ||
  350. (bwdif->deint && !bwdif->next->interlaced_frame && bwdif->next->repeat_pict)
  351. ) {
  352. bwdif->out = av_frame_clone(bwdif->cur);
  353. if (!bwdif->out)
  354. return AVERROR(ENOMEM);
  355. av_frame_free(&bwdif->prev);
  356. if (bwdif->out->pts != AV_NOPTS_VALUE)
  357. bwdif->out->pts *= 2;
  358. return ff_filter_frame(ctx->outputs[0], bwdif->out);
  359. }
  360. bwdif->out = ff_get_video_buffer(ctx->outputs[0], link->w, link->h);
  361. if (!bwdif->out)
  362. return AVERROR(ENOMEM);
  363. av_frame_copy_props(bwdif->out, bwdif->cur);
  364. bwdif->out->interlaced_frame = 0;
  365. if (bwdif->out->pts != AV_NOPTS_VALUE)
  366. bwdif->out->pts *= 2;
  367. return return_frame(ctx, 0);
  368. }
  369. static int request_frame(AVFilterLink *link)
  370. {
  371. AVFilterContext *ctx = link->src;
  372. BWDIFContext *bwdif = ctx->priv;
  373. int ret;
  374. if (bwdif->frame_pending) {
  375. return_frame(ctx, 1);
  376. return 0;
  377. }
  378. if (bwdif->eof)
  379. return AVERROR_EOF;
  380. ret = ff_request_frame(link->src->inputs[0]);
  381. if (ret == AVERROR_EOF && bwdif->cur) {
  382. AVFrame *next = av_frame_clone(bwdif->next);
  383. if (!next)
  384. return AVERROR(ENOMEM);
  385. bwdif->inter_field = -1;
  386. next->pts = bwdif->next->pts * 2 - bwdif->cur->pts;
  387. filter_frame(link->src->inputs[0], next);
  388. bwdif->eof = 1;
  389. } else if (ret < 0) {
  390. return ret;
  391. }
  392. return 0;
  393. }
  394. static av_cold void uninit(AVFilterContext *ctx)
  395. {
  396. BWDIFContext *bwdif = ctx->priv;
  397. av_frame_free(&bwdif->prev);
  398. av_frame_free(&bwdif->cur );
  399. av_frame_free(&bwdif->next);
  400. }
  401. static int query_formats(AVFilterContext *ctx)
  402. {
  403. static const enum AVPixelFormat pix_fmts[] = {
  404. AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV420P,
  405. AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
  406. AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
  407. AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P,
  408. AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
  409. AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
  410. AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12,
  411. AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
  412. AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
  413. AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P,
  414. AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9,
  415. AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
  416. AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
  417. AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
  418. AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
  419. AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP16,
  420. AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16,
  421. AV_PIX_FMT_NONE
  422. };
  423. AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
  424. if (!fmts_list)
  425. return AVERROR(ENOMEM);
  426. return ff_set_common_formats(ctx, fmts_list);
  427. }
  428. static int config_props(AVFilterLink *link)
  429. {
  430. AVFilterContext *ctx = link->src;
  431. BWDIFContext *s = link->src->priv;
  432. link->time_base.num = link->src->inputs[0]->time_base.num;
  433. link->time_base.den = link->src->inputs[0]->time_base.den * 2;
  434. link->w = link->src->inputs[0]->w;
  435. link->h = link->src->inputs[0]->h;
  436. if(s->mode&1)
  437. link->frame_rate = av_mul_q(link->src->inputs[0]->frame_rate, (AVRational){2,1});
  438. if (link->w < 3 || link->h < 3) {
  439. av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
  440. return AVERROR(EINVAL);
  441. }
  442. s->csp = av_pix_fmt_desc_get(link->format);
  443. if (s->csp->comp[0].depth > 8) {
  444. s->filter_intra = filter_intra_16bit;
  445. s->filter_line = filter_line_c_16bit;
  446. s->filter_edge = filter_edge_16bit;
  447. } else {
  448. s->filter_intra = filter_intra;
  449. s->filter_line = filter_line_c;
  450. s->filter_edge = filter_edge;
  451. }
  452. if (ARCH_X86)
  453. ff_bwdif_init_x86(s);
  454. return 0;
  455. }
  456. #define OFFSET(x) offsetof(BWDIFContext, x)
  457. #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
  458. #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }
  459. static const AVOption bwdif_options[] = {
  460. { "mode", "specify the interlacing mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=BWDIF_MODE_SEND_FIELD}, 0, 1, FLAGS, "mode"},
  461. CONST("send_frame", "send one frame for each frame", BWDIF_MODE_SEND_FRAME, "mode"),
  462. CONST("send_field", "send one frame for each field", BWDIF_MODE_SEND_FIELD, "mode"),
  463. { "parity", "specify the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=BWDIF_PARITY_AUTO}, -1, 1, FLAGS, "parity" },
  464. CONST("tff", "assume top field first", BWDIF_PARITY_TFF, "parity"),
  465. CONST("bff", "assume bottom field first", BWDIF_PARITY_BFF, "parity"),
  466. CONST("auto", "auto detect parity", BWDIF_PARITY_AUTO, "parity"),
  467. { "deint", "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=BWDIF_DEINT_ALL}, 0, 1, FLAGS, "deint" },
  468. CONST("all", "deinterlace all frames", BWDIF_DEINT_ALL, "deint"),
  469. CONST("interlaced", "only deinterlace frames marked as interlaced", BWDIF_DEINT_INTERLACED, "deint"),
  470. { NULL }
  471. };
  472. AVFILTER_DEFINE_CLASS(bwdif);
  473. static const AVFilterPad avfilter_vf_bwdif_inputs[] = {
  474. {
  475. .name = "default",
  476. .type = AVMEDIA_TYPE_VIDEO,
  477. .filter_frame = filter_frame,
  478. },
  479. { NULL }
  480. };
  481. static const AVFilterPad avfilter_vf_bwdif_outputs[] = {
  482. {
  483. .name = "default",
  484. .type = AVMEDIA_TYPE_VIDEO,
  485. .request_frame = request_frame,
  486. .config_props = config_props,
  487. },
  488. { NULL }
  489. };
  490. AVFilter ff_vf_bwdif = {
  491. .name = "bwdif",
  492. .description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."),
  493. .priv_size = sizeof(BWDIFContext),
  494. .priv_class = &bwdif_class,
  495. .uninit = uninit,
  496. .query_formats = query_formats,
  497. .inputs = avfilter_vf_bwdif_inputs,
  498. .outputs = avfilter_vf_bwdif_outputs,
  499. .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
  500. };