Go to the documentation of this file.
78 #define OFFSET(x) offsetof(ShowFreqsContext, x)
79 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
103 {
"colors",
"set channels colors",
OFFSET(colors),
AV_OPT_TYPE_STRING, {.str =
"red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0,
FLAGS },
154 float overlap,
scale;
158 s->nb_freq =
s->fft_size / 2;
159 s->win_size =
s->fft_size;
164 "The window size might be too high.\n");
171 for (
i = 0;
i <
s->nb_channels;
i++) {
180 s->nb_channels =
inlink->ch_layout.nb_channels;
182 s->bypass =
av_calloc(
s->nb_channels,
sizeof(*
s->bypass));
185 s->fft_input =
av_calloc(
s->nb_channels,
sizeof(*
s->fft_input));
188 s->fft_data =
av_calloc(
s->nb_channels,
sizeof(*
s->fft_data));
191 s->avg_data =
av_calloc(
s->nb_channels,
sizeof(*
s->avg_data));
194 for (
i = 0;
i <
s->nb_channels;
i++) {
197 s->avg_data[
i] =
av_calloc(
s->nb_freq,
sizeof(**
s->avg_data));
198 if (!
s->fft_data[
i] || !
s->avg_data[
i] || !
s->fft_input[
i])
204 sizeof(*
s->window_func_lut));
205 if (!
s->window_func_lut)
208 if (
s->overlap == 1.)
209 s->overlap = overlap;
210 s->hop_size = (1. -
s->overlap) *
s->win_size;
211 if (
s->hop_size < 1) {
216 for (
s->scale = 0,
i = 0; i < s->win_size;
i++) {
217 s->scale +=
s->window_func_lut[
i] *
s->window_func_lut[
i];
233 s->nb_draw_channels =
s->nb_channels;
235 if (strcmp(
s->ch_layout_str,
"all")) {
236 int nb_draw_channels = 0;
240 for (
int ch = 0; ch <
s->nb_channels; ch++) {
244 nb_draw_channels +=
s->bypass[ch] == 0;
247 s->nb_draw_channels = nb_draw_channels;
258 if ((
color & 0xffffff) != 0)
268 return (
s->w/(
float)
s->nb_freq)*
f;
270 return s->w-pow(
s->w, (
s->nb_freq-
f-1)/(
s->nb_freq-1.));
272 return pow(
s->w,
f/(
s->nb_freq-1.));
284 return pow(
s->w, (
s->nb_freq-
f-1)/(
s->nb_freq-1.))-
285 pow(
s->w, (
s->nb_freq-
f-2)/(
s->nb_freq-1.));
287 return pow(
s->w, (
f+1)/(
s->nb_freq-1.))-
288 pow(
s->w,
f /(
s->nb_freq-1.));
295 double a,
int f, uint8_t fg[4],
int *prev_y,
299 const float min =
s->minamp;
300 const float avg =
s->avg_data[ch][
f];
303 int end = outlink->
h;
323 y =
a * outlink->
h - 1;
326 end = (outlink->
h /
s->nb_draw_channels) * (ch + 1);
327 y = (outlink->
h /
s->nb_draw_channels) * ch +
a * (outlink->
h /
s->nb_draw_channels) - 1;
343 y =
av_clip(
s->avg_data[ch][
f], 0, outlink->
h - 1);
353 for (x = sx + 1; x < sx + bsize && x <
w; x++)
355 for (
i = y;
i <= *prev_y;
i++)
358 for (
i = *prev_y;
i <= y;
i++)
360 for (x = sx + 1; x < sx + bsize && x <
w; x++)
366 for (x = sx; x < sx + bsize && x <
w; x++)
367 for (
i = y;
i < end;
i++)
371 for (x = sx; x < sx + bsize && x <
w; x++)
383 const int win_size =
s->win_size;
389 for (ch = 0; ch <
s->nb_channels; ch++) {
395 for (n = 0; n < win_size; n++) {
396 s->fft_input[ch][n].re = p[n] *
s->window_func_lut[n];
397 s->fft_input[ch][n].im = 0;
402 for (ch = 0; ch <
s->nb_channels; ch++) {
406 s->tx_fn(
s->fft,
s->fft_data[ch],
s->fft_input[ch],
sizeof(
float));
410 if (
s->old_pts >=
s->pts)
414 #define RE(x, ch) s->fft_data[ch][x].re
415 #define IM(x, ch) s->fft_data[ch][x].im
416 #define M(a, b) (sqrt((a) * (a) + (b) * (b)))
417 #define P(a, b) (atan2((b), (a)))
429 for (n = 0; n < outlink->
h; n++)
430 memset(
out->data[0] +
out->linesize[0] * n, 0, outlink->
w * 4);
432 for (ch = 0; ch <
s->nb_channels; ch++) {
433 uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
444 switch (
s->data_mode) {
446 for (
f = 0;
f <
s->nb_freq;
f++) {
453 for (
f = 0;
f <
s->nb_freq;
f++) {
460 for (
f = 0;
f <
s->nb_freq;
f++) {
480 const int offset =
s->win_size -
s->hop_size;
484 float *dst = (
float *)
s->window->extended_data[ch];
486 memmove(dst, &dst[
s->hop_size],
offset *
sizeof(
float));
533 for (
i = 0;
i <
s->nb_channels;
i++) {
573 .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])
static const AVFilterPad showfreqs_inputs[]
#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...
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
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
static void generate_window_func(float *lut, int N, int win_func, float *overlap)
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#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 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)
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_calloc(size_t nmemb, size_t size)
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.
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_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
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.
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.