From patchwork Wed Nov 29 22:15:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 6459 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp5042186jah; Wed, 29 Nov 2017 14:16:37 -0800 (PST) X-Google-Smtp-Source: AGs4zMb1ABY14lSga3l45sYkEnIXVPuXqSeOcGaw0Ugy17IDB3ZkEFOfGoQjwxIy35TGfRz/jyy6 X-Received: by 10.223.171.202 with SMTP id s68mr250523wrc.13.1511993797095; Wed, 29 Nov 2017 14:16:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511993797; cv=none; d=google.com; s=arc-20160816; b=CkpiMVnTCJtHEZ+1MDiNpeCN53fJ4CtaURXpYaynuWpe5/oVCBCrQqg3SJwYjhOTVN AcDNZSbxFzc0uxycGIKix4QLZxWyj+hKAMbFP1sOWC1bcAtNSBiVSv62ircQdEp6KWeJ K7Q+YV1GnvGqzIo6ezuF7zxBubidf2x0kN9ARcfzDa5+uWkOc/1ZFxLi29DCVemWiLW2 2Ud74JUy81QVcr7ExO/O8ZFcO8FeiD6a8YtQSu18F99hJnfmEp4k7PMdTyDAOh2KzIMM qeBIB6UCj9AxUo21ouj8ciFNwPIR06Nvknb5FWBQ51LVf+zv9rhqzLzQLFvptD+32aXc AMcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=LgDhVW5sGDf16Bbf92RIkq7pG4QkZY2NRHV1G6zfmfM=; b=DQBXHwntNaDXZ+oW21JXFxJKMhRjb7TmAQIkjNRQUnOERixk6kZX6Tg8Pig16+0NOE 5KYryqG9gqFxhjfGrc9FXNtFLEkQt0tZ2bi38R4S9LNRWeC3hi6t792HJ7lhc8HjHXmx ZDMgp46/QHH7yqm83Qb/5xmKjo2vIUHYj63qsrLJeFfx1sOsIznoiuEEDGDzrh5C0Qmr lP1tkqjMYZATz7Xtz89UI2cdRVMaf4rsmFPpc/cEUGDt6U/SPvcdvix3mMfynY00TRj9 +i96UHiu5EPz2uT5CnsY+zf56X8QYHEz9Qsu7fZxw24kxOLLbVVYXvAHdNDIDrjymNQe sqfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=uCtZ/rKA; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c70si1930602wmd.260.2017.11.29.14.16.36; Wed, 29 Nov 2017 14:16:37 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=uCtZ/rKA; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DAF2D689F90; Thu, 30 Nov 2017 00:16:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 556AE689CFA for ; Thu, 30 Nov 2017 00:16:25 +0200 (EET) Received: by mail-wm0-f66.google.com with SMTP id g75so9470822wme.0 for ; Wed, 29 Nov 2017 14:16:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=dalo4YFpbN4Qn6ldsHm8G61qgdyH0RbsKG2iFnaWwl0=; b=uCtZ/rKAvDiBQ2tuYU25wz2d0jaKhKOHFIk7NgtWkJt6KxgLfa7zj1gKMNagiW/M6L RJUQdciC7XBV5eYWlW2zRWe70zCIZghX/WUDq1eNW638PsYxEulmInAypD+pB4g12Ri3 kOLRsw4OC4SKev8r+XewMriCEzDkhwvpQsj9RGYuDI5roQW+zkLGyGLhvrdYlt9cXOKr i+7SX/Xd1qWFgftRKuNBcn8SF52zdY7jIzkc4ojM88RJ53gEiG0hXMdG+DIF/UDKkb9g 8Hitlkk2blPiTgUSOQpqrrg0vyJ0jBJErMhdDCpIn8CRo5we+hKBuen+rY4wEk3OfkYV 1ajw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=dalo4YFpbN4Qn6ldsHm8G61qgdyH0RbsKG2iFnaWwl0=; b=o1Nhd5Tp1bbymFgIGy4191TWCe9VA0s0QTyPDXbAW6QhXUkZWqPt5yH68JUf86Hqam Vwr5TuFwO1vuGRDGVmfcJmycucCuyMYi9cwcaPaZAhVVzFqFsrYZK9ybYNXcWJRX6A6F r8d566b+YQJS8kT+yBEodiaUBfTPLKmEr0/uRGbQ1OlE1lcNUEsB2bM8FYrxcIdhkSrd S2i/Nhu1J+YbgR2/fg25+i/hcwVrL90Y6w3h6Kza5yo/qdepOUdYv6q3KbEvDFU1MMuD EPwNsSnUEgz3tqBJySY2UxqVXQKzO1TFb1yYdzhJMppCglMYVq9rDC4e4HJ5F7wY4btV yUEA== X-Gm-Message-State: AJaThX64hKF5em0fuC6P90Lde/EU5oGf27IlXV9e+zrJl9l4clBfFGH8 B9ejkWx/RqlMXwOria9VE9tVRg== X-Received: by 10.28.210.72 with SMTP id j69mr231030wmg.51.1511993786295; Wed, 29 Nov 2017 14:16:26 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id q140sm2342007wmd.35.2017.11.29.14.16.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2017 14:16:25 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Wed, 29 Nov 2017 23:15:44 +0100 Message-Id: <20171129221544.31833-1-onemda@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_stereo3d: implement auto detection by using frame side data X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- doc/filters.texi | 4 ++++ libavfilter/vf_stereo3d.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 4a4efc70c8..e8da5e21a6 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -14057,6 +14057,10 @@ Set stereoscopic image format of input. Available values for input image formats are: @table @samp +@item auto +set input format using frame side data +If such data is not available filter will return unchanged input. + @item sbsl side by side parallel (left eye left, right eye right) diff --git a/libavfilter/vf_stereo3d.c b/libavfilter/vf_stereo3d.c index 8b22f880ca..a51fbeb75d 100644 --- a/libavfilter/vf_stereo3d.c +++ b/libavfilter/vf_stereo3d.c @@ -25,6 +25,7 @@ #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" +#include "libavutil/stereo3d.h" #include "avfilter.h" #include "drawutils.h" #include "formats.h" @@ -47,8 +48,8 @@ enum StereoCode { ANAGLYPH_YB_DUBOIS, // anaglyph yellow/blue dubois ANAGLYPH_RB_GRAY, // anaglyph red/blue gray ANAGLYPH_RG_GRAY, // anaglyph red/green gray - MONO_L, // mono output for debugging (left eye only) - MONO_R, // mono output for debugging (right eye only) + MONO_L, // mono output (left eye only) + MONO_R, // mono output (right eye only) INTERLEAVE_ROWS_LR, // row-interleave (left eye has top row) INTERLEAVE_ROWS_RL, // row-interleave (right eye has top row) SIDE_BY_SIDE_LR, // side by side parallel (left eye left, right eye right) @@ -66,7 +67,8 @@ enum StereoCode { INTERLEAVE_COLS_LR, // column-interleave (left eye first, right eye second) INTERLEAVE_COLS_RL, // column-interleave (right eye first, left eye second) HDMI, // HDMI frame pack (left eye first, right eye second) - STEREO_CODE_COUNT // TODO: needs autodetection + AUTO, // guess input format using frame's metadata. + STEREO_CODE_COUNT }; typedef struct StereoComponent { @@ -173,6 +175,7 @@ static const AVOption stereo3d_options[] = { { "irr", "interleave rows right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_ROWS_RL}, 0, 0, FLAGS, "in" }, { "icl", "interleave columns left first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_COLS_LR}, 0, 0, FLAGS, "in" }, { "icr", "interleave columns right first", 0, AV_OPT_TYPE_CONST, {.i64=INTERLEAVE_COLS_RL}, 0, 0, FLAGS, "in" }, + { "auto", "guess using frame metadata", 0, AV_OPT_TYPE_CONST, {.i64=AUTO}, 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" }, @@ -366,6 +369,9 @@ static int config_output(AVFilterLink *outlink) int ret; s->aspect = inlink->sample_aspect_ratio; + if (s->in.format == AUTO || (s->in.format == s->out.format)) + return 0; + switch (s->in.format) { case INTERLEAVE_COLS_LR: case INTERLEAVE_COLS_RL: @@ -670,6 +676,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) int out_off_left[4], out_off_right[4]; int i, ret; + if (s->in.format == AUTO) { + AVFrameSideData *sd = av_frame_get_side_data(inpicref, AV_FRAME_DATA_STEREO3D); + + if (sd) { + AVStereo3D *s3d = (AVStereo3D *)sd->data; + + switch (s3d->type) { + case AV_STEREO3D_SIDEBYSIDE: s->in.format = SIDE_BY_SIDE_LR; break; + case AV_STEREO3D_SIDEBYSIDE_QUINCUNX: s->in.format = SIDE_BY_SIDE_LR; break; + case AV_STEREO3D_TOPBOTTOM: s->in.format = ABOVE_BELOW_LR; break; + case AV_STEREO3D_CHECKERBOARD: s->in.format = CHECKERBOARD_LR; break; + case AV_STEREO3D_FRAMESEQUENCE: s->in.format = ALTERNATING_LR; break; + case AV_STEREO3D_LINES: s->in.format = INTERLEAVE_ROWS_LR; break; + case AV_STEREO3D_COLUMNS: s->in.format = INTERLEAVE_COLS_LR; break; + default: s->in.format = s->out.format = MONO_L; + }; + } else { + s->in.format = s->out.format = MONO_L; + } + if ((ret = config_output(outlink)) < 0) + return ret; + } + if (s->in.format == s->out.format) return ff_filter_frame(outlink, inpicref);