vf_stereo3d.c
Go to the documentation of this file.
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 
22 #include "libavutil/avassert.h"
23 #include "libavutil/imgutils.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/parseutils.h"
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "formats.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 enum StereoCode {
33  ANAGLYPH_RC_GRAY, // anaglyph red/cyan gray
34  ANAGLYPH_RC_HALF, // anaglyph red/cyan half colored
35  ANAGLYPH_RC_COLOR, // anaglyph red/cyan colored
36  ANAGLYPH_RC_DUBOIS, // anaglyph red/cyan dubois
37  ANAGLYPH_GM_GRAY, // anaglyph green/magenta gray
38  ANAGLYPH_GM_HALF, // anaglyph green/magenta half colored
39  ANAGLYPH_GM_COLOR, // anaglyph green/magenta colored
40  ANAGLYPH_GM_DUBOIS, // anaglyph green/magenta dubois
41  ANAGLYPH_YB_GRAY, // anaglyph yellow/blue gray
42  ANAGLYPH_YB_HALF, // anaglyph yellow/blue half colored
43  ANAGLYPH_YB_COLOR, // anaglyph yellow/blue colored
44  ANAGLYPH_YB_DUBOIS, // anaglyph yellow/blue dubois
45  ANAGLYPH_RB_GRAY, // anaglyph red/blue gray
46  ANAGLYPH_RG_GRAY, // anaglyph red/green gray
47  MONO_L, // mono output for debugging (left eye only)
48  MONO_R, // mono output for debugging (right eye only)
49  INTERLEAVE_ROWS_LR, // row-interleave (left eye has top row)
50  INTERLEAVE_ROWS_RL, // row-interleave (right eye has top row)
51  SIDE_BY_SIDE_LR, // side by side parallel (left eye left, right eye right)
52  SIDE_BY_SIDE_RL, // side by side crosseye (right eye left, left eye right)
53  SIDE_BY_SIDE_2_LR, // side by side parallel with half width resolution
54  SIDE_BY_SIDE_2_RL, // side by side crosseye with half width resolution
55  ABOVE_BELOW_LR, // above-below (left eye above, right eye below)
56  ABOVE_BELOW_RL, // above-below (right eye above, left eye below)
57  ABOVE_BELOW_2_LR, // above-below with half height resolution
58  ABOVE_BELOW_2_RL, // above-below with half height resolution
59  STEREO_CODE_COUNT // TODO: needs autodetection
60 };
61 
62 typedef struct StereoComponent {
64  int width, height;
69 
70 static const int ana_coeff[][3][6] = {
72  {{19595, 38470, 7471, 0, 0, 0},
73  { 0, 0, 0, 0, 0, 0},
74  { 0, 0, 0, 19595, 38470, 7471}},
76  {{19595, 38470, 7471, 0, 0, 0},
77  { 0, 0, 0, 19595, 38470, 7471},
78  { 0, 0, 0, 0, 0, 0}},
80  {{19595, 38470, 7471, 0, 0, 0},
81  { 0, 0, 0, 19595, 38470, 7471},
82  { 0, 0, 0, 19595, 38470, 7471}},
84  {{19595, 38470, 7471, 0, 0, 0},
85  { 0, 0, 0, 0, 65536, 0},
86  { 0, 0, 0, 0, 0, 65536}},
88  {{65536, 0, 0, 0, 0, 0},
89  { 0, 0, 0, 0, 65536, 0},
90  { 0, 0, 0, 0, 0, 65536}},
92  {{29891, 32800, 11559, -2849, -5763, -102},
93  {-2627, -2479, -1033, 24804, 48080, -1209},
94  { -997, -1350, -358, -4729, -7403, 80373}},
96  {{ 0, 0, 0, 19595, 38470, 7471},
97  {19595, 38470, 7471, 0, 0, 0},
98  { 0, 0, 0, 19595, 38470, 7471}},
100  {{ 0, 0, 0, 65536, 0, 0},
101  {19595, 38470, 7471, 0, 0, 0},
102  { 0, 0, 0, 0, 0, 65536}},
104  {{ 0, 0, 0, 65536, 0, 0},
105  { 0, 65536, 0, 0, 0, 0},
106  { 0, 0, 0, 0, 0, 65536}},
108  {{-4063,-10354, -2556, 34669, 46203, 1573},
109  {18612, 43778, 9372, -1049, -983, -4260},
110  { -983, -1769, 1376, 590, 4915, 61407}},
111  [ANAGLYPH_YB_GRAY] =
112  {{ 0, 0, 0, 19595, 38470, 7471},
113  { 0, 0, 0, 19595, 38470, 7471},
114  {19595, 38470, 7471, 0, 0, 0}},
115  [ANAGLYPH_YB_HALF] =
116  {{ 0, 0, 0, 65536, 0, 0},
117  { 0, 0, 0, 0, 65536, 0},
118  {19595, 38470, 7471, 0, 0, 0}},
120  {{ 0, 0, 0, 65536, 0, 0},
121  { 0, 0, 0, 0, 65536, 0},
122  { 0, 0, 65536, 0, 0, 0}},
124  {{65535,-12650,18451, -987, -7590, -1049},
125  {-1604, 56032, 4196, 370, 3826, -1049},
126  {-2345,-10676, 1358, 5801, 11416, 56217}},
127 };
128 
129 typedef struct Stereo3DContext {
130  const AVClass *class;
132  int width, height;
133  int row_step;
134  int ana_matrix[3][6];
136  int linesize[4];
137  int pixstep[4];
139 
140 #define OFFSET(x) offsetof(Stereo3DContext, x)
141 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
142 
143 static const AVOption stereo3d_options[] = {
144  { "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"},
145  { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "in" },
146  { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "in" },
147  { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "in" },
148  { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "in" },
149  { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "in" },
150  { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "in" },
151  { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "in" },
152  { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "in" },
153  { "out", "set output format", OFFSET(out.format), AV_OPT_TYPE_INT, {.i64=ANAGLYPH_RC_DUBOIS}, 0, STEREO_CODE_COUNT-1, FLAGS, "out"},
154  { "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "out" },
155  { "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "out" },
156  { "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "out" },
157  { "abr", "above below right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_RL}, 0, 0, FLAGS, "out" },
158  { "agmc", "anaglyph green magenta color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_COLOR}, 0, 0, FLAGS, "out" },
159  { "agmd", "anaglyph green magenta dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_DUBOIS}, 0, 0, FLAGS, "out" },
160  { "agmg", "anaglyph green magenta gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_GRAY}, 0, 0, FLAGS, "out" },
161  { "agmh", "anaglyph green magenta half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_GM_HALF}, 0, 0, FLAGS, "out" },
162  { "arbg", "anaglyph red blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RB_GRAY}, 0, 0, FLAGS, "out" },
163  { "arcc", "anaglyph red cyan color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_COLOR}, 0, 0, FLAGS, "out" },
164  { "arcd", "anaglyph red cyan dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_DUBOIS}, 0, 0, FLAGS, "out" },
165  { "arcg", "anaglyph red cyan gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_GRAY}, 0, 0, FLAGS, "out" },
166  { "arch", "anaglyph red cyan half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RC_HALF}, 0, 0, FLAGS, "out" },
167  { "argg", "anaglyph red green gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_RG_GRAY}, 0, 0, FLAGS, "out" },
168  { "aybc", "anaglyph yellow blue color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_COLOR}, 0, 0, FLAGS, "out" },
169  { "aybd", "anaglyph yellow blue dubois", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_DUBOIS}, 0, 0, FLAGS, "out" },
170  { "aybg", "anaglyph yellow blue gray", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_GRAY}, 0, 0, FLAGS, "out" },
171  { "aybh", "anaglyph yellow blue half color", 0, AV_OPT_TYPE_CONST, {.i64=ANAGLYPH_YB_HALF}, 0, 0, FLAGS, "out" },
172  { "irl", "interleave rows left first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_LR}, 0, 0, FLAGS, "out" },
173  { "irr", "interleave rows right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_RL}, 0, 0, FLAGS, "out" },
174  { "ml", "mono left", 0, AV_OPT_TYPE_CONST, {.i64=MONO_L}, 0, 0, FLAGS, "out" },
175  { "mr", "mono right", 0, AV_OPT_TYPE_CONST, {.i64=MONO_R}, 0, 0, FLAGS, "out" },
176  { "sbs2l", "side by side half width left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_LR}, 0, 0, FLAGS, "out" },
177  { "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "out" },
178  { "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "out" },
179  { "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "out" },
180  {NULL},
181 };
182 
183 AVFILTER_DEFINE_CLASS(stereo3d);
184 
186 static const enum AVPixelFormat other_pix_fmts[] = {
213 };
214 
216 {
217  Stereo3DContext *s = ctx->priv;
218  const enum AVPixelFormat *pix_fmts;
219 
220  switch (s->out.format) {
221  case ANAGLYPH_GM_COLOR:
222  case ANAGLYPH_GM_DUBOIS:
223  case ANAGLYPH_GM_GRAY:
224  case ANAGLYPH_GM_HALF:
225  case ANAGLYPH_RB_GRAY:
226  case ANAGLYPH_RC_COLOR:
227  case ANAGLYPH_RC_DUBOIS:
228  case ANAGLYPH_RC_GRAY:
229  case ANAGLYPH_RC_HALF:
230  case ANAGLYPH_RG_GRAY:
231  case ANAGLYPH_YB_COLOR:
232  case ANAGLYPH_YB_DUBOIS:
233  case ANAGLYPH_YB_GRAY:
234  case ANAGLYPH_YB_HALF:
235  pix_fmts = anaglyph_pix_fmts;
236  break;
237  default:
238  pix_fmts = other_pix_fmts;
239  }
240 
242 
243  return 0;
244 }
245 
246 static int config_output(AVFilterLink *outlink)
247 {
248  AVFilterContext *ctx = outlink->src;
249  AVFilterLink *inlink = ctx->inputs[0];
250  Stereo3DContext *s = ctx->priv;
251  AVRational aspect = inlink->sample_aspect_ratio;
252  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
253  int ret;
254 
255  switch (s->in.format) {
256  case SIDE_BY_SIDE_2_LR:
257  case SIDE_BY_SIDE_LR:
258  case SIDE_BY_SIDE_2_RL:
259  case SIDE_BY_SIDE_RL:
260  if (inlink->w & 1) {
261  av_log(ctx, AV_LOG_ERROR, "width must be even\n");
262  return AVERROR_INVALIDDATA;
263  }
264  break;
265  case ABOVE_BELOW_2_LR:
266  case ABOVE_BELOW_LR:
267  case ABOVE_BELOW_2_RL:
268  case ABOVE_BELOW_RL:
269  if (s->out.format == INTERLEAVE_ROWS_LR ||
270  s->out.format == INTERLEAVE_ROWS_RL) {
271  if (inlink->h & 3) {
272  av_log(ctx, AV_LOG_ERROR, "height must be multiple of 4\n");
273  return AVERROR_INVALIDDATA;
274  }
275  }
276  if (inlink->h & 1) {
277  av_log(ctx, AV_LOG_ERROR, "height must be even\n");
278  return AVERROR_INVALIDDATA;
279  }
280  break;
281  }
282 
283  s->in.width =
284  s->width = inlink->w;
285  s->in.height =
286  s->height = inlink->h;
287  s->row_step = 1;
288  s->in.off_lstep =
289  s->in.off_rstep =
290  s->in.off_left =
291  s->in.off_right =
292  s->in.row_left =
293  s->in.row_right = 0;
294 
295  switch (s->in.format) {
296  case SIDE_BY_SIDE_2_LR:
297  aspect.num *= 2;
298  case SIDE_BY_SIDE_LR:
299  s->width = inlink->w / 2;
300  s->in.off_right = s->width;
301  break;
302  case SIDE_BY_SIDE_2_RL:
303  aspect.num *= 2;
304  case SIDE_BY_SIDE_RL:
305  s->width = inlink->w / 2;
306  s->in.off_left = s->width;
307  break;
308  case ABOVE_BELOW_2_LR:
309  aspect.den *= 2;
310  case ABOVE_BELOW_LR:
311  s->in.row_right =
312  s->height = inlink->h / 2;
313  break;
314  case ABOVE_BELOW_2_RL:
315  aspect.den *= 2;
316  case ABOVE_BELOW_RL:
317  s->in.row_left =
318  s->height = inlink->h / 2;
319  break;
320  default:
321  av_log(ctx, AV_LOG_ERROR, "input format %d is not supported\n", s->in.format);
322  return AVERROR(EINVAL);
323  }
324 
325  s->out.width = s->width;
326  s->out.height = s->height;
327  s->out.off_lstep =
328  s->out.off_rstep =
329  s->out.off_left =
330  s->out.off_right =
331  s->out.row_left =
332  s->out.row_right = 0;
333 
334  switch (s->out.format) {
335  case ANAGLYPH_RB_GRAY:
336  case ANAGLYPH_RG_GRAY:
337  case ANAGLYPH_RC_GRAY:
338  case ANAGLYPH_RC_HALF:
339  case ANAGLYPH_RC_COLOR:
340  case ANAGLYPH_RC_DUBOIS:
341  case ANAGLYPH_GM_GRAY:
342  case ANAGLYPH_GM_HALF:
343  case ANAGLYPH_GM_COLOR:
344  case ANAGLYPH_GM_DUBOIS:
345  case ANAGLYPH_YB_GRAY:
346  case ANAGLYPH_YB_HALF:
347  case ANAGLYPH_YB_COLOR:
348  case ANAGLYPH_YB_DUBOIS:
349  memcpy(s->ana_matrix, ana_coeff[s->out.format], sizeof(s->ana_matrix));
350  break;
351  case SIDE_BY_SIDE_2_LR:
352  aspect.num /= 2;
353  case SIDE_BY_SIDE_LR:
354  s->out.width = s->width * 2;
355  s->out.off_right = s->width;
356  break;
357  case SIDE_BY_SIDE_2_RL:
358  aspect.num /= 2;
359  case SIDE_BY_SIDE_RL:
360  s->out.width = s->width * 2;
361  s->out.off_left = s->width;
362  break;
363  case ABOVE_BELOW_2_LR:
364  aspect.den /= 2;
365  case ABOVE_BELOW_LR:
366  s->out.height = s->height * 2;
367  s->out.row_right = s->height;
368  break;
369  case ABOVE_BELOW_2_RL:
370  aspect.den /= 2;
371  case ABOVE_BELOW_RL:
372  s->out.height = s->height * 2;
373  s->out.row_left = s->height;
374  break;
375  case INTERLEAVE_ROWS_LR:
376  s->row_step = 2;
377  s->height = s->height / 2;
378  s->out.off_rstep =
379  s->in.off_rstep = 1;
380  break;
381  case INTERLEAVE_ROWS_RL:
382  s->row_step = 2;
383  s->height = s->height / 2;
384  s->out.off_lstep =
385  s->in.off_lstep = 1;
386  break;
387  case MONO_R:
388  s->in.off_left = s->in.off_right;
389  s->in.row_left = s->in.row_right;
390  case MONO_L:
391  break;
392  default:
393  av_log(ctx, AV_LOG_ERROR, "output format is not supported\n");
394  return AVERROR(EINVAL);
395  }
396 
397  outlink->w = s->out.width;
398  outlink->h = s->out.height;
399  outlink->sample_aspect_ratio = aspect;
400 
401  if ((ret = av_image_fill_linesizes(s->linesize, outlink->format, s->width)) < 0)
402  return ret;
405 
406  return 0;
407 }
408 
409 static inline uint8_t ana_convert(const int *coeff, uint8_t *left, uint8_t *right)
410 {
411  int sum;
412 
413  sum = coeff[0] * left[0] + coeff[3] * right[0]; //red in
414  sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in
415  sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in
416 
417  return av_clip_uint8(sum >> 16);
418 }
419 
420 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
421 {
422  AVFilterContext *ctx = inlink->dst;
423  Stereo3DContext *s = ctx->priv;
424  AVFilterLink *outlink = ctx->outputs[0];
425  AVFrame *out;
426  int out_off_left[4], out_off_right[4];
427  int in_off_left[4], in_off_right[4];
428  int i;
429 
430  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
431  if (!out) {
432  av_frame_free(&inpicref);
433  return AVERROR(ENOMEM);
434  }
435  av_frame_copy_props(out, inpicref);
436 
437  for (i = 0; i < 4; i++) {
438  in_off_left[i] = (s->in.row_left + s->in.off_lstep) * inpicref->linesize[i] + s->in.off_left * s->pixstep[i];
439  in_off_right[i] = (s->in.row_right + s->in.off_rstep) * inpicref->linesize[i] + s->in.off_right * s->pixstep[i];
440  out_off_left[i] = (s->out.row_left + s->out.off_lstep) * out->linesize[i] + s->out.off_left * s->pixstep[i];
441  out_off_right[i] = (s->out.row_right + s->out.off_rstep) * out->linesize[i] + s->out.off_right * s->pixstep[i];
442  }
443 
444  switch (s->out.format) {
445  case SIDE_BY_SIDE_LR:
446  case SIDE_BY_SIDE_RL:
447  case SIDE_BY_SIDE_2_LR:
448  case SIDE_BY_SIDE_2_RL:
449  case ABOVE_BELOW_LR:
450  case ABOVE_BELOW_RL:
451  case ABOVE_BELOW_2_LR:
452  case ABOVE_BELOW_2_RL:
453  case INTERLEAVE_ROWS_LR:
454  case INTERLEAVE_ROWS_RL:
455  for (i = 0; i < s->nb_planes; i++) {
456  av_image_copy_plane(out->data[i] + out_off_left[i],
457  out->linesize[i] * s->row_step,
458  inpicref->data[i] + in_off_left[i],
459  inpicref->linesize[i] * s->row_step,
460  s->linesize[i], s->height);
461  av_image_copy_plane(out->data[i] + out_off_right[i],
462  out->linesize[i] * s->row_step,
463  inpicref->data[i] + in_off_right[i],
464  inpicref->linesize[i] * s->row_step,
465  s->linesize[i], s->height);
466  }
467  break;
468  case MONO_L:
469  case MONO_R:
470  for (i = 0; i < s->nb_planes; i++) {
471  av_image_copy_plane(out->data[i], out->linesize[i],
472  inpicref->data[i] + in_off_left[i],
473  inpicref->linesize[i],
474  s->linesize[i], s->height);
475  }
476  break;
477  case ANAGLYPH_RB_GRAY:
478  case ANAGLYPH_RG_GRAY:
479  case ANAGLYPH_RC_GRAY:
480  case ANAGLYPH_RC_HALF:
481  case ANAGLYPH_RC_COLOR:
482  case ANAGLYPH_RC_DUBOIS:
483  case ANAGLYPH_GM_GRAY:
484  case ANAGLYPH_GM_HALF:
485  case ANAGLYPH_GM_COLOR:
486  case ANAGLYPH_GM_DUBOIS:
487  case ANAGLYPH_YB_GRAY:
488  case ANAGLYPH_YB_HALF:
489  case ANAGLYPH_YB_COLOR:
490  case ANAGLYPH_YB_DUBOIS: {
491  int i, x, y, il, ir, o;
492  uint8_t *src = inpicref->data[0];
493  uint8_t *dst = out->data[0];
494  int out_width = s->out.width;
495  int *ana_matrix[3];
496 
497  for (i = 0; i < 3; i++)
498  ana_matrix[i] = s->ana_matrix[i];
499 
500  for (y = 0; y < s->out.height; y++) {
501  o = out->linesize[0] * y;
502  il = in_off_left[0] + y * inpicref->linesize[0];
503  ir = in_off_right[0] + y * inpicref->linesize[0];
504  for (x = 0; x < out_width; x++, il += 3, ir += 3, o+= 3) {
505  dst[o ] = ana_convert(ana_matrix[0], src + il, src + ir);
506  dst[o + 1] = ana_convert(ana_matrix[1], src + il, src + ir);
507  dst[o + 2] = ana_convert(ana_matrix[2], src + il, src + ir);
508  }
509  }
510  break;
511  }
512  default:
513  av_assert0(0);
514  }
515 
516  av_frame_free(&inpicref);
517  return ff_filter_frame(outlink, out);
518 }
519 
520 static const AVFilterPad stereo3d_inputs[] = {
521  {
522  .name = "default",
523  .type = AVMEDIA_TYPE_VIDEO,
524  .filter_frame = filter_frame,
525  },
526  { NULL }
527 };
528 
529 static const AVFilterPad stereo3d_outputs[] = {
530  {
531  .name = "default",
532  .type = AVMEDIA_TYPE_VIDEO,
533  .config_props = config_output,
534  },
535  { NULL }
536 };
537 
539  .name = "stereo3d",
540  .description = NULL_IF_CONFIG_SMALL("Convert video stereoscopic 3D view."),
541  .priv_size = sizeof(Stereo3DContext),
543  .inputs = stereo3d_inputs,
544  .outputs = stereo3d_outputs,
545  .priv_class = &stereo3d_class,
546 };
AVFilter avfilter_vf_stereo3d
Definition: vf_stereo3d.c:538
const char * s
Definition: avisynth_c.h:668
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:231
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:424
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
StereoComponent in
Definition: vf_stereo3d.c:131
AVOption.
Definition: opt.h:251
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:212
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:73
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1818
external API header
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:70
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:154
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:229
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
int num
numerator
Definition: rational.h:44
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:211
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:195
struct StereoComponent StereoComponent
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:234
AVFILTER_DEFINE_CLASS(stereo3d)
packed BGR 8:8:8, 32bpp, 0BGR0BGR...
Definition: pixfmt.h:216
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:143
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:233
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:308
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
Definition: imgutils.c:32
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:532
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
struct Stereo3DContext Stereo3DContext
StereoComponent out
Definition: vf_stereo3d.c:131
uint8_t
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
packed RGB 8:8:8, 32bpp, RGB0RGB0...
Definition: pixfmt.h:215
AVOptions.
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:112
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:209
planar YUV 4:4:4,36bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:230
int ana_matrix[3][6]
Definition: vf_stereo3d.c:134
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:98
static const AVFilterPad stereo3d_outputs[]
Definition: vf_stereo3d.c:529
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:173
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:200
void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:545
A filter pad used for either input or output.
Discrete Time axis x
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:169
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:157
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:133
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:99
void * priv
private data for use by the filter
Definition: avfilter.h:545
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), big-endian
Definition: pixfmt.h:188
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
planar YUV 4:4:4 36bpp, (1 Cr & Cb sample per 1x1 Y & A samples), little-endian
Definition: pixfmt.h:189
#define FLAGS
Definition: vf_stereo3d.c:141
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:96
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:143
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:97
#define OFFSET(x)
Definition: vf_stereo3d.c:140
ret
Definition: avfilter.c:821
static const AVFilterPad stereo3d_inputs[]
Definition: vf_stereo3d.c:520
planar YUV 4:4:4 40bpp, (1 Cr & Cb sample per 1x1 Y & A samples, big-endian)
Definition: pixfmt.h:194
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:71
enum StereoCode format
Definition: vf_stereo3d.c:63
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:142
static enum AVPixelFormat other_pix_fmts[]
Definition: vf_stereo3d.c:186
static const AVOption stereo3d_options[]
Definition: vf_stereo3d.c:143
NULL
Definition: eval.c:55
AVS_Value src
Definition: avisynth_c.h:523
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:218
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:171
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static enum AVPixelFormat anaglyph_pix_fmts[]
Definition: vf_stereo3d.c:185
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:236
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:436
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:86
planar YUV 4:4:4 64bpp, (1 Cr & Cb sample per 1x1 Y & A samples, little-endian)
Definition: pixfmt.h:201
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
static int config_output(AVFilterLink *outlink)
Definition: vf_stereo3d.c:246
packed BGR 8:8:8, 32bpp, BGR0BGR0...
Definition: pixfmt.h:217
const char * name
filter name
Definition: avfilter.h:437
static const double coeff[2][5]
Definition: vf_ow.c:64
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:235
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
static int query_formats(AVFilterContext *ctx)
Definition: vf_stereo3d.c:215
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:155
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:132
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:170
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:111
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of PIX_FMT_YUV444P and setting color_...
Definition: pixfmt.h:82
int den
denominator
Definition: rational.h:45
function y
Definition: D.m:1
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_stereo3d.c:420
static const int ana_coeff[][3][6]
Definition: vf_stereo3d.c:70
planar YUV 4:4:4,42bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:232
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
An instance of a filter.
Definition: avfilter.h:524
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:174
static uint8_t ana_convert(const int *coeff, uint8_t *left, uint8_t *right)
Definition: vf_stereo3d.c:409
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:242
internal API functions
packed RGB 8:8:8, 32bpp, 0RGB0RGB...
Definition: pixfmt.h:214
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
StereoCode
Definition: vf_stereo3d.c:32
planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:156
for(j=16;j >0;--j)
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:172
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:210