79#define OFFSET(x) offsetof(ShowFreqsContext, x)
80#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
104 {
"colors",
"set channels colors",
OFFSET(colors),
AV_OPT_TYPE_STRING, {.str =
"red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0,
FLAGS },
147 float overlap,
scale = 1.f;
151 s->nb_freq =
s->fft_size / 2;
152 s->win_size =
s->fft_size;
157 "The window size might be too high.\n");
164 for (
i = 0;
i <
s->nb_channels;
i++) {
175 s->bypass =
av_calloc(
s->nb_channels,
sizeof(*
s->bypass));
178 s->fft_input =
av_calloc(
s->nb_channels,
sizeof(*
s->fft_input));
181 s->fft_data =
av_calloc(
s->nb_channels,
sizeof(*
s->fft_data));
184 s->avg_data =
av_calloc(
s->nb_channels,
sizeof(*
s->avg_data));
187 for (
i = 0;
i <
s->nb_channels;
i++) {
190 s->avg_data[
i] =
av_calloc(
s->nb_freq,
sizeof(**
s->avg_data));
191 if (!
s->fft_data[
i] || !
s->avg_data[
i] || !
s->fft_input[
i])
197 sizeof(*
s->window_func_lut));
198 if (!
s->window_func_lut)
201 if (
s->overlap == 1.)
202 s->overlap = overlap;
203 s->hop_size = (1. -
s->overlap) *
s->win_size;
204 if (
s->hop_size < 1) {
209 for (
s->scale = 0,
i = 0;
i < s->win_size;
i++) {
210 s->scale +=
s->window_func_lut[
i] *
s->window_func_lut[
i];
226 s->nb_draw_channels =
s->nb_channels;
228 if (strcmp(
s->ch_layout_str,
"all")) {
229 int nb_draw_channels = 0;
233 for (
int ch = 0; ch <
s->nb_channels; ch++) {
237 nb_draw_channels +=
s->bypass[ch] == 0;
240 s->nb_draw_channels = nb_draw_channels;
251 if ((
color & 0xffffff) != 0)
261 return (
s->w/(
float)
s->nb_freq)*
f;
263 return s->w-pow(
s->w, (
s->nb_freq-
f-1)/(
s->nb_freq-1.));
265 return pow(
s->w,
f/(
s->nb_freq-1.));
277 return pow(
s->w, (
s->nb_freq-
f-1)/(
s->nb_freq-1.))-
278 pow(
s->w, (
s->nb_freq-
f-2)/(
s->nb_freq-1.));
280 return pow(
s->w, (
f+1)/(
s->nb_freq-1.))-
281 pow(
s->w,
f /(
s->nb_freq-1.));
288 double a,
int f, uint8_t fg[4],
int *prev_y,
293 const float min =
s->minamp;
294 const float avg =
s->avg_data[ch][
f];
297 int end = outlink->
h;
317 y =
a * outlink->
h - 1;
320 end = (outlink->
h /
s->nb_draw_channels) * (ch + 1);
321 y = (outlink->
h /
s->nb_draw_channels) * ch +
a * (outlink->
h /
s->nb_draw_channels) - 1;
337 y =
av_clip(
s->avg_data[ch][
f], 0, outlink->
h - 1);
347 for (x = sx + 1; x < sx + bsize && x <
w; x++)
349 for (
i = y;
i <= *prev_y;
i++)
352 for (
i = *prev_y;
i <= y;
i++)
354 for (x = sx + 1; x < sx + bsize && x <
w; x++)
360 for (x = sx; x < sx + bsize && x <
w; x++)
361 for (
i = y;
i < end;
i++)
365 for (x = sx; x < sx + bsize && x <
w; x++)
377 const int win_size =
s->win_size;
383 for (ch = 0; ch <
s->nb_channels; ch++) {
389 for (n = 0; n < win_size; n++) {
390 s->fft_input[ch][n].re = p[n] *
s->window_func_lut[n];
391 s->fft_input[ch][n].im = 0;
396 for (ch = 0; ch <
s->nb_channels; ch++) {
404 if (
s->old_pts >=
s->pts)
408#define RE(x, ch) s->fft_data[ch][x].re
409#define IM(x, ch) s->fft_data[ch][x].im
410#define M(a, b) (sqrt((a) * (a) + (b) * (b)))
411#define P(a, b) (atan2((b), (a)))
423 for (n = 0; n < outlink->
h; n++)
424 memset(
out->data[0] +
out->linesize[0] * n, 0, outlink->
w * 4);
426 for (ch = 0; ch <
s->nb_channels; ch++) {
427 uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
438 switch (
s->data_mode) {
440 for (
f = 0;
f <
s->nb_freq;
f++) {
447 for (
f = 0;
f <
s->nb_freq;
f++) {
454 for (
f = 0;
f <
s->nb_freq;
f++) {
475 const int offset =
s->win_size -
s->hop_size;
479 float *
dst = (
float *)
s->window->extended_data[ch];
528 for (
i = 0;
i <
s->nb_channels;
i++) {
553 .p.name =
"showfreqs",
555 .p.priv_class = &showfreqs_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static enum AVSampleFormat sample_fmts[]
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
#define DELAY(name, type, fill)
const FFFilter ff_avf_showfreqs
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static float get_bsize(ShowFreqsContext *s, int f)
static int get_sx(ShowFreqsContext *s, int f)
static const AVFilterPad showfreqs_outputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static void draw_dot(AVFrame *out, int x, int y, uint8_t fg[4])
static int plot_freqs(AVFilterLink *inlink, int64_t pts)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption showfreqs_options[]
static int config_output(AVFilterLink *outlink)
static void plot_freq(ShowFreqsContext *s, int ch, double a, int f, uint8_t fg[4], int *prev_y, AVFrame *out, AVFilterLink *outlink)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
int ff_inlink_queued_samples(AVFilterLink *link)
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
channel
Use these values when setting the channel map with ebur128_set_channel().
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
#define AV_NOPTS_VALUE
Undefined timestamp value.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FORWARD_WANTED(outlink, inlink)
Forward the frame_wanted_out flag from an output link to an input link.
#define FF_FILTER_FORWARD_STATUS(inlink, outlink)
Acknowledge the status on an input link and forward it to an output link.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVChannelLayout ch_layout
Channel layout of the audio data.
uint8_t ** extended_data
pointers to the data planes/channels.
Rational number (pair of numerator and denominator).
Link properties exposed to filter code, but not external callers.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
int64_t frame_count_in
Number of past frames sent through the link.
AVComplexFloat ** fft_data
AVComplexFloat ** fft_input
AVChannelLayout ch_layout
#define av_realloc_f(p, o, n)
static AVFormatContext * ctx
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
static void generate_window_func(float *lut, int N, int win_func, float *overlap)