Go to the documentation of this file.
116 #define OFFSET(x) offsetof(ShowCWTContext, x)
117 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
175 for (
int n = 0; n <
s->nb_threads; n++)
181 for (
int n = 0; n <
s->nb_threads; n++)
217 int frequency_band_count,
218 float frequency_range,
219 float frequency_offset,
220 int frequency_scale,
float deviation)
223 for (
int y = 0; y < frequency_band_count; y++) {
224 float frequency = frequency_range * (1.f - (
float)y / frequency_band_count) + frequency_offset;
225 float frequency_derivative = frequency_range / frequency_band_count;
227 switch (frequency_scale) {
229 frequency =
powf(2.
f, frequency);
230 frequency_derivative *= logf(2.
f) * frequency;
233 frequency = 600.f * sinhf(frequency / 6.
f);
234 frequency_derivative *=
sqrtf(frequency * frequency + 360000.
f) / 6.f;
237 frequency = 700.f * (
powf(10.
f, frequency / 2595.
f) - 1.f);
238 frequency_derivative *= (frequency + 700.f) * logf(10.
f) / 2595.f;
241 frequency = 676170.4f / (47.06538f -
expf(frequency * 0.08950404
f)) - 14678.49
f;
242 frequency_derivative *= (frequency * frequency + 14990.4 * frequency + 4577850.f) / 160514.
f;
263 const int hop_size =
s->hop_size;
265 float *cache0 = (
float *)
s->cache[0]->extended_data[ch];
266 float *cache = (
float *)
s->cache[1]->extended_data[ch];
271 const int offset =
s->hop_index;
279 memset(&cache[
s->hop_index], 0,
280 (hop_size -
s->hop_index) *
sizeof(
float));
281 }
else if (
s->hop_index + fin->
nb_samples < hop_size) {
285 for (
int n = 0; n < hop_size; n++) {
286 src[n].re = cache0[n];
288 src[n + hop_size].re = cache[n];
289 src[n + hop_size].im = 0.f;
292 s->tx_fn(
s->fft[jobnr], dst,
src,
sizeof(*
src));
300 const ptrdiff_t ylinesize =
s->outpicref->linesize[0];
301 const ptrdiff_t ulinesize =
s->outpicref->linesize[1];
302 const ptrdiff_t vlinesize =
s->outpicref->linesize[2];
303 const ptrdiff_t alinesize =
s->outpicref->linesize[3];
304 const float log_factor = 1.f/logf(
s->logarithmic_basis);
305 const int count =
s->frequency_band_count;
306 const int start = (count * jobnr) / nb_jobs;
307 const int end = (count * (jobnr+1)) / nb_jobs;
308 const int ihop_index =
s->ihop_index;
309 const int ihop_size =
s->ihop_size;
310 const int direction =
s->direction;
311 uint8_t *dstY, *dstU, *dstV, *dstA;
312 const int mode =
s->mode;
313 const int w_1 =
s->w - 1;
314 const int x =
s->pos;
317 for (
int y = start; y < end; y++) {
319 y * ihop_size + ihop_index;
324 dstY =
s->outpicref->data[0] + y * ylinesize;
325 dstU =
s->outpicref->data[1] + y * ulinesize;
326 dstV =
s->outpicref->data[2] + y * vlinesize;
327 dstA =
s->outpicref->data[3] ?
s->outpicref->data[3] + y * alinesize :
NULL;
331 dstY =
s->outpicref->data[0] + x * ylinesize + w_1 - y;
332 dstU =
s->outpicref->data[1] + x * ulinesize + w_1 - y;
333 dstV =
s->outpicref->data[2] + x * vlinesize + w_1 - y;
334 dstA =
s->outpicref->data[3] ?
s->outpicref->data[3] + x * alinesize + w_1 - y :
NULL;
344 switch (
s->direction) {
346 memmove(dstY, dstY + 1, w_1);
347 memmove(dstU, dstU + 1, w_1);
348 memmove(dstV, dstV + 1, w_1);
350 memmove(dstA, dstA + 1, w_1);
353 memmove(dstY + 1, dstY, w_1);
354 memmove(dstU + 1, dstU, w_1);
355 memmove(dstV + 1, dstV, w_1);
357 memmove(dstA + 1, dstA, w_1);
376 y * ihop_size + ihop_index;
400 const int nb_channels =
s->nb_channels;
401 const float yf = 1.f / nb_channels;
405 for (
int ch = 0; ch < nb_channels; ch++) {
407 y * ihop_size + ihop_index;
429 U = 0.5f + 0.5f *
U *
Y /
M_PI;
440 Y = 0.5f + 0.5f *
Y /
M_PI;
463 const int ch = *(
int *)
arg;
465 const int output_sample_count =
s->output_sample_count;
466 const int ihop_size =
s->ihop_size;
467 const int ioffset = (
s->output_padding_size - ihop_size) >> 1;
468 const int count =
s->frequency_band_count;
469 const int start = (count * jobnr) / nb_jobs;
470 const int end = (count * (jobnr+1)) / nb_jobs;
472 for (
int y = start; y < end; y++) {
476 const float *kernel = (
const float *)
s->kernel->extended_data[y];
477 const unsigned *
index = (
const unsigned *)
s->index;
478 const int kernel_start =
s->kernel_start[y];
479 const int kernel_stop =
s->kernel_stop[y];
481 memset(isrc, 0,
sizeof(*isrc) * output_sample_count);
482 for (
int i = kernel_start;
i < kernel_stop;
i++) {
483 const unsigned n =
index[
i];
484 const float ff = kernel[
i];
486 isrc[n].
re += ff * dst[
i].
re;
487 isrc[n].
im += ff * dst[
i].
im;
490 s->itx_fn(
s->ifft[jobnr], idst, isrc,
sizeof(*isrc));
492 memcpy(chout, idst + ioffset,
sizeof(*chout) * ihop_size);
501 const int size =
s->input_sample_count;
502 const float scale_factor = 1.f/(
float)
size;
503 const int output_sample_count =
s->output_sample_count;
504 const int fsize =
s->frequency_band_count;
505 unsigned *
index =
s->index;
507 for (
int y = 0; y <
fsize; y++) {
508 float *kernel = (
float *)
s->kernel->extended_data[y];
509 int *kernel_start =
s->kernel_start;
510 int *kernel_stop =
s->kernel_stop;
511 float frequency =
s->frequency_band[y*2];
512 float deviation = 1.f / (
s->frequency_band[y*2+1] *
513 output_sample_count);
515 for (
int n = 0; n <
size; n++) {
516 float ff,
f =
fabsf(n-frequency);
519 ff =
expf(-
f*
f*deviation) * scale_factor;
523 for (
int n = 0; n <
size; n++) {
524 if (kernel[n] != 0.
f) {
530 for (
int n = 0; n <
size; n++) {
531 if (kernel[
size - n - 1] != 0.
f) {
532 kernel_stop[y] =
size - n;
538 for (
int n = 0; n <
size; n++)
539 index[n] = n % output_sample_count;
547 float maximum_frequency =
fminf(
s->maximum_frequency,
inlink->sample_rate * 0.5f);
548 float minimum_frequency =
s->minimum_frequency;
554 switch (
s->direction) {
557 s->frequency_band_count =
s->h;
561 s->frequency_band_count =
s->w;
567 s->nb_channels =
inlink->ch_layout.nb_channels;
570 s->nb_consumed_samples = 65536;
572 s->input_sample_count =
s->nb_consumed_samples;
573 s->hop_size =
s->nb_consumed_samples >> 1;
574 s->input_padding_size = 65536;
575 s->output_padding_size =
FFMAX(16,
s->input_padding_size *
s->pps /
inlink->sample_rate);
584 s->output_sample_count =
s->output_padding_size;
588 s->ihop_size =
s->output_padding_size >> 1;
594 for (
int n = 0; n <
s->nb_threads; n++) {
604 for (
int n = 0; n <
s->nb_threads; n++) {
610 s->frequency_band =
av_calloc(
s->frequency_band_count,
611 sizeof(*
s->frequency_band) * 2);
621 s->index =
av_calloc(
s->input_padding_size,
sizeof(*
s->index));
622 s->kernel_start =
av_calloc(
s->frequency_band_count,
sizeof(*
s->kernel_start));
623 s->kernel_stop =
av_calloc(
s->frequency_band_count,
sizeof(*
s->kernel_stop));
624 if (!
s->outpicref || !
s->fft_in || !
s->fft_out ||
625 !
s->ifft_in || !
s->ifft_out || !
s->kernel_start || !
s->kernel_stop ||
626 !
s->frequency_band || !
s->kernel || !
s->cache[0] || !
s->cache[1] || !
s->index)
629 s->ifft_in->format =
inlink->format;
630 s->ifft_in->nb_samples =
s->ifft_in_size * 2;
631 s->ifft_in->ch_layout.nb_channels =
s->frequency_band_count;
636 s->ifft_out->format =
inlink->format;
637 s->ifft_out->nb_samples =
s->ifft_out_size * 2;
638 s->ifft_out->ch_layout.nb_channels =
s->frequency_band_count;
643 s->kernel->format =
inlink->format;
644 s->kernel->nb_samples =
s->input_padding_size;
645 s->kernel->ch_layout.nb_channels =
s->frequency_band_count;
650 s->outpicref->sample_aspect_ratio = (
AVRational){1,1};
652 for (
int y = 0; y < outlink->
h; y++) {
653 memset(
s->outpicref->data[0] + y *
s->outpicref->linesize[0], 0, outlink->
w);
654 memset(
s->outpicref->data[1] + y *
s->outpicref->linesize[1], 128, outlink->
w);
655 memset(
s->outpicref->data[2] + y *
s->outpicref->linesize[2], 128, outlink->
w);
656 if (
s->outpicref->data[3])
657 memset(
s->outpicref->data[3] + y *
s->outpicref->linesize[3], 0, outlink->
w);
663 minimum_frequency *=
factor;
664 maximum_frequency *=
factor;
666 switch (
s->frequency_scale) {
668 minimum_frequency = logf(minimum_frequency) / logf(2.
f);
669 maximum_frequency = logf(maximum_frequency) / logf(2.
f);
672 minimum_frequency = 6.f * asinhf(minimum_frequency / 600.
f);
673 maximum_frequency = 6.f * asinhf(maximum_frequency / 600.
f);
676 minimum_frequency = 2595.f *
log10f(1.
f + minimum_frequency / 700.
f);
677 maximum_frequency = 2595.f *
log10f(1.
f + maximum_frequency / 700.
f);
680 minimum_frequency = 11.17268f * log(1.
f + (46.06538
f * minimum_frequency) / (minimum_frequency + 14678.49
f));
681 maximum_frequency = 11.17268f * log(1.
f + (46.06538
f * maximum_frequency) / (maximum_frequency + 14678.49
f));
686 s->frequency_band_count, maximum_frequency - minimum_frequency,
687 minimum_frequency,
s->frequency_scale,
s->deviation);
692 switch (
s->direction) {
708 if (strcmp(
s->rate_str,
"auto")) {
711 s->frame_rate =
s->auto_frame_rate;
726 const int nb_planes = 3 + (
s->outpicref->data[3] !=
NULL);
731 switch (
s->direction) {
733 for (
int p = 0; p < nb_planes; p++) {
734 ptrdiff_t linesize =
s->outpicref->linesize[p];
736 for (
int y =
s->h - 1; y > 0; y--) {
737 uint8_t *dst =
s->outpicref->data[p] + y * linesize;
739 memmove(dst, dst - linesize,
s->w);
744 for (
int p = 0; p < nb_planes; p++) {
745 ptrdiff_t linesize =
s->outpicref->linesize[p];
747 for (
int y = 0; y <
s->h - 1; y++) {
748 uint8_t *dst =
s->outpicref->data[p] + y * linesize;
750 memmove(dst, dst + linesize,
s->w);
763 switch (
s->direction) {
766 if (
s->pos >=
s->w) {
780 if (
s->pos >=
s->h) {
795 switch (
s->direction) {
811 switch (
s->direction) {
813 for (
int p = 0; p < nb_planes; p++) {
814 ptrdiff_t linesize =
s->outpicref->linesize[p];
815 const int size =
s->w -
s->pos;
816 const int fill = p > 0 && p < 3 ? 128 : 0;
817 const int x =
s->pos;
819 for (
int y = 0; y <
s->h; y++) {
820 uint8_t *dst =
s->outpicref->data[p] + y * linesize + x;
822 memset(dst, fill,
size);
827 for (
int p = 0; p < nb_planes; p++) {
828 ptrdiff_t linesize =
s->outpicref->linesize[p];
829 const int size =
s->w -
s->pos;
830 const int fill = p > 0 && p < 3 ? 128 : 0;
832 for (
int y = 0; y <
s->h; y++) {
833 uint8_t *dst =
s->outpicref->data[p] + y * linesize;
835 memset(dst, fill,
size);
840 for (
int p = 0; p < nb_planes; p++) {
841 ptrdiff_t linesize =
s->outpicref->linesize[p];
842 const int fill = p > 0 && p < 3 ? 128 : 0;
844 for (
int y =
s->pos; y < s->
h; y++) {
845 uint8_t *dst =
s->outpicref->data[p] + y * linesize;
847 memset(dst, fill,
s->w);
852 for (
int p = 0; p < nb_planes; p++) {
853 ptrdiff_t linesize =
s->outpicref->linesize[p];
854 const int fill = p > 0 && p < 3 ? 128 : 0;
856 for (
int y =
s->h -
s->pos; y >= 0; y--) {
857 uint8_t *dst =
s->outpicref->data[p] + y * linesize;
859 memset(dst, fill,
s->w);
869 int64_t pts_offset =
s->new_frame ? 0LL :
av_rescale(
s->ihop_index,
s->hop_size,
s->ihop_size);
872 s->outpicref->duration = 1;
876 if (
s->ihop_index >=
s->ihop_size)
882 if (
s->old_pts <
s->outpicref->pts) {
892 s->old_pts =
s->outpicref->pts;
908 const int count =
s->nb_channels;
909 const int start = (count * jobnr) / nb_jobs;
910 const int end = (count * (jobnr+1)) / nb_jobs;
912 for (
int ch = start; ch < end; ch++)
931 if (
s->ihop_index == 0) {
938 if (
ret > 0 ||
s->eof) {
940 FFMIN(
s->nb_threads,
s->nb_channels));
942 if ((
s->hop_index == 0 &&
s->slide !=
SLIDE_FRAME) ||
s->new_frame) {
943 s->in_pts = fin->
pts;
949 s->hop_index =
s->hop_size;
954 if (
s->hop_index >=
s->hop_size ||
s->ihop_index > 0) {
960 for (
int ch = 0; ch <
s->nb_channels &&
s->ihop_index == 0; ch++) {
989 s->hop_index >=
s->hop_size ||
s->eof) {
1019 .description =
NULL_IF_CONFIG_SMALL(
"Convert input audio to a CWT (Continuous Wavelet Transform) spectrum video output."),
1026 .priv_class = &showcwt_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.
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
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
static int run_channels_cwt_prepare(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
#define u(width, name, range_min, range_max)
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
#define AVERROR_EOF
End of file.
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).
@ AVCOL_RANGE_JPEG
Full range content.
static const AVOption showcwt_options[]
#define FILTER_QUERY_FUNC(func)
const char * name
Filter name.
static int output_frame(AVFilterContext *ctx)
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...
static void compute_kernel(AVFilterContext *ctx)
const AVFilter ff_avf_showcwt
static av_cold void uninit(AVFilterContext *ctx)
static av_always_inline float scale(float x, float s)
static __device__ float fabsf(float a)
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
static float remap_log(float value, float log_factor)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
float fminf(float, float)
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...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static int64_t fsize(FILE *f)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
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.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Rational number (pair of numerator and denominator).
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
static void frequency_band(float *frequency_band, int frequency_band_count, float frequency_range, float frequency_offset, int frequency_scale, float deviation)
static __device__ float sqrtf(float a)
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
static int run_channel_cwt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static AVRational av_make_q(int num, int den)
Create an AVRational.
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int query_formats(AVFilterContext *ctx)
AVFilterContext * src
source filter
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
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
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static const AVFilterPad showcwt_inputs[]
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
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
static int run_channel_cwt_prepare(AVFilterContext *ctx, void *arg, int jobnr, int ch)
uint8_t ** extended_data
pointers to the data planes/channels.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
AVSampleFormat
Audio sample formats.
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 default value
AVFILTER_DEFINE_CLASS(showcwt)
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)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void * av_calloc(size_t nmemb, size_t size)
static int activate(AVFilterContext *ctx)
AVRational auto_frame_rate
#define FFSWAP(type, a, b)
static int config_output(AVFilterLink *outlink)
int h
agreed upon image height
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static const int factor[16]
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define FILTER_OUTPUTS(array)
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
static const AVFilterPad showcwt_outputs[]
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.