avfilter/avf_showspectrum: add horizontal orientation support
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
9f4c7b4df7
commit
e30e5c83ae
@ -14665,6 +14665,10 @@ It accepts the following values:
|
|||||||
@end table
|
@end table
|
||||||
|
|
||||||
Default value is @code{hann}.
|
Default value is @code{hann}.
|
||||||
|
|
||||||
|
@item orientation
|
||||||
|
Set orientation of time vs frequency axis. Can be @code{vertical} or
|
||||||
|
@code{horizontal}. Default is @code{vertical}.
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
The usage is very similar to the showwaves filter; see the examples in that
|
The usage is very similar to the showwaves filter; see the examples in that
|
||||||
|
@ -39,12 +39,15 @@ enum DisplayMode { COMBINED, SEPARATE, NB_MODES };
|
|||||||
enum DisplayScale { LINEAR, SQRT, CBRT, LOG, NB_SCALES };
|
enum DisplayScale { LINEAR, SQRT, CBRT, LOG, NB_SCALES };
|
||||||
enum ColorMode { CHANNEL, INTENSITY, NB_CLMODES };
|
enum ColorMode { CHANNEL, INTENSITY, NB_CLMODES };
|
||||||
enum SlideMode { REPLACE, SCROLL, FULLFRAME, RSCROLL, NB_SLIDES };
|
enum SlideMode { REPLACE, SCROLL, FULLFRAME, RSCROLL, NB_SLIDES };
|
||||||
|
enum Orientation { VERTICAL, HORIZONTAL, NB_ORIENTATIONS };
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const AVClass *class;
|
const AVClass *class;
|
||||||
int w, h;
|
int w, h;
|
||||||
AVFrame *outpicref;
|
AVFrame *outpicref;
|
||||||
int nb_display_channels;
|
int nb_display_channels;
|
||||||
|
int orientation;
|
||||||
|
int channel_width;
|
||||||
int channel_height;
|
int channel_height;
|
||||||
int sliding; ///< 1 if sliding mode, 0 otherwise
|
int sliding; ///< 1 if sliding mode, 0 otherwise
|
||||||
int mode; ///< channel display mode
|
int mode; ///< channel display mode
|
||||||
@ -100,6 +103,9 @@ static const AVOption showspectrum_options[] = {
|
|||||||
{ "nuttall", "Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL}, 0, 0, FLAGS, "win_func" },
|
{ "nuttall", "Nuttall", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_NUTTALL}, 0, 0, FLAGS, "win_func" },
|
||||||
{ "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS}, 0, 0, FLAGS, "win_func" },
|
{ "lanczos", "Lanczos", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_LANCZOS}, 0, 0, FLAGS, "win_func" },
|
||||||
{ "gauss", "Gauss", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS}, 0, 0, FLAGS, "win_func" },
|
{ "gauss", "Gauss", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_GAUSS}, 0, 0, FLAGS, "win_func" },
|
||||||
|
{ "orientation", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=VERTICAL}, 0, NB_ORIENTATIONS-1, FLAGS, "orientation" },
|
||||||
|
{ "vertical", NULL, 0, AV_OPT_TYPE_CONST, {.i64=VERTICAL}, 0, 0, FLAGS, "orientation" },
|
||||||
|
{ "horizontal", NULL, 0, AV_OPT_TYPE_CONST, {.i64=HORIZONTAL}, 0, 0, FLAGS, "orientation" },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -168,16 +174,23 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
AVFilterContext *ctx = outlink->src;
|
AVFilterContext *ctx = outlink->src;
|
||||||
AVFilterLink *inlink = ctx->inputs[0];
|
AVFilterLink *inlink = ctx->inputs[0];
|
||||||
ShowSpectrumContext *s = ctx->priv;
|
ShowSpectrumContext *s = ctx->priv;
|
||||||
int i, rdft_bits, win_size, h;
|
int i, rdft_bits, win_size, h, w;
|
||||||
|
|
||||||
outlink->w = s->w;
|
outlink->w = s->w;
|
||||||
outlink->h = s->h;
|
outlink->h = s->h;
|
||||||
|
|
||||||
h = (s->mode == COMBINED) ? outlink->h : outlink->h / inlink->channels;
|
h = (s->mode == COMBINED || s->orientation == HORIZONTAL) ? outlink->h : outlink->h / inlink->channels;
|
||||||
|
w = (s->mode == COMBINED || s->orientation == VERTICAL) ? outlink->w : outlink->w / inlink->channels;
|
||||||
s->channel_height = h;
|
s->channel_height = h;
|
||||||
|
s->channel_width = w;
|
||||||
|
|
||||||
/* RDFT window size (precision) according to the requested output frame height */
|
if (s->orientation == VERTICAL) {
|
||||||
for (rdft_bits = 1; 1 << rdft_bits < 2 * h; rdft_bits++);
|
/* RDFT window size (precision) according to the requested output frame height */
|
||||||
|
for (rdft_bits = 1; 1 << rdft_bits < 2 * h; rdft_bits++);
|
||||||
|
} else {
|
||||||
|
/* RDFT window size (precision) according to the requested output frame width */
|
||||||
|
for (rdft_bits = 1; 1 << rdft_bits < 2 * w; rdft_bits++);
|
||||||
|
}
|
||||||
win_size = 1 << rdft_bits;
|
win_size = 1 << rdft_bits;
|
||||||
|
|
||||||
/* (re-)configuration if the video output changed (or first init) */
|
/* (re-)configuration if the video output changed (or first init) */
|
||||||
@ -232,19 +245,28 @@ static int config_output(AVFilterLink *outlink)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->xpos >= outlink->w)
|
if ((s->orientation == VERTICAL && s->xpos >= outlink->w) ||
|
||||||
|
(s->orientation == HORIZONTAL && s->xpos >= outlink->h))
|
||||||
s->xpos = 0;
|
s->xpos = 0;
|
||||||
|
|
||||||
outlink->frame_rate = av_make_q(inlink->sample_rate, win_size);
|
outlink->frame_rate = av_make_q(inlink->sample_rate, win_size);
|
||||||
if (s->sliding == FULLFRAME)
|
if (s->orientation == VERTICAL && s->sliding == FULLFRAME)
|
||||||
outlink->frame_rate.den *= outlink->w;
|
outlink->frame_rate.den *= outlink->w;
|
||||||
|
if (s->orientation == HORIZONTAL && s->sliding == FULLFRAME)
|
||||||
|
outlink->frame_rate.den *= outlink->h;
|
||||||
|
|
||||||
inlink->min_samples = inlink->max_samples = inlink->partial_buf_size =
|
inlink->min_samples = inlink->max_samples = inlink->partial_buf_size =
|
||||||
win_size;
|
win_size;
|
||||||
|
|
||||||
s->combine_buffer =
|
if (s->orientation == VERTICAL) {
|
||||||
av_realloc_f(s->combine_buffer, outlink->h * 3,
|
s->combine_buffer =
|
||||||
sizeof(*s->combine_buffer));
|
av_realloc_f(s->combine_buffer, outlink->h * 3,
|
||||||
|
sizeof(*s->combine_buffer));
|
||||||
|
} else {
|
||||||
|
s->combine_buffer =
|
||||||
|
av_realloc_f(s->combine_buffer, outlink->w * 3,
|
||||||
|
sizeof(*s->combine_buffer));
|
||||||
|
}
|
||||||
|
|
||||||
av_log(ctx, AV_LOG_VERBOSE, "s:%dx%d RDFT window size:%d\n",
|
av_log(ctx, AV_LOG_VERBOSE, "s:%dx%d RDFT window size:%d\n",
|
||||||
s->w, s->h, win_size);
|
s->w, s->h, win_size);
|
||||||
@ -261,10 +283,18 @@ static int request_frame(AVFilterLink *outlink)
|
|||||||
ret = ff_request_frame(inlink);
|
ret = ff_request_frame(inlink);
|
||||||
if (ret == AVERROR_EOF && s->sliding == FULLFRAME && s->xpos > 0 &&
|
if (ret == AVERROR_EOF && s->sliding == FULLFRAME && s->xpos > 0 &&
|
||||||
s->outpicref) {
|
s->outpicref) {
|
||||||
for (i = 0; i < outlink->h; i++) {
|
if (s->orientation == VERTICAL) {
|
||||||
memset(s->outpicref->data[0] + i * s->outpicref->linesize[0] + s->xpos, 0, outlink->w - s->xpos);
|
for (i = 0; i < outlink->h; i++) {
|
||||||
memset(s->outpicref->data[1] + i * s->outpicref->linesize[1] + s->xpos, 128, outlink->w - s->xpos);
|
memset(s->outpicref->data[0] + i * s->outpicref->linesize[0] + s->xpos, 0, outlink->w - s->xpos);
|
||||||
memset(s->outpicref->data[2] + i * s->outpicref->linesize[2] + s->xpos, 128, outlink->w - s->xpos);
|
memset(s->outpicref->data[1] + i * s->outpicref->linesize[1] + s->xpos, 128, outlink->w - s->xpos);
|
||||||
|
memset(s->outpicref->data[2] + i * s->outpicref->linesize[2] + s->xpos, 128, outlink->w - s->xpos);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = s->xpos; i < outlink->h; i++) {
|
||||||
|
memset(s->outpicref->data[0] + i * s->outpicref->linesize[0], 0, outlink->w);
|
||||||
|
memset(s->outpicref->data[1] + i * s->outpicref->linesize[1], 128, outlink->w);
|
||||||
|
memset(s->outpicref->data[2] + i * s->outpicref->linesize[2], 128, outlink->w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ret = ff_filter_frame(outlink, s->outpicref);
|
ret = ff_filter_frame(outlink, s->outpicref);
|
||||||
s->outpicref = NULL;
|
s->outpicref = NULL;
|
||||||
@ -286,9 +316,9 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
|
|||||||
const int nb_freq = 1 << (s->rdft_bits - 1);
|
const int nb_freq = 1 << (s->rdft_bits - 1);
|
||||||
const int win_size = nb_freq << 1;
|
const int win_size = nb_freq << 1;
|
||||||
const double w = 1. / (sqrt(nb_freq) * 32768.);
|
const double w = 1. / (sqrt(nb_freq) * 32768.);
|
||||||
int h = s->channel_height;
|
int h = s->orientation == VERTICAL ? s->channel_height : s->channel_width;
|
||||||
|
|
||||||
int ch, plane, n, y;
|
int ch, plane, n, x, y;
|
||||||
|
|
||||||
av_assert0(insamples->nb_samples == win_size);
|
av_assert0(insamples->nb_samples == win_size);
|
||||||
|
|
||||||
@ -310,10 +340,18 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
|
|||||||
#define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
|
#define MAGNITUDE(y, ch) hypot(RE(y, ch), IM(y, ch))
|
||||||
|
|
||||||
/* initialize buffer for combining to black */
|
/* initialize buffer for combining to black */
|
||||||
for (y = 0; y < outlink->h; y++) {
|
if (s->orientation == VERTICAL) {
|
||||||
s->combine_buffer[3 * y ] = 0;
|
for (y = 0; y < outlink->h; y++) {
|
||||||
s->combine_buffer[3 * y + 1] = 127.5;
|
s->combine_buffer[3 * y ] = 0;
|
||||||
s->combine_buffer[3 * y + 2] = 127.5;
|
s->combine_buffer[3 * y + 1] = 127.5;
|
||||||
|
s->combine_buffer[3 * y + 2] = 127.5;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (y = 0; y < outlink->w; y++) {
|
||||||
|
s->combine_buffer[3 * y ] = 0;
|
||||||
|
s->combine_buffer[3 * y + 1] = 127.5;
|
||||||
|
s->combine_buffer[3 * y + 2] = 127.5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ch = 0; ch < s->nb_display_channels; ch++) {
|
for (ch = 0; ch < s->nb_display_channels; ch++) {
|
||||||
@ -427,32 +465,62 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* copy to output */
|
/* copy to output */
|
||||||
if (s->sliding == SCROLL) {
|
if (s->orientation == VERTICAL) {
|
||||||
|
if (s->sliding == SCROLL) {
|
||||||
|
for (plane = 0; plane < 3; plane++) {
|
||||||
|
for (y = 0; y < outlink->h; y++) {
|
||||||
|
uint8_t *p = outpicref->data[plane] +
|
||||||
|
y * outpicref->linesize[plane];
|
||||||
|
memmove(p, p + 1, outlink->w - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s->xpos = outlink->w - 1;
|
||||||
|
} else if (s->sliding == RSCROLL) {
|
||||||
|
for (plane = 0; plane < 3; plane++) {
|
||||||
|
for (y = 0; y < outlink->h; y++) {
|
||||||
|
uint8_t *p = outpicref->data[plane] +
|
||||||
|
y * outpicref->linesize[plane];
|
||||||
|
memmove(p + 1, p, outlink->w - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s->xpos = 0;
|
||||||
|
}
|
||||||
for (plane = 0; plane < 3; plane++) {
|
for (plane = 0; plane < 3; plane++) {
|
||||||
|
uint8_t *p = outpicref->data[plane] +
|
||||||
|
(outlink->h - 1) * outpicref->linesize[plane] +
|
||||||
|
s->xpos;
|
||||||
for (y = 0; y < outlink->h; y++) {
|
for (y = 0; y < outlink->h; y++) {
|
||||||
uint8_t *p = outpicref->data[plane] +
|
*p = lrint(FFMAX(0, FFMIN(s->combine_buffer[3 * y + plane], 255)));
|
||||||
y * outpicref->linesize[plane];
|
p -= outpicref->linesize[plane];
|
||||||
memmove(p, p + 1, outlink->w - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s->xpos = outlink->w - 1;
|
} else {
|
||||||
} else if (s->sliding == RSCROLL) {
|
if (s->sliding == SCROLL) {
|
||||||
for (plane = 0; plane < 3; plane++) {
|
for (plane = 0; plane < 3; plane++) {
|
||||||
for (y = 0; y < outlink->h; y++) {
|
for (y = 1; y < outlink->h; y++) {
|
||||||
uint8_t *p = outpicref->data[plane] +
|
memmove(outpicref->data[plane] + (y-1) * outpicref->linesize[plane],
|
||||||
y * outpicref->linesize[plane];
|
outpicref->data[plane] + (y ) * outpicref->linesize[plane],
|
||||||
memmove(p + 1, p, outlink->w - 1);
|
outlink->w);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
s->xpos = outlink->h - 1;
|
||||||
|
} else if (s->sliding == RSCROLL) {
|
||||||
|
for (plane = 0; plane < 3; plane++) {
|
||||||
|
for (y = outlink->h - 1; y >= 1; y--) {
|
||||||
|
memmove(outpicref->data[plane] + (y ) * outpicref->linesize[plane],
|
||||||
|
outpicref->data[plane] + (y-1) * outpicref->linesize[plane],
|
||||||
|
outlink->w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s->xpos = 0;
|
||||||
}
|
}
|
||||||
s->xpos = 0;
|
for (plane = 0; plane < 3; plane++) {
|
||||||
}
|
uint8_t *p = outpicref->data[plane] +
|
||||||
for (plane = 0; plane < 3; plane++) {
|
s->xpos * outpicref->linesize[plane];
|
||||||
uint8_t *p = outpicref->data[plane] +
|
for (x = 0; x < outlink->w; x++) {
|
||||||
(outlink->h - 1) * outpicref->linesize[plane] +
|
*p = lrint(FFMAX(0, FFMIN(s->combine_buffer[3 * x + plane], 255)));
|
||||||
s->xpos;
|
p++;
|
||||||
for (y = 0; y < outlink->h; y++) {
|
}
|
||||||
*p = lrint(FFMAX(0, FFMIN(s->combine_buffer[3 * y + plane], 255)));
|
|
||||||
p -= outpicref->linesize[plane];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,7 +528,9 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
|
|||||||
outpicref->pts = insamples->pts;
|
outpicref->pts = insamples->pts;
|
||||||
|
|
||||||
s->xpos++;
|
s->xpos++;
|
||||||
if (s->xpos >= outlink->w)
|
if (s->orientation == VERTICAL && s->xpos >= outlink->w)
|
||||||
|
s->xpos = 0;
|
||||||
|
if (s->orientation == HORIZONTAL && s->xpos >= outlink->h)
|
||||||
s->xpos = 0;
|
s->xpos = 0;
|
||||||
if (s->sliding != FULLFRAME || s->xpos == 0) {
|
if (s->sliding != FULLFRAME || s->xpos == 0) {
|
||||||
ret = ff_filter_frame(outlink, av_frame_clone(s->outpicref));
|
ret = ff_filter_frame(outlink, av_frame_clone(s->outpicref));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user