Go to the documentation of this file.
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++) {
173 s->nb_channels =
inlink->ch_layout.nb_channels;
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++) {
561 .priv_class = &showfreqs_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
@ AV_SAMPLE_FMT_FLTP
float, planar
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static enum AVSampleFormat sample_fmts[]
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.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static void draw_dot(AVFrame *out, int x, int y, uint8_t fg[4])
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.
#define WIN_FUNC_OPTION(win_func_opt_name, win_func_offset, flag, default_window_func)
const char * name
Filter name.
const AVFilter ff_avf_showfreqs
int nb_channels
Number of channels in this layout.
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
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...
Link properties exposed to filter code, but not external callers.
AVComplexFloat ** fft_data
AVChannelLayout ch_layout
Channel layout of the audio data.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
static int config_output(AVFilterLink *outlink)
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().
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static enum AVPixelFormat pix_fmts[]
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type of AVComplexFloat, AVComplexDouble or AVComplex...
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define av_realloc_f(p, o, n)
AVComplexFloat ** fft_input
Describe the class of an AVClass context structure.
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.
Rational number (pair of numerator and denominator).
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int activate(AVFilterContext *ctx)
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVFilterContext * src
source filter
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
FF_FILTER_FORWARD_WANTED(outlink, inlink)
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
int w
agreed upon image width
uint8_t ** extended_data
pointers to the data planes/channels.
AVSampleFormat
Audio sample formats.
#define FILTER_QUERY_FUNC2(func)
static int get_sx(ShowFreqsContext *s, int f)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const char * name
Pad name.
int ff_inlink_queued_samples(AVFilterLink *link)
void * av_calloc(size_t nmemb, size_t size)
static void plot_freq(ShowFreqsContext *s, int ch, double a, int f, uint8_t fg[4], int *prev_y, AVFrame *out, AVFilterLink *outlink)
static const AVFilterPad showfreqs_outputs[]
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
static const AVOption showfreqs_options[]
int h
agreed upon image height
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.
@ AV_OPT_TYPE_INT
Underlying C type is int.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
static av_cold void uninit(AVFilterContext *ctx)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
static float get_bsize(ShowFreqsContext *s, int f)
char * av_strdup(const char *s)
Duplicate a string.
AVChannelLayout ch_layout
static void scale(int *out, const int *in, const int w, const int h, const int shift)
FF_FILTER_FORWARD_STATUS(inlink, outlink)
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
static int plot_freqs(AVFilterLink *inlink, int64_t pts)
@ 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...
AVFILTER_DEFINE_CLASS(showfreqs)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
int64_t frame_count_in
Number of past frames sent through the link.
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.