26#include "config_components.h"
96 int16_t *prev_y,
const uint8_t
color[4],
int h);
106#define OFFSET(x) offsetof(ShowWavesContext, x)
107#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
121 {
"colors",
"set channels colors",
OFFSET(colors),
AV_OPT_TYPE_STRING, {.str =
"red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0,
FLAGS },
222 const uint8_t
color[4],
int h)
225 buf[
h * linesize + 0] +=
color[0];
226 buf[
h * linesize + 1] +=
color[1];
227 buf[
h * linesize + 2] +=
color[2];
228 buf[
h * linesize + 3] +=
color[3];
234 const uint8_t
color[4],
int h)
243 const uint8_t
color[4],
int h)
249 FFSWAP(int16_t, start, end);
250 bufk = buf + start * linesize;
251 for (
int k = start; k < end; k++, bufk += linesize) {
261 const uint8_t
color[4],
int h)
268 FFSWAP(int16_t, start, end);
269 bufk = buf + start * linesize;
270 for (
int k = start; k < end; k++, bufk += linesize)
276 const uint8_t
color[4],
int h)
279 buf[
h * linesize + 0] +=
color[0];
280 buf[
h * linesize + 1] +=
color[1];
281 buf[
h * linesize + 2] +=
color[2];
282 buf[
h * linesize + 3] +=
color[3];
283 if (*prev_y &&
h != *prev_y) {
288 FFSWAP(int16_t, start, end);
289 bufk = buf + (start + 1) * linesize;
290 for (
int k = start + 1; k < end; k++, bufk += linesize) {
303 const uint8_t
color[4],
int h)
308 if (*prev_y &&
h != *prev_y) {
313 FFSWAP(int16_t, start, end);
314 bufk = buf + (start + 1) * linesize;
315 for (
int k = start + 1; k < end; k++, bufk += linesize)
324 const uint8_t
color[4],
int h)
326 const int start = (
height -
h) / 2;
327 const int end = start +
h;
328 uint8_t *bufk = buf + start * linesize;
329 for (
int k = start; k < end; k++, bufk += linesize) {
339 const uint8_t
color[4],
int h)
342 const int start = (
height -
h) / 2;
343 const int end = start +
h;
344 uint8_t *bufk = buf + start * linesize;
345 for (
int k = start; k < end; k++, bufk += linesize)
351 const uint8_t
color[4],
int h)
354 buf[
h * linesize] +=
color[0];
359 const uint8_t
color[4],
int h)
365 FFSWAP(int16_t, start, end);
366 for (k = start; k < end; k++)
367 buf[k * linesize] +=
color[0];
372 const uint8_t
color[4],
int h)
376 buf[
h * linesize] +=
color[0];
377 if (*prev_y &&
h != *prev_y) {
381 FFSWAP(int16_t, start, end);
382 for (k = start + 1; k < end; k++)
383 buf[k * linesize] +=
color[0];
391 const uint8_t
color[4],
int h)
394 const int start = (
height -
h) / 2;
395 const int end = start +
h;
396 for (k = start; k < end; k++)
397 buf[k * linesize] +=
color[0];
407 char *colors, *saveptr =
NULL;
418 if (!showwaves->
n.
num || !showwaves->
n.
den) {
434 showwaves->
n.
num, showwaves->
n.
den);
443 outlink->
w = showwaves->
w;
444 outlink->
h = showwaves->
h;
450 switch (outlink->
format) {
452 switch (showwaves->
mode) {
463 switch (showwaves->
mode) {
475 switch (showwaves->
scale) {
477 switch (showwaves->
mode) {
487 switch (showwaves->
mode) {
497 switch (showwaves->
mode) {
507 switch (showwaves->
mode) {
533 uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
535 for (ch = 0; ch < nb_channels; ch++) {
541 showwaves->
fg[4*ch + 0] = fg[0] * x / 255.;
542 showwaves->
fg[4*ch + 1] = fg[1] * x / 255.;
543 showwaves->
fg[4*ch + 2] = fg[2] * x / 255.;
544 showwaves->
fg[4*ch + 3] = fg[3] * x / 255.;
547 for (ch = 0; ch < nb_channels; ch++)
548 showwaves->
fg[4 * ch + 0] = x;
571 for (
int i = 0;
i < nb_channels;
i++)
583 int64_t last_column_samples = column_max_samples + remaining_samples;
587 const int ch_height = showwaves->
split_channels ? outlink->
h / nb_channels : outlink->
h;
588 const int linesize =
out->linesize[0];
589 const int pixstep = showwaves->
pixstep;
593 if (column_max_samples == 0) {
598 av_log(
ctx,
AV_LOG_DEBUG,
"Create frame averaging %"PRId64
" samples per column\n", column_max_samples);
600 memset(sum, 0, nb_channels *
sizeof(*sum));
605 const int16_t *p = (
const int16_t *)
frame->data[0];
607 for (
i = 0;
i <
frame->nb_samples;
i++) {
608 int64_t max_samples = col == outlink->
w - 1 ? last_column_samples: column_max_samples;
613 for (ch = 0; ch < nb_channels; ch++)
614 sum[ch] +=
abs(p[ch +
i*nb_channels]);
617 for (ch = 0; ch < nb_channels; ch++)
618 sum[ch] =
FFMAX(sum[ch],
abs(p[ch +
i*nb_channels]));
623 if (n == max_samples) {
624 for (ch = 0; ch < nb_channels; ch++) {
626 uint8_t *buf =
out->data[0] + col * pixstep;
630 buf += ch*ch_height*linesize;
633 showwaves->
draw_sample(buf, ch_height, linesize, &showwaves->
buf_idy[ch], &showwaves->
fg[ch * 4],
h);
668 out->width = outlink->
w;
669 out->height = outlink->
h;
670 for (
int j = 0; j < outlink->
h; j++)
671 memset(
out->data[0] + j*
out->linesize[0], 0, outlink->
w * showwaves->
pixstep);
680 if (!strcmp(
ctx->filter->name,
"showwavespic")) {
688#if CONFIG_SHOWWAVES_FILTER
697 const int16_t *
p = (
const int16_t *)insamples->
data[0];
698 int16_t *history = showwaves->history;
699 const int nb_channels = inlink->ch_layout.nb_channels;
700 int i, j, ret = 0, linesize;
701 const int pixstep = showwaves->pixstep;
702 const int ch_height = showwaves->split_channels ? outlink->h / nb_channels : outlink->h;
703 const int history_nb_samples = showwaves->history_nb_samples;
704 const int split_channels = showwaves->split_channels;
708 int16_t *buf_idy = showwaves->buf_idy;
709 int idx = showwaves->history_index;
710 int buf_idx = showwaves->buf_idx;
711 const uint8_t *fg = showwaves->fg;
712 const int w = showwaves->w;
715 for (
int n = 0; n < nb_samples * nb_channels; n++) {
716 history[idx++] =
p[n];
717 if (idx >= history_nb_samples)
720 showwaves->history_index = idx;
725 outpicref = showwaves->outpicref;
726 linesize = outpicref->linesize[0];
729 dst = outpicref->data[0];
730 for (
i = 0;
i < history_nb_samples;
i++) {
731 for (j = 0; j < nb_channels; j++) {
732 uint8_t *buf =
dst + buf_idx * pixstep;
736 buf += j*ch_height*linesize;
737 h = showwaves->get_h(history[idx++], ch_height);
738 if (idx >= history_nb_samples)
740 showwaves->draw_sample(buf, ch_height, linesize,
741 &buf_idy[j], &fg[j * 4],
h);
744 showwaves->c =
av_add_q(showwaves->c, i_n);
745 if (
av_cmp_q(showwaves->c, u_q) >= 0) {
753 showwaves->buf_idx = buf_idx;
755 if ((ret =
push_frame(outlink, history_nb_samples -
i - 1, insamples->pts)) < 0)
757 outpicref = showwaves->outpicref;
776 nb_samples = (q.
num + (q.
den / 2)) / q.
den;
782 return showwaves_filter_frame(inlink, in);
800 .p.name =
"showwaves",
802 .p.priv_class = &showwaves_class,
814#if CONFIG_SHOWWAVESPIC_FILTER
816#define OFFSET(x) offsetof(ShowWavesContext, x)
817#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
819static const AVOption showwavespic_options[] = {
823 {
"colors",
"set channels colors",
OFFSET(colors),
AV_OPT_TYPE_STRING, {.str =
"red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0,
FLAGS },
840static int showwavespic_config_input(
AVFilterLink *inlink)
874 f->frame = insamples;
897 .config_props = showwavespic_config_input,
898 .filter_frame = showwavespic_filter_frame,
912 .p.name =
"showwavespic",
914 .p.priv_class = &showwavespic_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)
static int request_frame(AVFilterLink *outlink)
const FFFilter ff_avf_showwavespic
const FFFilter ff_avf_showwaves
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int get_sqrt_h(int16_t sample, int height)
static int get_lin_h2(int16_t sample, int height)
static int push_single_pic(AVFilterLink *outlink)
static void draw_sample_point_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static int get_sqrt_h2(int16_t sample, int height)
static void draw_sample_line_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static void draw_sample_cline_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static int get_cbrt_h2(int16_t sample, int height)
static void draw_sample_p2p_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static int request_frame(AVFilterLink *outlink)
static void draw_sample_line_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static void draw_sample_p2p_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static int get_lin_h(int16_t sample, int height)
static void draw_sample_point_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static void draw_sample_line_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static const AVOption showwaves_options[]
static void draw_sample_cline_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static void draw_sample_cline_rgba_full(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static av_cold void uninit(AVFilterContext *ctx)
static int alloc_out_frame(ShowWavesContext *showwaves, AVFilterLink *outlink)
static int get_log_h(int16_t sample, int height)
static int config_output(AVFilterLink *outlink)
static int get_cbrt_h(int16_t sample, int height)
static int get_log_h2(int16_t sample, int height)
static void draw_sample_point_gray(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
static int push_frame(AVFilterLink *outlink, int i, int64_t pts)
static void draw_sample_p2p_rgba_scale(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
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.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
int(* init)(AVBSFContext *ctx)
@ 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_RATIONAL
Underlying C type is AVRational.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ 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...
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_EOF
End of file.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational av_add_q(AVRational b, AVRational c)
Add two rationals.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static AVRational av_make_q(int num, int den)
Create an AVRational.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
AVRational av_sub_q(AVRational b, AVRational c)
Subtract one rational from another.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
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_S16
signed 16 bits
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().
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.
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
static enum AVPixelFormat pix_fmts[]
#define FFSWAP(type, a, b)
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
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_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
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.
int sample_rate
samples per second
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
int format
agreed upon media format
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).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int64_t duration
Duration of the frame, in the same units as pts.
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.
int draw_mode
ShowWavesDrawMode.
void(* draw_sample)(uint8_t *buf, int height, int linesize, int16_t *prev_y, const uint8_t color[4], int h)
struct frame_node * last_frame
int(* get_h)(int16_t sample, int height)
struct frame_node * audio_frames
#define av_malloc_array(a, b)
static AVFormatContext * ctx
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.