From patchwork Wed Aug 14 01:14:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugene Lyapustin X-Patchwork-Id: 14493 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7D3F544999E for ; Wed, 14 Aug 2019 04:21:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4D076689AD1; Wed, 14 Aug 2019 04:21:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 39CD5680628 for ; Wed, 14 Aug 2019 04:21:56 +0300 (EEST) Received: by mail-lj1-f179.google.com with SMTP id f9so4735447ljc.13 for ; Tue, 13 Aug 2019 18:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=yg62Chl8w17A8mjLeZ103s+zei3CBR33qQOEMMoZta8=; b=O5p/x2aMIrK4JxKCzTojnGDlWDDtJolaq3K1zkXeY9yQmeGtL6nLndskP7z6UMSMUg Dg2cmVXMmtWjQ6wye3hv7OfqTf1BT5XZKTHua3TCsa92esOJMD38vMpA2j1rW92+J2gE 2w0ArnVDcepWz/8eCC03pcERzLPuxIvFD4yKyhZPWvN+eS5pSuZmsM2vwbybwDCc80Be DwTVGuSUx6DwiJTS5YqHTvHRUK1W+eUTckEabyMude0zxqT3WyyGUESviJWecLyHlyN/ Nipgs7yQShDNCNOk+RpCnF4TIVMOBL9h8moErTlbFDKF0fd7I8nKhEQcW4gpppeOBiZm 0PWw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=yg62Chl8w17A8mjLeZ103s+zei3CBR33qQOEMMoZta8=; b=k4cPCtRPLfjcff6pW0fqShHJIUaDuJI0E5sA1FiIdpVuckYWyi+dl0Oqx16YYD/9C7 xYJe2Bj8k/N9GpQ1hUKI4ka7TTOtcvlkanmtKL/CkBdr+KX8MBZALRfF4ogfwW/lWbpl qd90IUykLa83mNl8ACwz6jhlXnNipI429NZl7zZB4cmBBouWqtNQENMlhxwEIqvyPaSJ 9StZDaOQNrFePQe/kZv6BMD5Nh3eSui5r3AzyuCkMU48zOgfs1qIV95j0DIqPM9P+9GE lNVqCBVSLPmL5EeQnrw6nRuVZ/24DabAr10OJcLuqZGFtdy7uwqdMoNgQwUdpF7VuRYQ 3ljA== X-Gm-Message-State: APjAAAXw+HjBM8vnmDnwrZa8UgTtls6ybIqb5uGuwncjn5JK1mDi8FRL TKTCZpMZVE0/tWGLS/5K/FoNfcC7joA= X-Google-Smtp-Source: APXvYqyk74PlWR9ACdztVWpTEWa1kNOh8ba9fwQ/PgocB08obGc6R3s2ptbGt0SEETuVBtOpfi77oA== X-Received: by 2002:a2e:3a05:: with SMTP id h5mr7297142lja.135.1565745253810; Tue, 13 Aug 2019 18:14:13 -0700 (PDT) Received: from unis-note.localdomain ([176.109.79.157]) by smtp.gmail.com with ESMTPSA id k124sm19966197lfd.60.2019.08.13.18.14.13 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 13 Aug 2019 18:14:13 -0700 (PDT) From: Eugene Lyapustin To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Aug 2019 04:14:05 +0300 Message-Id: <20190814011405.11354-3-unishifft@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814011405.11354-1-unishifft@gmail.com> References: <20190814011405.11354-1-unishifft@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/3] avfilter/vf_v360: add dual fisheye format 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Eugene Lyapustin --- doc/filters.texi | 20 +++++++++++++++ libavfilter/vf_v360.c | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 6c70ffceb1..feb3a123b6 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -17972,6 +17972,26 @@ Format specific options: @item v_fov Set horizontal/vertical field of view. Values in degrees. @end table + +@item dfisheye +Dual fisheye. @i{(input only)} + +Format specific options: +@table @option +@item in_pad +Set padding proprtion. Values in decimals. + +Example values: +@table @samp +@item 0 +No padding. +@item 0.01 +1% padding. +@end table + +Default value is @b{@samp{0}}. +@end table + @end table @item interp diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index 3c69f2cf3d..fb0b0e0b46 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -48,6 +48,7 @@ enum Projections { CUBEMAP_6_1, EQUIANGULAR, FLAT, + DUAL_FISHEYE, NB_PROJECTIONS, }; @@ -136,6 +137,7 @@ static const AVOption v360_options[] = { { "c3x2", "cubemap3x2", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_3_2}, 0, 0, FLAGS, "in" }, { "c6x1", "cubemap6x1", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_6_1}, 0, 0, FLAGS, "in" }, { "eac", "equi-angular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIANGULAR}, 0, 0, FLAGS, "in" }, + { "dfisheye", "dual fisheye", 0, AV_OPT_TYPE_CONST, {.i64=DUAL_FISHEYE}, 0, 0, FLAGS, "in" }, { "output", "set output projection", OFFSET(out), AV_OPT_TYPE_INT, {.i64=CUBEMAP_3_2}, 0, NB_PROJECTIONS-1, FLAGS, "out" }, { "e", "equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=EQUIRECTANGULAR}, 0, 0, FLAGS, "out" }, { "c3x2", "cubemap3x2", 0, AV_OPT_TYPE_CONST, {.i64=CUBEMAP_3_2}, 0, 0, FLAGS, "out" }, @@ -1593,6 +1595,58 @@ static void flat_to_xyz(const V360Context *s, vec[2] = l_z / norm; } +/** + * Calculate frame position in dual fisheye format for corresponding 3D coordinates on sphere. + * + * @param s filter context + * @param vec coordinates on sphere + * @param width frame width + * @param height frame height + * @param us horizontal coordinates for interpolation window + * @param vs vertical coordinates for interpolation window + * @param du horizontal relative coordinate + * @param dv vertical relative coordinate + */ +static void xyz_to_dfisheye(const V360Context *s, + const float *vec, int width, int height, + uint16_t us[4][4], uint16_t vs[4][4], float *du, float *dv) +{ + const float scale = 1.f - s->in_pad; + + const float ew = width / 2.f; + const float eh = height; + + const float phi = atan2f(-vec[1], -vec[0]); + const float theta = acosf(fabsf(vec[2])) / M_PI; + + float uf = (theta * cosf(phi) * scale + 0.5f) * ew; + float vf = (theta * sinf(phi) * scale + 0.5f) * eh; + + int ui, vi; + int u_shift; + int i, j; + + if (vec[2] >= 0) { + u_shift = 0; + } else { + u_shift = ceilf(ew); + uf = ew - uf; + } + + ui = floorf(uf); + vi = floorf(vf); + + *du = uf - ui; + *dv = vf - vi; + + for (i = -1; i < 3; i++) { + for (j = -1; j < 3; j++) { + us[i + 1][j + 1] = av_clip(u_shift + ui + j, 0, width - 1); + vs[i + 1][j + 1] = av_clip( vi + i, 0, height - 1); + } + } +} + /** * Calculate rotation matrix for yaw/pitch/roll angles. */ @@ -1730,6 +1784,12 @@ static int config_output(AVFilterLink *outlink) case FLAT: av_log(ctx, AV_LOG_ERROR, "Flat format is not accepted as input.\n"); return AVERROR(EINVAL); + case DUAL_FISHEYE: + in_transform = xyz_to_dfisheye; + err = 0; + wf = inlink->w; + hf = inlink->h; + break; } if (err != 0) {