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 },
155 float overlap,
scale = 1.f;
159 s->nb_freq =
s->fft_size / 2;
160 s->win_size =
s->fft_size;
165 "The window size might be too high.\n");
172 for (
i = 0;
i <
s->nb_channels;
i++) {
181 s->nb_channels =
inlink->ch_layout.nb_channels;
183 s->bypass =
av_calloc(
s->nb_channels,
sizeof(*
s->bypass));
186 s->fft_input =
av_calloc(
s->nb_channels,
sizeof(*
s->fft_input));
189 s->fft_data =
av_calloc(
s->nb_channels,
sizeof(*
s->fft_data));
192 s->avg_data =
av_calloc(
s->nb_channels,
sizeof(*
s->avg_data));
195 for (
i = 0;
i <
s->nb_channels;
i++) {
198 s->avg_data[
i] =
av_calloc(
s->nb_freq,
sizeof(**
s->avg_data));
199 if (!
s->fft_data[
i] || !
s->avg_data[
i] || !
s->fft_input[
i])
205 sizeof(*
s->window_func_lut));
206 if (!
s->window_func_lut)
209 if (
s->overlap == 1.)
210 s->overlap = overlap;
211 s->hop_size = (1. -
s->overlap) *
s->win_size;
212 if (
s->hop_size < 1) {
217 for (
s->scale = 0,
i = 0; i < s->win_size;
i++) {
218 s->scale +=
s->window_func_lut[
i] *
s->window_func_lut[
i];
234 s->nb_draw_channels =
s->nb_channels;
236 if (strcmp(
s->ch_layout_str,
"all")) {
237 int nb_draw_channels = 0;
241 for (
int ch = 0; ch <
s->nb_channels; ch++) {
245 nb_draw_channels +=
s->bypass[ch] == 0;
248 s->nb_draw_channels = nb_draw_channels;
259 if ((
color & 0xffffff) != 0)
269 return (
s->w/(
float)
s->nb_freq)*
f;
271 return s->w-pow(
s->w, (
s->nb_freq-
f-1)/(
s->nb_freq-1.));
273 return pow(
s->w,
f/(
s->nb_freq-1.));
285 return pow(
s->w, (
s->nb_freq-
f-1)/(
s->nb_freq-1.))-
286 pow(
s->w, (
s->nb_freq-
f-2)/(
s->nb_freq-1.));
288 return pow(
s->w, (
f+1)/(
s->nb_freq-1.))-
289 pow(
s->w,
f /(
s->nb_freq-1.));
296 double a,
int f, uint8_t fg[4],
int *prev_y,
300 const float min =
s->minamp;
301 const float avg =
s->avg_data[ch][
f];
304 int end = outlink->
h;
324 y =
a * outlink->
h - 1;
327 end = (outlink->
h /
s->nb_draw_channels) * (ch + 1);
328 y = (outlink->
h /
s->nb_draw_channels) * ch +
a * (outlink->
h /
s->nb_draw_channels) - 1;
344 y =
av_clip(
s->avg_data[ch][
f], 0, outlink->
h - 1);
354 for (x = sx + 1; x < sx + bsize && x <
w; x++)
356 for (
i = y;
i <= *prev_y;
i++)
359 for (
i = *prev_y;
i <= y;
i++)
361 for (x = sx + 1; x < sx + bsize && x <
w; x++)
367 for (x = sx; x < sx + bsize && x <
w; x++)
368 for (
i = y;
i < end;
i++)
372 for (x = sx; x < sx + bsize && x <
w; x++)
384 const int win_size =
s->win_size;
390 for (ch = 0; ch <
s->nb_channels; ch++) {
396 for (n = 0; n < win_size; n++) {
397 s->fft_input[ch][n].re = p[n] *
s->window_func_lut[n];
398 s->fft_input[ch][n].im = 0;
403 for (ch = 0; ch <
s->nb_channels; ch++) {
411 if (
s->old_pts >=
s->pts)
415 #define RE(x, ch) s->fft_data[ch][x].re
416 #define IM(x, ch) s->fft_data[ch][x].im
417 #define M(a, b) (sqrt((a) * (a) + (b) * (b)))
418 #define P(a, b) (atan2((b), (a)))
430 for (n = 0; n < outlink->
h; n++)
431 memset(
out->data[0] +
out->linesize[0] * n, 0, outlink->
w * 4);
433 for (ch = 0; ch <
s->nb_channels; ch++) {
434 uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
445 switch (
s->data_mode) {
447 for (
f = 0;
f <
s->nb_freq;
f++) {
454 for (
f = 0;
f <
s->nb_freq;
f++) {
461 for (
f = 0;
f <
s->nb_freq;
f++) {
482 const int offset =
s->win_size -
s->hop_size;
486 float *dst = (
float *)
s->window->extended_data[ch];
488 memmove(dst, &dst[
s->hop_size],
offset *
sizeof(
float));
535 for (
i = 0;
i <
s->nb_channels;
i++) {
568 .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
A list of supported channel layouts.
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[]
enum MovChannelLayoutTag * layouts
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
offset must point to 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.
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 FILTER_QUERY_FUNC(func)
static int query_formats(AVFilterContext *ctx)
#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...
AVComplexFloat ** fft_data
AVChannelLayout ch_layout
Channel layout of the audio data.
static av_always_inline float scale(float x, float s)
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.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
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_INPUTS(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
offset must point to 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)
#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.
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
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
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.
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.
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.
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
int64_t frame_count_in
Number of past frames sent through the link.
FF_FILTER_FORWARD_STATUS(inlink, outlink)
#define FILTER_OUTPUTS(array)
static int plot_freqs(AVFilterLink *inlink, int64_t pts)
AVFILTER_DEFINE_CLASS(showfreqs)
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.