61 #define OFFSET(x) offsetof(AudioHistogramContext, x)
62 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
125 s->shistogram =
av_calloc(
s->w,
s->dchannels *
sizeof(*
s->shistogram));
129 s->achistogram =
av_calloc(
s->w,
s->dchannels *
sizeof(*
s->achistogram));
145 s->histogram_h =
s->h *
s->phisto;
146 s->ypos =
s->h *
s->phisto;
150 if (!
s->combine_buffer)
162 const int H =
s->histogram_h;
168 if (!
s->out ||
s->out->width != outlink->
w ||
169 s->out->height != outlink->
h) {
176 for (n =
H; n <
s->h; n++) {
177 memset(
s->out->data[0] + n *
s->out->linesize[0], 0,
w);
178 memset(
s->out->data[1] + n *
s->out->linesize[0], 127,
w);
179 memset(
s->out->data[2] + n *
s->out->linesize[0], 127,
w);
180 memset(
s->out->data[3] + n *
s->out->linesize[0], 0,
w);
185 for (y = 0; y <
w; y++) {
186 s->combine_buffer[3 * y ] = 0;
187 s->combine_buffer[3 * y + 1] = 127.5;
188 s->combine_buffer[3 * y + 2] = 127.5;
192 for (n = 0; n <
H; n++) {
193 memset(
s->out->data[0] + n *
s->out->linesize[0], 0,
w);
194 memset(
s->out->data[1] + n *
s->out->linesize[0], 127,
w);
195 memset(
s->out->data[2] + n *
s->out->linesize[0], 127,
w);
196 memset(
s->out->data[3] + n *
s->out->linesize[0], 0,
w);
198 s->out->pts =
in->pts;
200 s->first =
s->frame_count;
205 const float *
src = (
const float *)
in->extended_data[
c];
206 uint64_t *achistogram = &
s->achistogram[(
s->dmode ==
SINGLE ? 0:
c) *
w];
208 for (n = 0; n <
in->nb_samples; n++) {
214 if (
s->in[
s->first] &&
s->count >= 0) {
215 uint64_t *shistogram = &
s->shistogram[(
s->dmode ==
SINGLE ? 0:
c) *
w];
216 const float *src2 = (
const float *)
s->in[
s->first]->extended_data[
c];
218 for (n = 0; n <
in->nb_samples; n++) {
228 const float *
src = (
const float *)
in->extended_data[
c];
229 uint64_t *achistogram = &
s->achistogram[(
s->dmode ==
SINGLE ? 0:
c) *
w];
231 for (n = 0; n <
in->nb_samples; n++) {
237 if (
s->in[
s->first] &&
s->count >= 0) {
238 uint64_t *shistogram = &
s->shistogram[(
s->dmode ==
SINGLE ? 0:
c) *
w];
239 const float *src2 = (
const float *)
s->in[
s->first]->extended_data[
c];
241 for (n = 0; n <
in->nb_samples; n++) {
252 s->in[
s->frame_count] =
in;
254 if (
s->frame_count >
s->count)
257 for (n = 0; n <
w *
s->dchannels; n++) {
258 acmax =
FFMAX(
s->achistogram[n] -
s->shistogram[n], acmax);
261 for (
c = 0;
c <
s->dchannels;
c++) {
262 uint64_t *shistogram = &
s->shistogram[
c *
w];
263 uint64_t *achistogram = &
s->achistogram[
c *
w];
267 yf = 256.0f /
s->dchannels;
270 uf *= 0.5 * sin((2 *
M_PI *
c) /
s->dchannels);
271 vf *= 0.5 * cos((2 *
M_PI *
c) /
s->dchannels);
274 for (n = 0; n <
w; n++) {
278 a = achistogram[n] - shistogram[n];
282 aa =
a / (double)acmax;
285 aa = sqrt(
a) / sqrt(acmax);
306 for (y =
H -
h; y <
H; y++) {
307 s->out->data[0][y *
s->out->linesize[0] + n] = 255;
308 s->out->data[3][y *
s->out->linesize[0] + n] = 255;
314 s->out->data[0][
s->ypos *
s->out->linesize[0] + n] =
h;
315 s->out->data[1][
s->ypos *
s->out->linesize[1] + n] = 127;
316 s->out->data[2][
s->ypos *
s->out->linesize[2] + n] = 127;
317 s->out->data[3][
s->ypos *
s->out->linesize[3] + n] = 255;
320 float *
out = &
s->combine_buffer[3 * n];
323 old =
s->out->data[0][(
H -
h) *
s->out->linesize[0] + n];
324 for (y =
H -
h; y <
H; y++) {
325 if (
s->out->data[0][y *
s->out->linesize[0] + n] != old)
327 old =
s->out->data[0][y *
s->out->linesize[0] + n];
328 s->out->data[0][y *
s->out->linesize[0] + n] = yf;
329 s->out->data[1][y *
s->out->linesize[1] + n] = 128+uf;
330 s->out->data[2][y *
s->out->linesize[2] + n] = 128+vf;
331 s->out->data[3][y *
s->out->linesize[3] + n] = 255;
343 for (n = 0; n <
w; n++) {
344 float *
cb = &
s->combine_buffer[3 * n];
346 s->out->data[0][
s->ypos *
s->out->linesize[0] + n] =
cb[0];
347 s->out->data[1][
s->ypos *
s->out->linesize[1] + n] =
cb[1];
348 s->out->data[2][
s->ypos *
s->out->linesize[2] + n] =
cb[2];
349 s->out->data[3][
s->ypos *
s->out->linesize[3] + n] = 255;
354 for (p = 0; p < 4; p++) {
355 for (y =
s->h; y >=
H + 1; y--) {
356 memmove(
s->out->data[p] + (y ) *
s->out->linesize[p],
357 s->out->data[p] + (y-1) *
s->out->linesize[p],
w);
363 if (
s->slide ==
SCROLL ||
s->ypos >=
s->h)
405 for (
i = 0;
i < 101;
i++)
428 .
name =
"ahistogram",
436 .priv_class = &ahistogram_class,
static enum AVSampleFormat sample_fmts[]
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVOption ahistogram_options[]
AVFilter ff_avf_ahistogram
static int query_formats(AVFilterContext *ctx)
AVFILTER_DEFINE_CLASS(ahistogram)
static int config_input(AVFilterLink *inlink)
static const AVFilterPad ahistogram_outputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int activate(AVFilterContext *ctx)
static av_cold void uninit(AVFilterContext *ctx)
static int config_output(AVFilterLink *outlink)
static const AVFilterPad ahistogram_inputs[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
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.
static __device__ float fabsf(float a)
#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.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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)
Non-inlined equivalent of av_mallocz_array().
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
enum MovChannelLayoutTag * layouts
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Describe the class of an AVClass context structure.
A list of supported channel layouts.
void * priv
private data for use by the filter
A link between two filters.
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
int w
agreed upon image width
int h
agreed upon image height
int channels
Number of channels.
AVFilterFormatsConfig outcfg
Lists of supported formats / etc.
AVFilterContext * src
source filter
int sample_rate
samples per second
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
const char * name
Pad name.
const char * name
Filter name.
This structure describes decoded (raw) audio or video data.
Rational number (pair of numerator and denominator).
#define av_malloc_array(a, b)
static double cb(void *priv, double x, double y)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.