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.

480 lines
19KB

  1. /*
  2. * Copyright (c) 2010 Gordon Schmidt <gordon.schmidt <at> s2000.tu-chemnitz.de>
  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/imgutils.h"
  23. #include "libavutil/opt.h"
  24. #include "libavutil/parseutils.h"
  25. #include "libavutil/pixdesc.h"
  26. #include "avfilter.h"
  27. #include "formats.h"
  28. #include "internal.h"
  29. #include "video.h"
  30. enum StereoCode {
  31. ANAGLYPH_RC_GRAY, // anaglyph red/cyan gray
  32. ANAGLYPH_RC_HALF, // anaglyph red/cyan half colored
  33. ANAGLYPH_RC_COLOR, // anaglyph red/cyan colored
  34. ANAGLYPH_RC_DUBOIS, // anaglyph red/cyan dubois
  35. ANAGLYPH_GM_GRAY, // anaglyph green/magenta gray
  36. ANAGLYPH_GM_HALF, // anaglyph green/magenta half colored
  37. ANAGLYPH_GM_COLOR, // anaglyph green/magenta colored
  38. ANAGLYPH_GM_DUBOIS, // anaglyph green/magenta dubois
  39. ANAGLYPH_YB_GRAY, // anaglyph yellow/blue gray
  40. ANAGLYPH_YB_HALF, // anaglyph yellow/blue half colored
  41. ANAGLYPH_YB_COLOR, // anaglyph yellow/blue colored
  42. ANAGLYPH_YB_DUBOIS, // anaglyph yellow/blue dubois
  43. ANAGLYPH_RB_GRAY, // anaglyph red/blue gray
  44. ANAGLYPH_RG_GRAY, // anaglyph red/green gray
  45. MONO_L, // mono output for debugging (left eye only)
  46. MONO_R, // mono output for debugging (right eye only)
  47. INTERLEAVE_ROWS_LR, // row-interleave (left eye has top row)
  48. INTERLEAVE_ROWS_RL, // row-interleave (right eye has top row)
  49. SIDE_BY_SIDE_LR, // side by side parallel (left eye left, right eye right)
  50. SIDE_BY_SIDE_RL, // side by side crosseye (right eye left, left eye right)
  51. SIDE_BY_SIDE_2_LR, // side by side parallel with half width resolution
  52. SIDE_BY_SIDE_2_RL, // side by side crosseye with half width resolution
  53. ABOVE_BELOW_LR, // above-below (left eye above, right eye below)
  54. ABOVE_BELOW_RL, // above-below (right eye above, left eye below)
  55. ABOVE_BELOW_2_LR, // above-below with half height resolution
  56. ABOVE_BELOW_2_RL, // above-below with half height resolution
  57. STEREO_CODE_COUNT // TODO: needs autodetection
  58. };
  59. typedef struct StereoComponent {
  60. enum StereoCode format;
  61. int width, height;
  62. int off_left, off_right;
  63. int row_left, row_right;
  64. } StereoComponent;
  65. static const int ana_coeff[][3][6] = {
  66. [ANAGLYPH_RB_GRAY] =
  67. {{19595, 38470, 7471, 0, 0, 0},
  68. { 0, 0, 0, 0, 0, 0},
  69. { 0, 0, 0, 19595, 38470, 7471}},
  70. [ANAGLYPH_RG_GRAY] =
  71. {{19595, 38470, 7471, 0, 0, 0},
  72. { 0, 0, 0, 19595, 38470, 7471},
  73. { 0, 0, 0, 0, 0, 0}},
  74. [ANAGLYPH_RC_GRAY] =
  75. {{19595, 38470, 7471, 0, 0, 0},
  76. { 0, 0, 0, 19595, 38470, 7471},
  77. { 0, 0, 0, 19595, 38470, 7471}},
  78. [ANAGLYPH_RC_HALF] =
  79. {{19595, 38470, 7471, 0, 0, 0},
  80. { 0, 0, 0, 0, 65536, 0},
  81. { 0, 0, 0, 0, 0, 65536}},
  82. [ANAGLYPH_RC_COLOR] =
  83. {{65536, 0, 0, 0, 0, 0},
  84. { 0, 0, 0, 0, 65536, 0},
  85. { 0, 0, 0, 0, 0, 65536}},
  86. [ANAGLYPH_RC_DUBOIS] =
  87. {{29891, 32800, 11559, -2849, -5763, -102},
  88. {-2627, -2479, -1033, 24804, 48080, -1209},
  89. { -997, -1350, -358, -4729, -7403, 80373}},
  90. [ANAGLYPH_GM_GRAY] =
  91. {{ 0, 0, 0, 19595, 38470, 7471},
  92. {19595, 38470, 7471, 0, 0, 0},
  93. { 0, 0, 0, 19595, 38470, 7471}},
  94. [ANAGLYPH_GM_HALF] =
  95. {{ 0, 0, 0, 65536, 0, 0},
  96. {19595, 38470, 7471, 0, 0, 0},
  97. { 0, 0, 0, 0, 0, 65536}},
  98. [ANAGLYPH_GM_COLOR] =
  99. {{ 0, 0, 0, 65536, 0, 0},
  100. { 0, 65536, 0, 0, 0, 0},
  101. { 0, 0, 0, 0, 0, 65536}},
  102. [ANAGLYPH_GM_DUBOIS] =
  103. {{-4063,-10354, -2556, 34669, 46203, 1573},
  104. {18612, 43778, 9372, -1049, -983, -4260},
  105. { -983, -1769, 1376, 590, 4915, 61407}},
  106. [ANAGLYPH_YB_GRAY] =
  107. {{ 0, 0, 0, 19595, 38470, 7471},
  108. { 0, 0, 0, 19595, 38470, 7471},
  109. {19595, 38470, 7471, 0, 0, 0}},
  110. [ANAGLYPH_YB_HALF] =
  111. {{ 0, 0, 0, 65536, 0, 0},
  112. { 0, 0, 0, 0, 65536, 0},
  113. {19595, 38470, 7471, 0, 0, 0}},
  114. [ANAGLYPH_YB_COLOR] =
  115. {{ 0, 0, 0, 65536, 0, 0},
  116. { 0, 0, 0, 0, 65536, 0},
  117. { 0, 0, 65536, 0, 0, 0}},
  118. [ANAGLYPH_YB_DUBOIS] =
  119. {{65535,-12650,18451, -987, -7590, -1049},
  120. {-1604, 56032, 4196, 370, 3826, -1049},
  121. {-2345,-10676, 1358, 5801, 11416, 56217}},
  122. };
  123. typedef struct Stereo3DContext {
  124. const AVClass *class;
  125. StereoComponent in, out;
  126. int width, height;
  127. int row_step;
  128. int ana_matrix[3][6];
  129. } Stereo3DContext;
  130. #define OFFSET(x) offsetof(Stereo3DContext, x)
  131. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  132. static const AVOption stereo3d_options[] = {
  133. { "in", "set input format", OFFSET(in.format), AV_OPT_TYPE_INT, {.i64=SIDE_BY_SIDE_LR}, SIDE_BY_SIDE_LR, ABOVE_BELOW_2_RL, FLAGS, "in"},
  134. { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "in" },
  135. { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "in" },
  136. { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "in" },
  137. { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "in" },
  138. { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "in" },
  139. { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "in" },
  140. { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "in" },
  141. { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "in" },
  142. { "out", "set output format", OFFSET(out.format), AV_OPT_TYPE_INT, {.i64=ANAGLYPH_RC_DUBOIS}, 0, STEREO_CODE_COUNT-1, FLAGS, "out"},
  143. { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "out" },
  144. { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "out" },
  145. { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "out" },
  146. { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "out" },
  147. { "agmc", "anaglyph green magenta color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_COLOR}, 0, 0, FLAGS, "out" },
  148. { "agmd", "anaglyph green magenta dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_DUBOIS}, 0, 0, FLAGS, "out" },
  149. { "agmg", "anaglyph green magenta gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_GRAY}, 0, 0, FLAGS, "out" },
  150. { "agmh", "anaglyph green magenta half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_HALF}, 0, 0, FLAGS, "out" },
  151. { "arbg", "anaglyph red blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RB_GRAY}, 0, 0, FLAGS, "out" },
  152. { "arcc", "anaglyph red cyan color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_COLOR}, 0, 0, FLAGS, "out" },
  153. { "arcd", "anaglyph red cyan dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_DUBOIS}, 0, 0, FLAGS, "out" },
  154. { "arcg", "anaglyph red cyan gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_GRAY}, 0, 0, FLAGS, "out" },
  155. { "arch", "anaglyph red cyan half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_HALF}, 0, 0, FLAGS, "out" },
  156. { "argg", "anaglyph red green gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RG_GRAY}, 0, 0, FLAGS, "out" },
  157. { "aybc", "anaglyph yellow blue color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_COLOR}, 0, 0, FLAGS, "out" },
  158. { "aybd", "anaglyph yellow blue dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_DUBOIS}, 0, 0, FLAGS, "out" },
  159. { "aybg", "anaglyph yellow blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_GRAY}, 0, 0, FLAGS, "out" },
  160. { "aybh", "anaglyph yellow blue half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_HALF}, 0, 0, FLAGS, "out" },
  161. { "irl", "interleave rows left first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_LR}, 0, 0, FLAGS, "out" },
  162. { "irr", "interleave rows right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_RL}, 0, 0, FLAGS, "out" },
  163. { "ml", "mono left", 0, AV_OPT_TYPE_CONST, {.i64=MONO_L}, 0, 0, FLAGS, "out" },
  164. { "mr", "mono right", 0, AV_OPT_TYPE_CONST, {.i64=MONO_R}, 0, 0, FLAGS, "out" },
  165. { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "out" },
  166. { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "out" },
  167. { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "out" },
  168. { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "out" },
  169. {NULL},
  170. };
  171. AVFILTER_DEFINE_CLASS(stereo3d);
  172. static av_cold int init(AVFilterContext *ctx, const char *args)
  173. {
  174. Stereo3DContext *s = ctx->priv;
  175. static const char *shorthand[] = { "in", "out", NULL };
  176. int ret;
  177. s->class = &stereo3d_class;
  178. av_opt_set_defaults(s);
  179. if ((ret = av_opt_set_from_string(s, args, shorthand, "=", ":")) < 0)
  180. return ret;
  181. return 0;
  182. }
  183. static int query_formats(AVFilterContext *ctx)
  184. {
  185. static const enum AVPixelFormat pix_fmts[] = {
  186. AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE
  187. };
  188. ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
  189. return 0;
  190. }
  191. static int config_output(AVFilterLink *outlink)
  192. {
  193. AVFilterContext *ctx = outlink->src;
  194. AVFilterLink *inlink = ctx->inputs[0];
  195. Stereo3DContext *s = ctx->priv;
  196. AVRational aspect = inlink->sample_aspect_ratio;
  197. s->in.width =
  198. s->width = inlink->w;
  199. s->in.height =
  200. s->height = inlink->h;
  201. s->row_step = 1;
  202. s->in.off_left =
  203. s->in.off_right =
  204. s->in.row_left =
  205. s->in.row_right = 0;
  206. switch (s->in.format) {
  207. case SIDE_BY_SIDE_2_LR:
  208. aspect.num *= 2;
  209. case SIDE_BY_SIDE_LR:
  210. s->width = inlink->w / 2;
  211. s->in.off_right = s->width * 3;
  212. break;
  213. case SIDE_BY_SIDE_2_RL:
  214. aspect.num *= 2;
  215. case SIDE_BY_SIDE_RL:
  216. s->width = inlink->w / 2;
  217. s->in.off_left = s->width * 3;
  218. break;
  219. case ABOVE_BELOW_2_LR:
  220. aspect.den *= 2;
  221. case ABOVE_BELOW_LR:
  222. s->in.row_right =
  223. s->height = inlink->h / 2;
  224. break;
  225. case ABOVE_BELOW_2_RL:
  226. aspect.den *= 2;
  227. case ABOVE_BELOW_RL:
  228. s->in.row_left =
  229. s->height = inlink->h / 2;
  230. break;
  231. default:
  232. av_log(ctx, AV_LOG_ERROR, "input format %d is not supported\n", s->in.format);
  233. return AVERROR(EINVAL);
  234. }
  235. s->out.width = s->width;
  236. s->out.height = s->height;
  237. s->out.off_left =
  238. s->out.off_right =
  239. s->out.row_left =
  240. s->out.row_right = 0;
  241. switch (s->out.format) {
  242. case ANAGLYPH_RB_GRAY:
  243. case ANAGLYPH_RG_GRAY:
  244. case ANAGLYPH_RC_GRAY:
  245. case ANAGLYPH_RC_HALF:
  246. case ANAGLYPH_RC_COLOR:
  247. case ANAGLYPH_RC_DUBOIS:
  248. case ANAGLYPH_GM_GRAY:
  249. case ANAGLYPH_GM_HALF:
  250. case ANAGLYPH_GM_COLOR:
  251. case ANAGLYPH_GM_DUBOIS:
  252. case ANAGLYPH_YB_GRAY:
  253. case ANAGLYPH_YB_HALF:
  254. case ANAGLYPH_YB_COLOR:
  255. case ANAGLYPH_YB_DUBOIS:
  256. memcpy(s->ana_matrix, ana_coeff[s->out.format], sizeof(s->ana_matrix));
  257. break;
  258. case SIDE_BY_SIDE_2_LR:
  259. aspect.num /= 2;
  260. case SIDE_BY_SIDE_LR:
  261. s->out.width =
  262. s->out.off_right = s->width * 3;
  263. break;
  264. case SIDE_BY_SIDE_2_RL:
  265. aspect.num /= 2;
  266. case SIDE_BY_SIDE_RL:
  267. s->out.width = s->width * 2;
  268. s->out.off_left = s->width * 3;
  269. break;
  270. case ABOVE_BELOW_2_LR:
  271. aspect.den /= 2;
  272. case ABOVE_BELOW_LR:
  273. s->out.height = s->height * 2;
  274. s->out.row_right = s->height;
  275. break;
  276. case ABOVE_BELOW_2_RL:
  277. aspect.den /= 2;
  278. case ABOVE_BELOW_RL:
  279. s->out.height = s->height * 2;
  280. s->out.row_left = s->height;
  281. break;
  282. case INTERLEAVE_ROWS_LR:
  283. s->row_step = 2;
  284. s->height = s->height / 2;
  285. s->out.off_right = s->width * 3;
  286. s->in.off_right += s->in.width * 3;
  287. break;
  288. case INTERLEAVE_ROWS_RL:
  289. s->row_step = 2;
  290. s->height = s->height / 2;
  291. s->out.off_left = s->width * 3;
  292. s->in.off_left += s->in.width * 3;
  293. break;
  294. case MONO_R:
  295. s->in.off_left = s->in.off_right;
  296. s->in.row_left = s->in.row_right;
  297. case MONO_L:
  298. break;
  299. default:
  300. av_log(ctx, AV_LOG_ERROR, "output format is not supported\n");
  301. return AVERROR(EINVAL);
  302. }
  303. outlink->w = s->out.width;
  304. outlink->h = s->out.height;
  305. outlink->sample_aspect_ratio = aspect;
  306. return 0;
  307. }
  308. static inline uint8_t ana_convert(const int *coeff, uint8_t *left, uint8_t *right)
  309. {
  310. int sum;
  311. sum = coeff[0] * left[0] + coeff[3] * right[0]; //red in
  312. sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in
  313. sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in
  314. return av_clip_uint8(sum >> 16);
  315. }
  316. static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
  317. {
  318. AVFilterContext *ctx = inlink->dst;
  319. Stereo3DContext *s = ctx->priv;
  320. AVFilterLink *outlink = ctx->outputs[0];
  321. AVFilterBufferRef *out;
  322. int out_off_left, out_off_right;
  323. int in_off_left, in_off_right;
  324. int ret;
  325. out = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
  326. if (!out) {
  327. avfilter_unref_bufferp(&inpicref);
  328. return AVERROR(ENOMEM);
  329. }
  330. out->pts = inpicref->pts;
  331. out->pos = inpicref->pos;
  332. in_off_left = s->in.row_left * inpicref->linesize[0] + s->in.off_left;
  333. in_off_right = s->in.row_right * inpicref->linesize[0] + s->in.off_right;
  334. out_off_left = s->out.row_left * out->linesize[0] + s->out.off_left;
  335. out_off_right = s->out.row_right * out->linesize[0] + s->out.off_right;
  336. switch (s->out.format) {
  337. case SIDE_BY_SIDE_LR:
  338. case SIDE_BY_SIDE_RL:
  339. case SIDE_BY_SIDE_2_LR:
  340. case SIDE_BY_SIDE_2_RL:
  341. case ABOVE_BELOW_LR:
  342. case ABOVE_BELOW_RL:
  343. case ABOVE_BELOW_2_LR:
  344. case ABOVE_BELOW_2_RL:
  345. case INTERLEAVE_ROWS_LR:
  346. case INTERLEAVE_ROWS_RL:
  347. av_image_copy_plane(out->data[0] + out_off_left,
  348. out->linesize[0] * s->row_step,
  349. inpicref->data[0] + in_off_left,
  350. inpicref->linesize[0] * s->row_step,
  351. 3 * s->width, s->height);
  352. av_image_copy_plane(out->data[0] + out_off_right,
  353. out->linesize[0] * s->row_step,
  354. inpicref->data[0] + in_off_right,
  355. inpicref->linesize[0] * s->row_step,
  356. 3 * s->width, s->height);
  357. break;
  358. case MONO_L:
  359. case MONO_R:
  360. av_image_copy_plane(out->data[0], out->linesize[0],
  361. inpicref->data[0] + in_off_left,
  362. inpicref->linesize[0],
  363. 3 * s->width, s->height);
  364. break;
  365. case ANAGLYPH_RB_GRAY:
  366. case ANAGLYPH_RG_GRAY:
  367. case ANAGLYPH_RC_GRAY:
  368. case ANAGLYPH_RC_HALF:
  369. case ANAGLYPH_RC_COLOR:
  370. case ANAGLYPH_RC_DUBOIS:
  371. case ANAGLYPH_GM_GRAY:
  372. case ANAGLYPH_GM_HALF:
  373. case ANAGLYPH_GM_COLOR:
  374. case ANAGLYPH_GM_DUBOIS:
  375. case ANAGLYPH_YB_GRAY:
  376. case ANAGLYPH_YB_HALF:
  377. case ANAGLYPH_YB_COLOR:
  378. case ANAGLYPH_YB_DUBOIS: {
  379. int i, x, y, il, ir, o;
  380. uint8_t *src = inpicref->data[0];
  381. uint8_t *dst = out->data[0];
  382. int out_width = s->out.width;
  383. int *ana_matrix[3];
  384. for (i = 0; i < 3; i++)
  385. ana_matrix[i] = s->ana_matrix[i];
  386. for (y = 0; y < s->out.height; y++) {
  387. o = out->linesize[0] * y;
  388. il = in_off_left + y * inpicref->linesize[0];
  389. ir = in_off_right + y * inpicref->linesize[0];
  390. for (x = 0; x < out_width; x++, il += 3, ir += 3, o+= 3) {
  391. dst[o ] = ana_convert(ana_matrix[0], src + il, src + ir);
  392. dst[o + 1] = ana_convert(ana_matrix[1], src + il, src + ir);
  393. dst[o + 2] = ana_convert(ana_matrix[2], src + il, src + ir);
  394. }
  395. }
  396. break;
  397. }
  398. default:
  399. av_assert0(0);
  400. }
  401. ret = ff_filter_frame(outlink, out);
  402. avfilter_unref_bufferp(&inpicref);
  403. if (ret < 0)
  404. return ret;
  405. return 0;
  406. }
  407. static av_cold void uninit(AVFilterContext *ctx)
  408. {
  409. Stereo3DContext *s = ctx->priv;
  410. av_opt_free(s);
  411. }
  412. static const AVFilterPad stereo3d_inputs[] = {
  413. {
  414. .name = "default",
  415. .type = AVMEDIA_TYPE_VIDEO,
  416. .get_video_buffer = ff_null_get_video_buffer,
  417. .filter_frame = filter_frame,
  418. .min_perms = AV_PERM_READ,
  419. },
  420. { NULL }
  421. };
  422. static const AVFilterPad stereo3d_outputs[] = {
  423. {
  424. .name = "default",
  425. .type = AVMEDIA_TYPE_VIDEO,
  426. .config_props = config_output,
  427. .min_perms = AV_PERM_WRITE,
  428. },
  429. { NULL }
  430. };
  431. AVFilter avfilter_vf_stereo3d = {
  432. .name = "stereo3d",
  433. .description = NULL_IF_CONFIG_SMALL("Convert video stereoscopic 3D view."),
  434. .priv_size = sizeof(Stereo3DContext),
  435. .init = init,
  436. .uninit = uninit,
  437. .query_formats = query_formats,
  438. .inputs = stereo3d_inputs,
  439. .outputs = stereo3d_outputs,
  440. .priv_class = &stereo3d_class,
  441. };