From ca0423198304305d832304e218611fb5d61921b3 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Tue, 3 Mar 2020 12:03:42 +0100 Subject: avfilter/vf_v360: add half equirectangular output format --- libavfilter/v360.h | 1 + libavfilter/vf_v360.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'libavfilter') diff --git a/libavfilter/v360.h b/libavfilter/v360.h index 4b2351f177..f2f1a47144 100644 --- a/libavfilter/v360.h +++ b/libavfilter/v360.h @@ -50,6 +50,7 @@ enum Projections { TETRAHEDRON, BARREL_SPLIT, TSPYRAMID, + HEQUIRECTANGULAR, NB_PROJECTIONS, }; diff --git a/libavfilter/vf_v360.c b/libavfilter/vf_v360.c index 5cbf8c95b1..3d4ee25216 100644 --- a/libavfilter/vf_v360.c +++ b/libavfilter/vf_v360.c @@ -103,6 +103,8 @@ static const AVOption v360_options[] = { {"tetrahedron", "tetrahedron", 0, AV_OPT_TYPE_CONST, {.i64=TETRAHEDRON}, 0, 0, FLAGS, "out" }, {"barrelsplit", "barrel split facebook's 360 format", 0, AV_OPT_TYPE_CONST, {.i64=BARREL_SPLIT}, 0, 0, FLAGS, "out" }, { "tsp", "truncated square pyramid", 0, AV_OPT_TYPE_CONST, {.i64=TSPYRAMID}, 0, 0, FLAGS, "out" }, + { "hequirect", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "out" }, + { "he", "half equirectangular", 0, AV_OPT_TYPE_CONST, {.i64=HEQUIRECTANGULAR},0, 0, FLAGS, "out" }, { "interp", "set interpolation method", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=BILINEAR}, 0, NB_INTERP_METHODS-1, FLAGS, "interp" }, { "near", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" }, { "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" }, @@ -1630,6 +1632,35 @@ static int equirect_to_xyz(const V360Context *s, return 1; } +/** + * Calculate 3D coordinates on sphere for corresponding frame position in half equirectangular format. + * + * @param s filter private context + * @param i horizontal position on frame [0, width) + * @param j vertical position on frame [0, height) + * @param width frame width + * @param height frame height + * @param vec coordinates on sphere + */ +static int hequirect_to_xyz(const V360Context *s, + int i, int j, int width, int height, + float *vec) +{ + const float phi = ((2.f * i + 0.5f) / width - 1.f) * M_PI_2; + const float theta = ((2.f * j + 0.5f) / height - 1.f) * M_PI_2; + + const float sin_phi = sinf(phi); + const float cos_phi = cosf(phi); + const float sin_theta = sinf(theta); + const float cos_theta = cosf(theta); + + vec[0] = cos_theta * sin_phi; + vec[1] = -sin_theta; + vec[2] = -cos_theta * cos_phi; + + return 1; +} + /** * Prepare data for processing stereographic output format. * @@ -3934,6 +3965,12 @@ static int config_output(AVFilterLink *outlink) w = lrintf(wf); h = lrintf(hf); break; + case HEQUIRECTANGULAR: + s->out_transform = hequirect_to_xyz; + prepare_out = NULL; + w = lrintf(wf / 2.f); + h = lrintf(hf); + break; default: av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n"); return AVERROR_BUG; -- cgit v1.2.3