[FFmpeg-devel] [PATCH] lavfi/stereo3d: support for alternating frames input format
Paul B Mahol
onemda at gmail.com
Fri Apr 26 16:17:14 CEST 2013
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
doc/filters.texi | 6 +++++
libavfilter/vf_stereo3d.c | 66 +++++++++++++++++++++++++++++++++++------------
2 files changed, 55 insertions(+), 17 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 8dce89e..e7935cf 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -5744,6 +5744,12 @@ above-below with half height resolution
above-below with half height resolution
(right eye above, left eye below)
+ at item al
+alternating frames (left eye first, right eye second)
+
+ at item ar
+alternating frames (right eye first, left eye second)
+
Default value is @samp{sbsl}.
@end table
diff --git a/libavfilter/vf_stereo3d.c b/libavfilter/vf_stereo3d.c
index a98a2f8..fa670e5 100644
--- a/libavfilter/vf_stereo3d.c
+++ b/libavfilter/vf_stereo3d.c
@@ -56,6 +56,8 @@ enum StereoCode {
ABOVE_BELOW_RL, // above-below (right eye above, left eye below)
ABOVE_BELOW_2_LR, // above-below with half height resolution
ABOVE_BELOW_2_RL, // above-below with half height resolution
+ ALTERNATING_LR, // alternating frames (left eye first, right eye second)
+ ALTERNATING_RL, // alternating frames (right eye first, left eye second)
STEREO_CODE_COUNT // TODO: needs autodetection
};
@@ -135,13 +137,14 @@ typedef struct Stereo3DContext {
int nb_planes;
int linesize[4];
int pixstep[4];
+ AVFrame *prev;
} Stereo3DContext;
#define OFFSET(x) offsetof(Stereo3DContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
static const AVOption stereo3d_options[] = {
- { "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"},
+ { "in", "set input format", OFFSET(in.format), AV_OPT_TYPE_INT, {.i64=SIDE_BY_SIDE_LR}, SIDE_BY_SIDE_LR, STEREO_CODE_COUNT-1, FLAGS, "in"},
{ "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "in" },
{ "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "in" },
{ "abl", "above below left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_LR}, 0, 0, FLAGS, "in" },
@@ -150,6 +153,8 @@ static const AVOption stereo3d_options[] = {
{ "sbs2r", "side by side half width right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_2_RL}, 0, 0, FLAGS, "in" },
{ "sbsl", "side by side left first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_LR}, 0, 0, FLAGS, "in" },
{ "sbsr", "side by side right first", 0, AV_OPT_TYPE_CONST, {.i64=SIDE_BY_SIDE_RL}, 0, 0, FLAGS, "in" },
+ { "al", "alternating frames left first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_LR}, 0, 0, FLAGS, "in" },
+ { "ar", "alternating frames right first", 0, AV_OPT_TYPE_CONST, {.i64=ALTERNATING_RL}, 0, 0, FLAGS, "in" },
{ "out", "set output format", OFFSET(out.format), AV_OPT_TYPE_INT, {.i64=ANAGLYPH_RC_DUBOIS}, 0, STEREO_CODE_COUNT-1, FLAGS, "out"},
{ "ab2l", "above below half height left first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_LR}, 0, 0, FLAGS, "out" },
{ "ab2r", "above below half height right first", 0, AV_OPT_TYPE_CONST, {.i64=ABOVE_BELOW_2_RL}, 0, 0, FLAGS, "out" },
@@ -249,6 +254,7 @@ static int config_output(AVFilterLink *outlink)
AVFilterLink *inlink = ctx->inputs[0];
Stereo3DContext *s = ctx->priv;
AVRational aspect = inlink->sample_aspect_ratio;
+ AVRational fps = inlink->frame_rate;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
int ret;
@@ -317,6 +323,11 @@ static int config_output(AVFilterLink *outlink)
s->in.row_left =
s->height = inlink->h / 2;
break;
+ case ALTERNATING_RL:
+ case ALTERNATING_LR:
+ outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
+ fps.den *= 2;
+ break;
default:
av_log(ctx, AV_LOG_ERROR, "input format %d is not supported\n", s->in.format);
return AVERROR(EINVAL);
@@ -390,12 +401,13 @@ static int config_output(AVFilterLink *outlink)
case MONO_L:
break;
default:
- av_log(ctx, AV_LOG_ERROR, "output format is not supported\n");
+ av_log(ctx, AV_LOG_ERROR, "output format %d is not supported\n", s->out.format);
return AVERROR(EINVAL);
}
outlink->w = s->out.width;
outlink->h = s->out.height;
+ outlink->frame_rate = fps;
outlink->sample_aspect_ratio = aspect;
if ((ret = av_image_fill_linesizes(s->linesize, outlink->format, s->width)) < 0)
@@ -422,21 +434,38 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
AVFilterContext *ctx = inlink->dst;
Stereo3DContext *s = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0];
- AVFrame *out;
+ AVFrame *out, *left, *right;
int out_off_left[4], out_off_right[4];
int in_off_left[4], in_off_right[4];
int i;
+ switch (s->in.format) {
+ case ALTERNATING_LR:
+ case ALTERNATING_RL:
+ if (!s->prev) {
+ s->prev = inpicref;
+ return 0;
+ }
+ left = s->prev;
+ right = inpicref;
+ if (s->in.format == ALTERNATING_RL)
+ FFSWAP(AVFrame *, left, right);
+ break;
+ default:
+ left = right = inpicref;
+ };
+
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
if (!out) {
+ av_frame_free(&s->prev);
av_frame_free(&inpicref);
return AVERROR(ENOMEM);
}
av_frame_copy_props(out, inpicref);
for (i = 0; i < 4; i++) {
- in_off_left[i] = (s->in.row_left + s->in.off_lstep) * inpicref->linesize[i] + s->in.off_left * s->pixstep[i];
- in_off_right[i] = (s->in.row_right + s->in.off_rstep) * inpicref->linesize[i] + s->in.off_right * s->pixstep[i];
+ in_off_left[i] = (s->in.row_left + s->in.off_lstep) * left->linesize[i] + s->in.off_left * s->pixstep[i];
+ in_off_right[i] = (s->in.row_right + s->in.off_rstep) * right->linesize[i] + s->in.off_right * s->pixstep[i];
out_off_left[i] = (s->out.row_left + s->out.off_lstep) * out->linesize[i] + s->out.off_left * s->pixstep[i];
out_off_right[i] = (s->out.row_right + s->out.off_rstep) * out->linesize[i] + s->out.off_right * s->pixstep[i];
}
@@ -455,22 +484,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
for (i = 0; i < s->nb_planes; i++) {
av_image_copy_plane(out->data[i] + out_off_left[i],
out->linesize[i] * s->row_step,
- inpicref->data[i] + in_off_left[i],
- inpicref->linesize[i] * s->row_step,
+ left->data[i] + in_off_left[i],
+ left->linesize[i] * s->row_step,
s->linesize[i], s->height);
av_image_copy_plane(out->data[i] + out_off_right[i],
out->linesize[i] * s->row_step,
- inpicref->data[i] + in_off_right[i],
- inpicref->linesize[i] * s->row_step,
+ right->data[i] + in_off_right[i],
+ right->linesize[i] * s->row_step,
s->linesize[i], s->height);
}
break;
case MONO_L:
+ right = left;
case MONO_R:
for (i = 0; i < s->nb_planes; i++) {
av_image_copy_plane(out->data[i], out->linesize[i],
- inpicref->data[i] + in_off_left[i],
- inpicref->linesize[i],
+ right->data[i] + in_off_left[i],
+ right->linesize[i],
s->linesize[i], s->height);
}
break;
@@ -489,7 +519,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
case ANAGLYPH_YB_COLOR:
case ANAGLYPH_YB_DUBOIS: {
int i, x, y, il, ir, o;
- uint8_t *src = inpicref->data[0];
+ uint8_t *lsrc = left->data[0];
+ uint8_t *rsrc = right->data[0];
uint8_t *dst = out->data[0];
int out_width = s->out.width;
int *ana_matrix[3];
@@ -499,12 +530,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
for (y = 0; y < s->out.height; y++) {
o = out->linesize[0] * y;
- il = in_off_left[0] + y * inpicref->linesize[0];
- ir = in_off_right[0] + y * inpicref->linesize[0];
+ il = in_off_left[0] + y * left->linesize[0];
+ ir = in_off_right[0] + y * right->linesize[0];
for (x = 0; x < out_width; x++, il += 3, ir += 3, o+= 3) {
- dst[o ] = ana_convert(ana_matrix[0], src + il, src + ir);
- dst[o + 1] = ana_convert(ana_matrix[1], src + il, src + ir);
- dst[o + 2] = ana_convert(ana_matrix[2], src + il, src + ir);
+ dst[o ] = ana_convert(ana_matrix[0], lsrc + il, rsrc + ir);
+ dst[o + 1] = ana_convert(ana_matrix[1], lsrc + il, rsrc + ir);
+ dst[o + 2] = ana_convert(ana_matrix[2], lsrc + il, rsrc + ir);
}
}
break;
@@ -514,6 +545,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
}
av_frame_free(&inpicref);
+ av_frame_free(&s->prev);
return ff_filter_frame(outlink, out);
}
--
1.7.11.2
More information about the ffmpeg-devel
mailing list