2011-12-25 17:37:53 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Stefano Sabatini
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2012-07-23 11:44:48 +02:00
|
|
|
* audio to video multimedia filter
|
2011-12-25 17:37:53 +01:00
|
|
|
*/
|
|
|
|
|
2014-12-24 15:03:26 +01:00
|
|
|
#include "libavutil/avassert.h"
|
2016-01-19 22:09:55 +01:00
|
|
|
#include "libavutil/avstring.h"
|
2012-11-13 14:16:48 +01:00
|
|
|
#include "libavutil/channel_layout.h"
|
2011-12-25 17:37:53 +01:00
|
|
|
#include "libavutil/opt.h"
|
|
|
|
#include "libavutil/parseutils.h"
|
|
|
|
#include "avfilter.h"
|
2019-05-30 20:31:03 +02:00
|
|
|
#include "filters.h"
|
2011-12-25 17:37:53 +01:00
|
|
|
#include "formats.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "video.h"
|
2012-06-22 14:33:09 +02:00
|
|
|
#include "internal.h"
|
2011-12-25 17:37:53 +01:00
|
|
|
|
2013-01-22 12:11:36 +01:00
|
|
|
enum ShowWavesMode {
|
|
|
|
MODE_POINT,
|
|
|
|
MODE_LINE,
|
2014-08-04 11:40:47 +02:00
|
|
|
MODE_P2P,
|
2013-12-26 12:08:24 +01:00
|
|
|
MODE_CENTERED_LINE,
|
2013-01-22 12:11:36 +01:00
|
|
|
MODE_NB,
|
|
|
|
};
|
|
|
|
|
2016-01-21 20:07:12 +01:00
|
|
|
enum ShowWavesScale {
|
|
|
|
SCALE_LIN,
|
|
|
|
SCALE_LOG,
|
2016-08-10 11:34:04 +02:00
|
|
|
SCALE_SQRT,
|
|
|
|
SCALE_CBRT,
|
2016-01-21 20:07:12 +01:00
|
|
|
SCALE_NB,
|
|
|
|
};
|
|
|
|
|
2018-03-23 19:02:51 +01:00
|
|
|
enum ShowWavesDrawMode {
|
|
|
|
DRAW_SCALE,
|
|
|
|
DRAW_FULL,
|
|
|
|
DRAW_NB,
|
|
|
|
};
|
|
|
|
|
2020-07-17 14:25:13 +02:00
|
|
|
enum ShowWavesFilterMode {
|
|
|
|
FILTER_AVERAGE,
|
|
|
|
FILTER_PEAK,
|
|
|
|
FILTER_NB,
|
|
|
|
};
|
|
|
|
|
2014-12-24 15:03:26 +01:00
|
|
|
struct frame_node {
|
|
|
|
AVFrame *frame;
|
|
|
|
struct frame_node *next;
|
|
|
|
};
|
|
|
|
|
2017-05-12 20:00:49 +02:00
|
|
|
typedef struct ShowWavesContext {
|
2011-12-25 17:37:53 +01:00
|
|
|
const AVClass *class;
|
|
|
|
int w, h;
|
|
|
|
AVRational rate;
|
2016-01-19 22:09:55 +01:00
|
|
|
char *colors;
|
2011-12-25 17:37:53 +01:00
|
|
|
int buf_idx;
|
2014-08-04 11:40:47 +02:00
|
|
|
int16_t *buf_idy; /* y coordinate of previous sample for each channel */
|
2013-03-10 01:30:30 +01:00
|
|
|
AVFrame *outpicref;
|
2011-12-25 17:37:53 +01:00
|
|
|
int n;
|
2016-01-19 22:09:55 +01:00
|
|
|
int pixstep;
|
2011-12-25 17:37:53 +01:00
|
|
|
int sample_count_mod;
|
2015-03-07 02:44:04 +01:00
|
|
|
int mode; ///< ShowWavesMode
|
2016-01-21 20:07:12 +01:00
|
|
|
int scale; ///< ShowWavesScale
|
2018-03-23 19:02:51 +01:00
|
|
|
int draw_mode; ///< ShowWavesDrawMode
|
2013-12-26 13:39:49 +01:00
|
|
|
int split_channels;
|
2020-07-17 14:25:13 +02:00
|
|
|
int filter_mode;
|
2016-01-19 22:09:55 +01:00
|
|
|
uint8_t *fg;
|
2016-01-21 20:07:12 +01:00
|
|
|
|
|
|
|
int (*get_h)(int16_t sample, int height);
|
2013-12-26 12:57:20 +01:00
|
|
|
void (*draw_sample)(uint8_t *buf, int height, int linesize,
|
2016-01-21 20:07:12 +01:00
|
|
|
int16_t *prev_y, const uint8_t color[4], int h);
|
2014-12-24 15:03:26 +01:00
|
|
|
|
|
|
|
/* single picture */
|
|
|
|
int single_pic;
|
|
|
|
struct frame_node *audio_frames;
|
|
|
|
struct frame_node *last_frame;
|
|
|
|
int64_t total_samples;
|
|
|
|
int64_t *sum; /* abs sum of the samples per channel */
|
2011-12-25 17:37:53 +01:00
|
|
|
} ShowWavesContext;
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(ShowWavesContext, x)
|
2012-08-13 13:40:01 +02:00
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
2011-12-25 17:37:53 +01:00
|
|
|
|
|
|
|
static const AVOption showwaves_options[] = {
|
2012-08-13 13:40:01 +02:00
|
|
|
{ "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
|
|
|
|
{ "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
|
2013-04-11 14:17:20 +02:00
|
|
|
{ "mode", "select display mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_POINT}, 0, MODE_NB-1, FLAGS, "mode"},
|
2014-08-20 22:32:06 +02:00
|
|
|
{ "point", "draw a point for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_POINT}, .flags=FLAGS, .unit="mode"},
|
|
|
|
{ "line", "draw a line for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_LINE}, .flags=FLAGS, .unit="mode"},
|
|
|
|
{ "p2p", "draw a line between samples", 0, AV_OPT_TYPE_CONST, {.i64=MODE_P2P}, .flags=FLAGS, .unit="mode"},
|
|
|
|
{ "cline", "draw a centered line for each sample", 0, AV_OPT_TYPE_CONST, {.i64=MODE_CENTERED_LINE}, .flags=FLAGS, .unit="mode"},
|
2012-09-05 14:26:01 +02:00
|
|
|
{ "n", "set how many samples to show in the same point", OFFSET(n), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS },
|
2016-06-09 05:00:22 +02:00
|
|
|
{ "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
|
|
|
|
{ "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
|
2015-09-08 23:32:06 +02:00
|
|
|
{ "split_channels", "draw channels separately", OFFSET(split_channels), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
|
2016-01-19 22:09:55 +01:00
|
|
|
{ "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
|
2016-01-21 20:07:12 +01:00
|
|
|
{ "scale", "set amplitude scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, SCALE_NB-1, FLAGS, .unit="scale" },
|
|
|
|
{ "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_LIN}, .flags=FLAGS, .unit="scale"},
|
|
|
|
{ "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_LOG}, .flags=FLAGS, .unit="scale"},
|
2016-08-10 11:34:04 +02:00
|
|
|
{ "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_SQRT}, .flags=FLAGS, .unit="scale"},
|
|
|
|
{ "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_CBRT}, .flags=FLAGS, .unit="scale"},
|
2018-03-23 19:02:51 +01:00
|
|
|
{ "draw", "set draw mode", OFFSET(draw_mode), AV_OPT_TYPE_INT, {.i64 = DRAW_SCALE}, 0, DRAW_NB-1, FLAGS, .unit="draw" },
|
|
|
|
{ "scale", "scale pixel values for each drawn sample", 0, AV_OPT_TYPE_CONST, {.i64=DRAW_SCALE}, .flags=FLAGS, .unit="draw"},
|
|
|
|
{ "full", "draw every pixel for sample directly", 0, AV_OPT_TYPE_CONST, {.i64=DRAW_FULL}, .flags=FLAGS, .unit="draw"},
|
2013-09-07 14:13:50 +02:00
|
|
|
{ NULL }
|
2011-12-25 17:37:53 +01:00
|
|
|
};
|
|
|
|
|
2012-06-22 14:33:09 +02:00
|
|
|
AVFILTER_DEFINE_CLASS(showwaves);
|
2011-12-25 17:37:53 +01:00
|
|
|
|
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
ShowWavesContext *showwaves = ctx->priv;
|
|
|
|
|
2013-03-10 01:30:30 +01:00
|
|
|
av_frame_free(&showwaves->outpicref);
|
2014-08-04 11:40:47 +02:00
|
|
|
av_freep(&showwaves->buf_idy);
|
2016-01-19 22:09:55 +01:00
|
|
|
av_freep(&showwaves->fg);
|
2014-12-24 15:03:26 +01:00
|
|
|
|
|
|
|
if (showwaves->single_pic) {
|
|
|
|
struct frame_node *node = showwaves->audio_frames;
|
|
|
|
while (node) {
|
|
|
|
struct frame_node *tmp = node;
|
|
|
|
|
|
|
|
node = node->next;
|
|
|
|
av_frame_free(&tmp->frame);
|
|
|
|
av_freep(&tmp);
|
|
|
|
}
|
|
|
|
av_freep(&showwaves->sum);
|
|
|
|
showwaves->last_frame = NULL;
|
|
|
|
}
|
2011-12-25 17:37:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
AVFilterFormats *formats = NULL;
|
|
|
|
AVFilterChannelLayouts *layouts = NULL;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
2012-11-05 14:34:08 +01:00
|
|
|
static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE };
|
2016-01-19 22:09:55 +01:00
|
|
|
static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };
|
2015-10-05 05:39:25 +02:00
|
|
|
int ret;
|
2011-12-25 17:37:53 +01:00
|
|
|
|
|
|
|
/* set input audio formats */
|
|
|
|
formats = ff_make_format_list(sample_fmts);
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
|
|
|
|
return ret;
|
2011-12-25 17:37:53 +01:00
|
|
|
|
|
|
|
layouts = ff_all_channel_layouts();
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
|
|
|
|
return ret;
|
2011-12-25 17:37:53 +01:00
|
|
|
|
|
|
|
formats = ff_all_samplerates();
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
|
|
|
|
return ret;
|
2011-12-25 17:37:53 +01:00
|
|
|
|
|
|
|
/* set output video format */
|
|
|
|
formats = ff_make_format_list(pix_fmts);
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
|
|
|
|
return ret;
|
2011-12-25 17:37:53 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-21 20:07:12 +01:00
|
|
|
static int get_lin_h(int16_t sample, int height)
|
|
|
|
{
|
|
|
|
return height/2 - av_rescale(sample, height/2, INT16_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_lin_h2(int16_t sample, int height)
|
|
|
|
{
|
|
|
|
return av_rescale(FFABS(sample), height, INT16_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_log_h(int16_t sample, int height)
|
|
|
|
{
|
|
|
|
return height/2 - FFSIGN(sample) * (log10(1 + FFABS(sample)) * (height/2) / log10(1 + INT16_MAX));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_log_h2(int16_t sample, int height)
|
|
|
|
{
|
|
|
|
return log10(1 + FFABS(sample)) * height / log10(1 + INT16_MAX);
|
|
|
|
}
|
|
|
|
|
2016-08-10 11:34:04 +02:00
|
|
|
static int get_sqrt_h(int16_t sample, int height)
|
|
|
|
{
|
|
|
|
return height/2 - FFSIGN(sample) * (sqrt(FFABS(sample)) * (height/2) / sqrt(INT16_MAX));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_sqrt_h2(int16_t sample, int height)
|
|
|
|
{
|
|
|
|
return sqrt(FFABS(sample)) * height / sqrt(INT16_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_cbrt_h(int16_t sample, int height)
|
|
|
|
{
|
|
|
|
return height/2 - FFSIGN(sample) * (cbrt(FFABS(sample)) * (height/2) / cbrt(INT16_MAX));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_cbrt_h2(int16_t sample, int height)
|
|
|
|
{
|
|
|
|
return cbrt(FFABS(sample)) * height / cbrt(INT16_MAX);
|
|
|
|
}
|
|
|
|
|
2018-03-23 19:02:51 +01:00
|
|
|
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)
|
2016-01-19 22:09:55 +01:00
|
|
|
{
|
|
|
|
if (h >= 0 && h < height) {
|
|
|
|
buf[h * linesize + 0] += color[0];
|
|
|
|
buf[h * linesize + 1] += color[1];
|
|
|
|
buf[h * linesize + 2] += color[2];
|
|
|
|
buf[h * linesize + 3] += color[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-23 19:02:51 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (h >= 0 && h < height) {
|
|
|
|
buf[h * linesize + 0] = color[0];
|
|
|
|
buf[h * linesize + 1] = color[1];
|
|
|
|
buf[h * linesize + 2] = color[2];
|
|
|
|
buf[h * linesize + 3] = color[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2016-01-19 22:09:55 +01:00
|
|
|
{
|
|
|
|
int k;
|
|
|
|
int start = height/2;
|
|
|
|
int end = av_clip(h, 0, height-1);
|
|
|
|
if (start > end)
|
|
|
|
FFSWAP(int16_t, start, end);
|
|
|
|
for (k = start; k < end; k++) {
|
|
|
|
buf[k * linesize + 0] += color[0];
|
|
|
|
buf[k * linesize + 1] += color[1];
|
|
|
|
buf[k * linesize + 2] += color[2];
|
|
|
|
buf[k * linesize + 3] += color[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-23 19:02:51 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
int start = height/2;
|
|
|
|
int end = av_clip(h, 0, height-1);
|
|
|
|
if (start > end)
|
|
|
|
FFSWAP(int16_t, start, end);
|
|
|
|
for (k = start; k < end; k++) {
|
|
|
|
buf[k * linesize + 0] = color[0];
|
|
|
|
buf[k * linesize + 1] = color[1];
|
|
|
|
buf[k * linesize + 2] = color[2];
|
|
|
|
buf[k * linesize + 3] = color[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2016-01-19 22:09:55 +01:00
|
|
|
{
|
|
|
|
int k;
|
|
|
|
if (h >= 0 && h < height) {
|
|
|
|
buf[h * linesize + 0] += color[0];
|
|
|
|
buf[h * linesize + 1] += color[1];
|
|
|
|
buf[h * linesize + 2] += color[2];
|
|
|
|
buf[h * linesize + 3] += color[3];
|
|
|
|
if (*prev_y && h != *prev_y) {
|
|
|
|
int start = *prev_y;
|
|
|
|
int end = av_clip(h, 0, height-1);
|
|
|
|
if (start > end)
|
|
|
|
FFSWAP(int16_t, start, end);
|
|
|
|
for (k = start + 1; k < end; k++) {
|
|
|
|
buf[k * linesize + 0] += color[0];
|
|
|
|
buf[k * linesize + 1] += color[1];
|
|
|
|
buf[k * linesize + 2] += color[2];
|
|
|
|
buf[k * linesize + 3] += color[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*prev_y = h;
|
|
|
|
}
|
|
|
|
|
2018-03-23 19:02:51 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
if (h >= 0 && h < height) {
|
|
|
|
buf[h * linesize + 0] = color[0];
|
|
|
|
buf[h * linesize + 1] = color[1];
|
|
|
|
buf[h * linesize + 2] = color[2];
|
|
|
|
buf[h * linesize + 3] = color[3];
|
|
|
|
if (*prev_y && h != *prev_y) {
|
|
|
|
int start = *prev_y;
|
|
|
|
int end = av_clip(h, 0, height-1);
|
|
|
|
if (start > end)
|
|
|
|
FFSWAP(int16_t, start, end);
|
|
|
|
for (k = start + 1; k < end; k++) {
|
|
|
|
buf[k * linesize + 0] = color[0];
|
|
|
|
buf[k * linesize + 1] = color[1];
|
|
|
|
buf[k * linesize + 2] = color[2];
|
|
|
|
buf[k * linesize + 3] = color[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*prev_y = 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)
|
2016-01-19 22:09:55 +01:00
|
|
|
{
|
|
|
|
int k;
|
|
|
|
const int start = (height - h) / 2;
|
|
|
|
const int end = start + h;
|
|
|
|
for (k = start; k < end; k++) {
|
|
|
|
buf[k * linesize + 0] += color[0];
|
|
|
|
buf[k * linesize + 1] += color[1];
|
|
|
|
buf[k * linesize + 2] += color[2];
|
|
|
|
buf[k * linesize + 3] += color[3];
|
|
|
|
}
|
|
|
|
}
|
2018-03-23 19:02:51 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
const int start = (height - h) / 2;
|
|
|
|
const int end = start + h;
|
|
|
|
for (k = start; k < end; k++) {
|
|
|
|
buf[k * linesize + 0] = color[0];
|
|
|
|
buf[k * linesize + 1] = color[1];
|
|
|
|
buf[k * linesize + 2] = color[2];
|
|
|
|
buf[k * linesize + 3] = color[3];
|
|
|
|
}
|
|
|
|
}
|
2016-01-19 22:09:55 +01:00
|
|
|
|
|
|
|
static void draw_sample_point_gray(uint8_t *buf, int height, int linesize,
|
2016-01-21 20:07:12 +01:00
|
|
|
int16_t *prev_y,
|
|
|
|
const uint8_t color[4], int h)
|
2016-01-19 22:09:55 +01:00
|
|
|
{
|
|
|
|
if (h >= 0 && h < height)
|
|
|
|
buf[h * linesize] += color[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_sample_line_gray(uint8_t *buf, int height, int linesize,
|
2016-01-21 20:07:12 +01:00
|
|
|
int16_t *prev_y,
|
|
|
|
const uint8_t color[4], int h)
|
2016-01-19 22:09:55 +01:00
|
|
|
{
|
|
|
|
int k;
|
|
|
|
int start = height/2;
|
|
|
|
int end = av_clip(h, 0, height-1);
|
|
|
|
if (start > end)
|
|
|
|
FFSWAP(int16_t, start, end);
|
|
|
|
for (k = start; k < end; k++)
|
|
|
|
buf[k * linesize] += color[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_sample_p2p_gray(uint8_t *buf, int height, int linesize,
|
2016-01-21 20:07:12 +01:00
|
|
|
int16_t *prev_y,
|
|
|
|
const uint8_t color[4], int h)
|
2016-01-19 22:09:55 +01:00
|
|
|
{
|
|
|
|
int k;
|
|
|
|
if (h >= 0 && h < height) {
|
|
|
|
buf[h * linesize] += color[0];
|
|
|
|
if (*prev_y && h != *prev_y) {
|
|
|
|
int start = *prev_y;
|
|
|
|
int end = av_clip(h, 0, height-1);
|
|
|
|
if (start > end)
|
|
|
|
FFSWAP(int16_t, start, end);
|
|
|
|
for (k = start + 1; k < end; k++)
|
|
|
|
buf[k * linesize] += color[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*prev_y = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_sample_cline_gray(uint8_t *buf, int height, int linesize,
|
2016-01-21 20:07:12 +01:00
|
|
|
int16_t *prev_y,
|
|
|
|
const uint8_t color[4], int h)
|
2016-01-19 22:09:55 +01:00
|
|
|
{
|
|
|
|
int k;
|
|
|
|
const int start = (height - h) / 2;
|
|
|
|
const int end = start + h;
|
|
|
|
for (k = start; k < end; k++)
|
|
|
|
buf[k * linesize] += color[0];
|
|
|
|
}
|
|
|
|
|
2011-12-25 17:37:53 +01:00
|
|
|
static int config_output(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
ShowWavesContext *showwaves = ctx->priv;
|
2014-08-04 11:40:47 +02:00
|
|
|
int nb_channels = inlink->channels;
|
2016-01-19 22:09:55 +01:00
|
|
|
char *colors, *saveptr = NULL;
|
|
|
|
uint8_t x;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
if (showwaves->single_pic)
|
|
|
|
showwaves->n = 1;
|
2011-12-25 17:37:53 +01:00
|
|
|
|
2013-03-16 20:00:39 +01:00
|
|
|
if (!showwaves->n)
|
2019-05-28 11:07:47 +02:00
|
|
|
showwaves->n = FFMAX(1, av_rescale_q(inlink->sample_rate, av_make_q(1, showwaves->w), showwaves->rate));
|
2011-12-25 17:37:53 +01:00
|
|
|
|
2013-04-11 14:17:20 +02:00
|
|
|
showwaves->buf_idx = 0;
|
2014-08-04 11:40:47 +02:00
|
|
|
if (!(showwaves->buf_idy = av_mallocz_array(nb_channels, sizeof(*showwaves->buf_idy)))) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Could not allocate showwaves buffer\n");
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
2011-12-25 17:37:53 +01:00
|
|
|
outlink->w = showwaves->w;
|
|
|
|
outlink->h = showwaves->h;
|
|
|
|
outlink->sample_aspect_ratio = (AVRational){1,1};
|
|
|
|
|
|
|
|
outlink->frame_rate = av_div_q((AVRational){inlink->sample_rate,showwaves->n},
|
|
|
|
(AVRational){showwaves->w,1});
|
|
|
|
|
2012-07-14 18:26:04 +02:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "s:%dx%d r:%f n:%d\n",
|
2011-12-25 17:37:53 +01:00
|
|
|
showwaves->w, showwaves->h, av_q2d(outlink->frame_rate), showwaves->n);
|
2016-01-19 22:09:55 +01:00
|
|
|
|
|
|
|
switch (outlink->format) {
|
|
|
|
case AV_PIX_FMT_GRAY8:
|
|
|
|
switch (showwaves->mode) {
|
|
|
|
case MODE_POINT: showwaves->draw_sample = draw_sample_point_gray; break;
|
|
|
|
case MODE_LINE: showwaves->draw_sample = draw_sample_line_gray; break;
|
|
|
|
case MODE_P2P: showwaves->draw_sample = draw_sample_p2p_gray; break;
|
|
|
|
case MODE_CENTERED_LINE: showwaves->draw_sample = draw_sample_cline_gray; break;
|
|
|
|
default:
|
|
|
|
return AVERROR_BUG;
|
|
|
|
}
|
|
|
|
showwaves->pixstep = 1;
|
|
|
|
break;
|
|
|
|
case AV_PIX_FMT_RGBA:
|
|
|
|
switch (showwaves->mode) {
|
2018-03-23 19:02:51 +01:00
|
|
|
case MODE_POINT: showwaves->draw_sample = showwaves->draw_mode == DRAW_SCALE ? draw_sample_point_rgba_scale : draw_sample_point_rgba_full; break;
|
|
|
|
case MODE_LINE: showwaves->draw_sample = showwaves->draw_mode == DRAW_SCALE ? draw_sample_line_rgba_scale : draw_sample_line_rgba_full; break;
|
|
|
|
case MODE_P2P: showwaves->draw_sample = showwaves->draw_mode == DRAW_SCALE ? draw_sample_p2p_rgba_scale : draw_sample_p2p_rgba_full; break;
|
|
|
|
case MODE_CENTERED_LINE: showwaves->draw_sample = showwaves->draw_mode == DRAW_SCALE ? draw_sample_cline_rgba_scale : draw_sample_cline_rgba_full; break;
|
2016-01-19 22:09:55 +01:00
|
|
|
default:
|
|
|
|
return AVERROR_BUG;
|
|
|
|
}
|
|
|
|
showwaves->pixstep = 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-21 20:07:12 +01:00
|
|
|
switch (showwaves->scale) {
|
|
|
|
case SCALE_LIN:
|
|
|
|
switch (showwaves->mode) {
|
|
|
|
case MODE_POINT:
|
|
|
|
case MODE_LINE:
|
|
|
|
case MODE_P2P: showwaves->get_h = get_lin_h; break;
|
|
|
|
case MODE_CENTERED_LINE: showwaves->get_h = get_lin_h2; break;
|
|
|
|
default:
|
|
|
|
return AVERROR_BUG;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCALE_LOG:
|
|
|
|
switch (showwaves->mode) {
|
|
|
|
case MODE_POINT:
|
|
|
|
case MODE_LINE:
|
|
|
|
case MODE_P2P: showwaves->get_h = get_log_h; break;
|
|
|
|
case MODE_CENTERED_LINE: showwaves->get_h = get_log_h2; break;
|
|
|
|
default:
|
|
|
|
return AVERROR_BUG;
|
|
|
|
}
|
|
|
|
break;
|
2016-08-10 11:34:04 +02:00
|
|
|
case SCALE_SQRT:
|
|
|
|
switch (showwaves->mode) {
|
|
|
|
case MODE_POINT:
|
|
|
|
case MODE_LINE:
|
|
|
|
case MODE_P2P: showwaves->get_h = get_sqrt_h; break;
|
|
|
|
case MODE_CENTERED_LINE: showwaves->get_h = get_sqrt_h2; break;
|
|
|
|
default:
|
|
|
|
return AVERROR_BUG;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCALE_CBRT:
|
|
|
|
switch (showwaves->mode) {
|
|
|
|
case MODE_POINT:
|
|
|
|
case MODE_LINE:
|
|
|
|
case MODE_P2P: showwaves->get_h = get_cbrt_h; break;
|
|
|
|
case MODE_CENTERED_LINE: showwaves->get_h = get_cbrt_h2; break;
|
|
|
|
default:
|
|
|
|
return AVERROR_BUG;
|
|
|
|
}
|
|
|
|
break;
|
2016-01-21 20:07:12 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 22:09:55 +01:00
|
|
|
showwaves->fg = av_malloc_array(nb_channels, 4 * sizeof(*showwaves->fg));
|
|
|
|
if (!showwaves->fg)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
colors = av_strdup(showwaves->colors);
|
|
|
|
if (!colors)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2018-03-23 19:02:51 +01:00
|
|
|
if (showwaves->draw_mode == DRAW_SCALE) {
|
|
|
|
/* multiplication factor, pre-computed to avoid in-loop divisions */
|
|
|
|
x = 255 / ((showwaves->split_channels ? 1 : nb_channels) * showwaves->n);
|
|
|
|
} else {
|
|
|
|
x = 255;
|
|
|
|
}
|
2016-01-19 22:09:55 +01:00
|
|
|
if (outlink->format == AV_PIX_FMT_RGBA) {
|
|
|
|
uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff };
|
|
|
|
|
|
|
|
for (ch = 0; ch < nb_channels; ch++) {
|
|
|
|
char *color;
|
|
|
|
|
|
|
|
color = av_strtok(ch == 0 ? colors : NULL, " |", &saveptr);
|
|
|
|
if (color)
|
|
|
|
av_parse_color(fg, color, -1, ctx);
|
|
|
|
showwaves->fg[4*ch + 0] = fg[0] * x / 255.;
|
|
|
|
showwaves->fg[4*ch + 1] = fg[1] * x / 255.;
|
|
|
|
showwaves->fg[4*ch + 2] = fg[2] * x / 255.;
|
|
|
|
showwaves->fg[4*ch + 3] = fg[3] * x / 255.;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (ch = 0; ch < nb_channels; ch++)
|
|
|
|
showwaves->fg[4 * ch + 0] = x;
|
|
|
|
}
|
|
|
|
av_free(colors);
|
|
|
|
|
2011-12-25 17:37:53 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-22 21:11:23 +01:00
|
|
|
inline static int push_frame(AVFilterLink *outlink)
|
2011-12-25 17:37:53 +01:00
|
|
|
{
|
2014-08-04 11:40:47 +02:00
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
2011-12-25 17:37:53 +01:00
|
|
|
ShowWavesContext *showwaves = outlink->src->priv;
|
2014-08-04 11:40:47 +02:00
|
|
|
int nb_channels = inlink->channels;
|
|
|
|
int ret, i;
|
2011-12-25 17:37:53 +01:00
|
|
|
|
2015-10-02 16:04:47 +02:00
|
|
|
ret = ff_filter_frame(outlink, showwaves->outpicref);
|
2011-12-25 17:37:53 +01:00
|
|
|
showwaves->outpicref = NULL;
|
|
|
|
showwaves->buf_idx = 0;
|
2014-11-09 14:19:36 +01:00
|
|
|
for (i = 0; i < nb_channels; i++)
|
2014-08-04 11:40:47 +02:00
|
|
|
showwaves->buf_idy[i] = 0;
|
2013-01-22 21:11:23 +01:00
|
|
|
return ret;
|
2011-12-25 17:37:53 +01:00
|
|
|
}
|
|
|
|
|
2014-12-24 15:03:26 +01:00
|
|
|
static int push_single_pic(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
ShowWavesContext *showwaves = ctx->priv;
|
2019-04-21 21:06:25 +02:00
|
|
|
int64_t n = 0, column_max_samples = showwaves->total_samples / outlink->w;
|
|
|
|
int64_t remaining_samples = showwaves->total_samples - (column_max_samples * outlink->w);
|
|
|
|
int64_t last_column_samples = column_max_samples + remaining_samples;
|
2014-12-24 15:03:26 +01:00
|
|
|
AVFrame *out = showwaves->outpicref;
|
|
|
|
struct frame_node *node;
|
|
|
|
const int nb_channels = inlink->channels;
|
|
|
|
const int ch_height = showwaves->split_channels ? outlink->h / nb_channels : outlink->h;
|
|
|
|
const int linesize = out->linesize[0];
|
2016-01-19 22:09:55 +01:00
|
|
|
const int pixstep = showwaves->pixstep;
|
2014-12-24 15:03:26 +01:00
|
|
|
int col = 0;
|
|
|
|
int64_t *sum = showwaves->sum;
|
|
|
|
|
2019-04-21 21:06:25 +02:00
|
|
|
if (column_max_samples == 0) {
|
2015-09-03 14:52:18 +02:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Too few samples\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2019-04-21 21:06:25 +02:00
|
|
|
av_log(ctx, AV_LOG_DEBUG, "Create frame averaging %"PRId64" samples per column\n", column_max_samples);
|
2014-12-24 15:03:26 +01:00
|
|
|
|
|
|
|
memset(sum, 0, nb_channels);
|
|
|
|
|
|
|
|
for (node = showwaves->audio_frames; node; node = node->next) {
|
|
|
|
int i;
|
|
|
|
const AVFrame *frame = node->frame;
|
|
|
|
const int16_t *p = (const int16_t *)frame->data[0];
|
|
|
|
|
|
|
|
for (i = 0; i < frame->nb_samples; i++) {
|
2019-04-21 21:06:25 +02:00
|
|
|
int64_t max_samples = col == outlink->w - 1 ? last_column_samples: column_max_samples;
|
2014-12-24 15:03:26 +01:00
|
|
|
int ch;
|
|
|
|
|
2020-07-17 14:25:13 +02:00
|
|
|
switch (showwaves->filter_mode) {
|
|
|
|
case FILTER_AVERAGE:
|
|
|
|
for (ch = 0; ch < nb_channels; ch++)
|
|
|
|
sum[ch] += abs(p[ch + i*nb_channels]) << 1;
|
|
|
|
break;
|
|
|
|
case FILTER_PEAK:
|
|
|
|
for (ch = 0; ch < nb_channels; ch++)
|
|
|
|
sum[ch] = FFMAX(sum[ch], abs(p[ch + i*nb_channels]));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-21 21:06:25 +02:00
|
|
|
n++;
|
|
|
|
if (n == max_samples) {
|
2014-12-24 15:03:26 +01:00
|
|
|
for (ch = 0; ch < nb_channels; ch++) {
|
2020-07-17 14:25:13 +02:00
|
|
|
int16_t sample = sum[ch] / (showwaves->filter_mode == FILTER_AVERAGE ? max_samples : 1);
|
2016-01-19 22:09:55 +01:00
|
|
|
uint8_t *buf = out->data[0] + col * pixstep;
|
2016-01-21 20:07:12 +01:00
|
|
|
int h;
|
|
|
|
|
2014-12-24 15:03:26 +01:00
|
|
|
if (showwaves->split_channels)
|
|
|
|
buf += ch*ch_height*linesize;
|
|
|
|
av_assert0(col < outlink->w);
|
2016-01-21 20:07:12 +01:00
|
|
|
h = showwaves->get_h(sample, ch_height);
|
|
|
|
showwaves->draw_sample(buf, ch_height, linesize, &showwaves->buf_idy[ch], &showwaves->fg[ch * 4], h);
|
2014-12-24 15:03:26 +01:00
|
|
|
sum[ch] = 0;
|
|
|
|
}
|
|
|
|
col++;
|
|
|
|
n = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return push_frame(outlink);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-25 17:37:53 +01:00
|
|
|
static int request_frame(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
ShowWavesContext *showwaves = outlink->src->priv;
|
|
|
|
AVFilterLink *inlink = outlink->src->inputs[0];
|
|
|
|
int ret;
|
|
|
|
|
2015-10-02 16:04:47 +02:00
|
|
|
ret = ff_request_frame(inlink);
|
2014-12-24 15:03:26 +01:00
|
|
|
if (ret == AVERROR_EOF && showwaves->outpicref) {
|
|
|
|
if (showwaves->single_pic)
|
|
|
|
push_single_pic(outlink);
|
|
|
|
else
|
|
|
|
push_frame(outlink);
|
|
|
|
}
|
|
|
|
|
2011-12-25 17:37:53 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-24 15:03:26 +01:00
|
|
|
static int alloc_out_frame(ShowWavesContext *showwaves, const int16_t *p,
|
|
|
|
const AVFilterLink *inlink, AVFilterLink *outlink,
|
|
|
|
const AVFrame *in)
|
|
|
|
{
|
|
|
|
if (!showwaves->outpicref) {
|
|
|
|
int j;
|
|
|
|
AVFrame *out = showwaves->outpicref =
|
|
|
|
ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
|
|
|
if (!out)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
out->width = outlink->w;
|
|
|
|
out->height = outlink->h;
|
|
|
|
out->pts = in->pts + av_rescale_q((p - (int16_t *)in->data[0]) / inlink->channels,
|
|
|
|
av_make_q(1, inlink->sample_rate),
|
|
|
|
outlink->time_base);
|
|
|
|
for (j = 0; j < outlink->h; j++)
|
2016-01-19 22:09:55 +01:00
|
|
|
memset(out->data[0] + j*out->linesize[0], 0, outlink->w * showwaves->pixstep);
|
2014-12-24 15:03:26 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold int init(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
ShowWavesContext *showwaves = ctx->priv;
|
|
|
|
|
|
|
|
if (!strcmp(ctx->filter->name, "showwavespic")) {
|
|
|
|
showwaves->single_pic = 1;
|
|
|
|
showwaves->mode = MODE_CENTERED_LINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CONFIG_SHOWWAVES_FILTER
|
|
|
|
|
|
|
|
static int showwaves_filter_frame(AVFilterLink *inlink, AVFrame *insamples)
|
2011-12-25 17:37:53 +01:00
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
ShowWavesContext *showwaves = ctx->priv;
|
2013-03-10 01:30:30 +01:00
|
|
|
const int nb_samples = insamples->nb_samples;
|
|
|
|
AVFrame *outpicref = showwaves->outpicref;
|
2011-12-25 17:37:53 +01:00
|
|
|
int16_t *p = (int16_t *)insamples->data[0];
|
2013-07-13 23:46:27 +02:00
|
|
|
int nb_channels = inlink->channels;
|
2013-12-26 12:57:20 +01:00
|
|
|
int i, j, ret = 0;
|
2016-01-19 22:09:55 +01:00
|
|
|
const int pixstep = showwaves->pixstep;
|
2011-12-25 17:37:53 +01:00
|
|
|
const int n = showwaves->n;
|
2013-12-26 13:39:49 +01:00
|
|
|
const int ch_height = showwaves->split_channels ? outlink->h / nb_channels : outlink->h;
|
2011-12-25 17:37:53 +01:00
|
|
|
|
|
|
|
/* draw data in the buffer */
|
|
|
|
for (i = 0; i < nb_samples; i++) {
|
2014-12-24 15:03:26 +01:00
|
|
|
|
|
|
|
ret = alloc_out_frame(showwaves, p, inlink, outlink, insamples);
|
|
|
|
if (ret < 0)
|
|
|
|
goto end;
|
|
|
|
outpicref = showwaves->outpicref;
|
|
|
|
|
2013-12-26 13:39:49 +01:00
|
|
|
for (j = 0; j < nb_channels; j++) {
|
2016-01-19 22:09:55 +01:00
|
|
|
uint8_t *buf = outpicref->data[0] + showwaves->buf_idx * pixstep;
|
2014-12-24 15:03:26 +01:00
|
|
|
const int linesize = outpicref->linesize[0];
|
2016-01-21 20:07:12 +01:00
|
|
|
int h;
|
|
|
|
|
2013-12-26 13:39:49 +01:00
|
|
|
if (showwaves->split_channels)
|
|
|
|
buf += j*ch_height*linesize;
|
2016-01-21 20:07:12 +01:00
|
|
|
h = showwaves->get_h(*p++, ch_height);
|
|
|
|
showwaves->draw_sample(buf, ch_height, linesize,
|
|
|
|
&showwaves->buf_idy[j], &showwaves->fg[j * 4], h);
|
2013-12-26 13:39:49 +01:00
|
|
|
}
|
2013-01-22 12:11:36 +01:00
|
|
|
|
2011-12-25 17:37:53 +01:00
|
|
|
showwaves->sample_count_mod++;
|
|
|
|
if (showwaves->sample_count_mod == n) {
|
|
|
|
showwaves->sample_count_mod = 0;
|
|
|
|
showwaves->buf_idx++;
|
|
|
|
}
|
2019-05-30 20:31:03 +02:00
|
|
|
if (showwaves->buf_idx == showwaves->w ||
|
|
|
|
(ff_outlink_get_status(inlink) && i == nb_samples - 1))
|
2013-01-22 21:11:23 +01:00
|
|
|
if ((ret = push_frame(outlink)) < 0)
|
|
|
|
break;
|
2013-01-21 23:00:20 +01:00
|
|
|
outpicref = showwaves->outpicref;
|
2011-12-25 17:37:53 +01:00
|
|
|
}
|
|
|
|
|
2014-12-24 15:03:26 +01:00
|
|
|
end:
|
2013-03-10 01:30:30 +01:00
|
|
|
av_frame_free(&insamples);
|
2013-01-22 21:11:23 +01:00
|
|
|
return ret;
|
2011-12-25 17:37:53 +01:00
|
|
|
}
|
|
|
|
|
2019-05-30 20:31:03 +02:00
|
|
|
static int activate(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
ShowWavesContext *showwaves = ctx->priv;
|
|
|
|
AVFrame *in;
|
|
|
|
const int nb_samples = showwaves->n * outlink->w;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
|
|
|
|
|
|
|
|
ret = ff_inlink_consume_samples(inlink, nb_samples, nb_samples, &in);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (ret > 0)
|
|
|
|
return showwaves_filter_frame(inlink, in);
|
|
|
|
|
|
|
|
FF_FILTER_FORWARD_STATUS(inlink, outlink);
|
|
|
|
FF_FILTER_FORWARD_WANTED(outlink, inlink);
|
|
|
|
|
|
|
|
return FFERROR_NOT_READY;
|
|
|
|
}
|
|
|
|
|
2012-11-28 20:01:59 +01:00
|
|
|
static const AVFilterPad showwaves_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad showwaves_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = config_output,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2013-10-29 11:50:56 +01:00
|
|
|
AVFilter ff_avf_showwaves = {
|
2013-09-07 14:13:50 +02:00
|
|
|
.name = "showwaves",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Convert input audio to a video output."),
|
2013-12-26 12:57:20 +01:00
|
|
|
.init = init,
|
2013-09-07 14:13:50 +02:00
|
|
|
.uninit = uninit,
|
|
|
|
.query_formats = query_formats,
|
|
|
|
.priv_size = sizeof(ShowWavesContext),
|
|
|
|
.inputs = showwaves_inputs,
|
2019-05-30 20:31:03 +02:00
|
|
|
.activate = activate,
|
2013-09-07 14:13:50 +02:00
|
|
|
.outputs = showwaves_outputs,
|
|
|
|
.priv_class = &showwaves_class,
|
2011-12-25 17:37:53 +01:00
|
|
|
};
|
2014-12-24 15:03:26 +01:00
|
|
|
|
|
|
|
#endif // CONFIG_SHOWWAVES_FILTER
|
|
|
|
|
|
|
|
#if CONFIG_SHOWWAVESPIC_FILTER
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(ShowWavesContext, x)
|
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
|
|
|
|
|
|
|
static const AVOption showwavespic_options[] = {
|
|
|
|
{ "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
|
|
|
|
{ "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
|
2015-11-21 22:04:54 +01:00
|
|
|
{ "split_channels", "draw channels separately", OFFSET(split_channels), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
|
2016-01-19 22:09:55 +01:00
|
|
|
{ "colors", "set channels colors", OFFSET(colors), AV_OPT_TYPE_STRING, {.str = "red|green|blue|yellow|orange|lime|pink|magenta|brown" }, 0, 0, FLAGS },
|
2016-01-21 20:07:12 +01:00
|
|
|
{ "scale", "set amplitude scale", OFFSET(scale), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, SCALE_NB-1, FLAGS, .unit="scale" },
|
|
|
|
{ "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_LIN}, .flags=FLAGS, .unit="scale"},
|
|
|
|
{ "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_LOG}, .flags=FLAGS, .unit="scale"},
|
2017-03-09 10:23:28 +01:00
|
|
|
{ "sqrt", "square root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_SQRT}, .flags=FLAGS, .unit="scale"},
|
|
|
|
{ "cbrt", "cubic root", 0, AV_OPT_TYPE_CONST, {.i64=SCALE_CBRT}, .flags=FLAGS, .unit="scale"},
|
2019-04-26 08:17:11 +02:00
|
|
|
{ "draw", "set draw mode", OFFSET(draw_mode), AV_OPT_TYPE_INT, {.i64 = DRAW_SCALE}, 0, DRAW_NB-1, FLAGS, .unit="draw" },
|
|
|
|
{ "scale", "scale pixel values for each drawn sample", 0, AV_OPT_TYPE_CONST, {.i64=DRAW_SCALE}, .flags=FLAGS, .unit="draw"},
|
|
|
|
{ "full", "draw every pixel for sample directly", 0, AV_OPT_TYPE_CONST, {.i64=DRAW_FULL}, .flags=FLAGS, .unit="draw"},
|
2020-07-17 14:25:13 +02:00
|
|
|
{ "filter", "set filter mode", OFFSET(filter_mode), AV_OPT_TYPE_INT, {.i64 = FILTER_AVERAGE}, 0, FILTER_NB-1, FLAGS, .unit="filter" },
|
|
|
|
{ "average", "use average samples", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_AVERAGE}, .flags=FLAGS, .unit="filter"},
|
|
|
|
{ "peak", "use peak samples", 0, AV_OPT_TYPE_CONST, {.i64=FILTER_PEAK}, .flags=FLAGS, .unit="filter"},
|
2014-12-24 15:03:26 +01:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(showwavespic);
|
|
|
|
|
|
|
|
static int showwavespic_config_input(AVFilterLink *inlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
ShowWavesContext *showwaves = ctx->priv;
|
|
|
|
|
|
|
|
if (showwaves->single_pic) {
|
|
|
|
showwaves->sum = av_mallocz_array(inlink->channels, sizeof(*showwaves->sum));
|
|
|
|
if (!showwaves->sum)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int showwavespic_filter_frame(AVFilterLink *inlink, AVFrame *insamples)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
ShowWavesContext *showwaves = ctx->priv;
|
|
|
|
int16_t *p = (int16_t *)insamples->data[0];
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (showwaves->single_pic) {
|
|
|
|
struct frame_node *f;
|
|
|
|
|
|
|
|
ret = alloc_out_frame(showwaves, p, inlink, outlink, insamples);
|
|
|
|
if (ret < 0)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* queue the audio frame */
|
|
|
|
f = av_malloc(sizeof(*f));
|
|
|
|
if (!f) {
|
|
|
|
ret = AVERROR(ENOMEM);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
f->frame = insamples;
|
|
|
|
f->next = NULL;
|
|
|
|
if (!showwaves->last_frame) {
|
|
|
|
showwaves->audio_frames =
|
|
|
|
showwaves->last_frame = f;
|
|
|
|
} else {
|
|
|
|
showwaves->last_frame->next = f;
|
|
|
|
showwaves->last_frame = f;
|
|
|
|
}
|
|
|
|
showwaves->total_samples += insamples->nb_samples;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
av_frame_free(&insamples);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const AVFilterPad showwavespic_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = showwavespic_config_input,
|
|
|
|
.filter_frame = showwavespic_filter_frame,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad showwavespic_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = config_output,
|
|
|
|
.request_frame = request_frame,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
AVFilter ff_avf_showwavespic = {
|
|
|
|
.name = "showwavespic",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Convert input audio to a video output single picture."),
|
|
|
|
.init = init,
|
|
|
|
.uninit = uninit,
|
|
|
|
.query_formats = query_formats,
|
|
|
|
.priv_size = sizeof(ShowWavesContext),
|
|
|
|
.inputs = showwavespic_inputs,
|
|
|
|
.outputs = showwavespic_outputs,
|
|
|
|
.priv_class = &showwavespic_class,
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CONFIG_SHOWWAVESPIC_FILTER
|