You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avfilter/vf_v360: add perspective output projection
This commit is contained in:
@@ -19003,6 +19003,15 @@ Set horizontal/vertical/diagonal field of view. Values in degrees.
|
|||||||
If diagonal field of view is set it overrides horizontal and vertical field of view.
|
If diagonal field of view is set it overrides horizontal and vertical field of view.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
@item perspective
|
||||||
|
Perspective projection. @i{(output only)}
|
||||||
|
|
||||||
|
Format specific options:
|
||||||
|
@table @option
|
||||||
|
@item v_fov
|
||||||
|
Set perspective parameter.
|
||||||
|
@end table
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@item interp
|
@item interp
|
||||||
|
@@ -46,6 +46,7 @@ enum Projections {
|
|||||||
FISHEYE,
|
FISHEYE,
|
||||||
PANNINI,
|
PANNINI,
|
||||||
CYLINDRICAL,
|
CYLINDRICAL,
|
||||||
|
PERSPECTIVE,
|
||||||
NB_PROJECTIONS,
|
NB_PROJECTIONS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -90,6 +90,7 @@ static const AVOption v360_options[] = {
|
|||||||
{ "fisheye", "fisheye", 0, AV_OPT_TYPE_CONST, {.i64=FISHEYE}, 0, 0, FLAGS, "out" },
|
{ "fisheye", "fisheye", 0, AV_OPT_TYPE_CONST, {.i64=FISHEYE}, 0, 0, FLAGS, "out" },
|
||||||
{ "pannini", "pannini", 0, AV_OPT_TYPE_CONST, {.i64=PANNINI}, 0, 0, FLAGS, "out" },
|
{ "pannini", "pannini", 0, AV_OPT_TYPE_CONST, {.i64=PANNINI}, 0, 0, FLAGS, "out" },
|
||||||
{"cylindrical", "cylindrical", 0, AV_OPT_TYPE_CONST, {.i64=CYLINDRICAL}, 0, 0, FLAGS, "out" },
|
{"cylindrical", "cylindrical", 0, AV_OPT_TYPE_CONST, {.i64=CYLINDRICAL}, 0, 0, FLAGS, "out" },
|
||||||
|
{"perspective", "perspective", 0, AV_OPT_TYPE_CONST, {.i64=PERSPECTIVE}, 0, 0, FLAGS, "out" },
|
||||||
{ "interp", "set interpolation method", OFFSET(interp), AV_OPT_TYPE_INT, {.i64=BILINEAR}, 0, NB_INTERP_METHODS-1, FLAGS, "interp" },
|
{ "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" },
|
{ "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" },
|
{ "nearest", "nearest neighbour", 0, AV_OPT_TYPE_CONST, {.i64=NEAREST}, 0, 0, FLAGS, "interp" },
|
||||||
@@ -2334,6 +2335,51 @@ static void cylindrical_to_xyz(const V360Context *s,
|
|||||||
normalize_vector(vec);
|
normalize_vector(vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate 3D coordinates on sphere for corresponding frame position in perspective 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 void perspective_to_xyz(const V360Context *s,
|
||||||
|
int i, int j, int width, int height,
|
||||||
|
float *vec)
|
||||||
|
{
|
||||||
|
const float uf = ((2.f * i) / width - 1.f);
|
||||||
|
const float vf = ((2.f * j) / height - 1.f);
|
||||||
|
const float rh = hypotf(uf, vf);
|
||||||
|
const float sinzz = 1.f - rh * rh;
|
||||||
|
const float h = 1.f + s->v_fov;
|
||||||
|
const float sinz = (h - sqrtf(sinzz)) / (h / rh + rh / h);
|
||||||
|
const float sinz2 = sinz * sinz;
|
||||||
|
|
||||||
|
if (sinz2 <= 1.f) {
|
||||||
|
const float cosz = sqrtf(1.f - sinz2);
|
||||||
|
|
||||||
|
const float theta = asinf(cosz);
|
||||||
|
const float phi = atan2f(uf, vf);
|
||||||
|
|
||||||
|
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;
|
||||||
|
} else {
|
||||||
|
vec[0] = 0.f;
|
||||||
|
vec[1] = -1.f;
|
||||||
|
vec[2] = 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
normalize_vector(vec);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate 3D coordinates on sphere for corresponding frame position in dual fisheye format.
|
* Calculate 3D coordinates on sphere for corresponding frame position in dual fisheye format.
|
||||||
*
|
*
|
||||||
@@ -2884,6 +2930,7 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
wf = w;
|
wf = w;
|
||||||
hf = h / 9.f * 8.f;
|
hf = h / 9.f * 8.f;
|
||||||
break;
|
break;
|
||||||
|
case PERSPECTIVE:
|
||||||
case CYLINDRICAL:
|
case CYLINDRICAL:
|
||||||
case PANNINI:
|
case PANNINI:
|
||||||
case FISHEYE:
|
case FISHEYE:
|
||||||
@@ -3038,6 +3085,12 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
w = roundf(wf);
|
w = roundf(wf);
|
||||||
h = roundf(hf * 0.5f);
|
h = roundf(hf * 0.5f);
|
||||||
break;
|
break;
|
||||||
|
case PERSPECTIVE:
|
||||||
|
s->out_transform = perspective_to_xyz;
|
||||||
|
prepare_out = NULL;
|
||||||
|
w = roundf(wf / 2.f);
|
||||||
|
h = roundf(hf);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");
|
av_log(ctx, AV_LOG_ERROR, "Specified output format is not handled.\n");
|
||||||
return AVERROR_BUG;
|
return AVERROR_BUG;
|
||||||
|
Reference in New Issue
Block a user