72 static const char *
const var_names[] = {
"X",
"Y",
"W",
"H",
"N",
NULL };
77 #define OFFSET(x) offsetof(FFTFILTContext, x)
78 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
95 static inline double lum(
void *priv,
double x,
double y,
int plane)
98 return s->rdft_vdata[plane][(
int)x *
s->rdft_vlen[plane] + (
int)y];
101 static double weight_Y(
void *priv,
double x,
double y) {
return lum(priv, x, y,
Y); }
102 static double weight_U(
void *priv,
double x,
double y) {
return lum(priv, x, y,
U); }
103 static double weight_V(
void *priv,
double x,
double y) {
return lum(priv, x, y,
V); }
109 for (
i =
w;
i <
w + (w2-
w)/2;
i++)
110 dest[
i] = dest[2*
w -
i - 1];
113 dest[
i] = dest[w2 -
i];
121 for (
i = 0;
i <
h;
i++) {
122 for (j = 0; j <
w; j++)
123 s->rdft_hdata[plane][
i *
s->rdft_hlen[plane] + j] = *(
in->data[plane] +
in->linesize[plane] *
i + j);
125 copy_rev(
s->rdft_hdata[plane] +
i *
s->rdft_hlen[plane],
w,
s->rdft_hlen[plane]);
128 for (
i = 0;
i <
h;
i++)
129 av_rdft_calc(
s->hrdft[plane],
s->rdft_hdata[plane] +
i *
s->rdft_hlen[plane]);
134 const uint16_t *
src = (
const uint16_t *)
in->data[plane];
135 int linesize =
in->linesize[plane] / 2;
139 for (j = 0; j <
w; j++)
140 s->rdft_hdata[plane][
i *
s->rdft_hlen[plane] + j] = *(
src + linesize *
i + j);
142 copy_rev(
s->rdft_hdata[plane] +
i *
s->rdft_hlen[plane],
w,
s->rdft_hlen[plane]);
145 for (
i = 0;
i <
h;
i++)
146 av_rdft_calc(
s->hrdft[plane],
s->rdft_hdata[plane] +
i *
s->rdft_hlen[plane]);
154 for (
i = 0;
i <
s->rdft_hlen[plane];
i++) {
155 for (j = 0; j <
h; j++)
156 s->rdft_vdata[plane][
i *
s->rdft_vlen[plane] + j] =
157 s->rdft_hdata[plane][j *
s->rdft_hlen[plane] +
i];
158 copy_rev(
s->rdft_vdata[plane] +
i *
s->rdft_vlen[plane],
h,
s->rdft_vlen[plane]);
161 for (
i = 0;
i <
s->rdft_hlen[plane];
i++)
162 av_rdft_calc(
s->vrdft[plane],
s->rdft_vdata[plane] +
i *
s->rdft_vlen[plane]);
169 for (
i = 0;
i <
s->rdft_hlen[plane];
i++)
170 av_rdft_calc(
s->ivrdft[plane],
s->rdft_vdata[plane] +
i *
s->rdft_vlen[plane]);
172 for (
i = 0;
i <
s->rdft_hlen[plane];
i++)
173 for (j = 0; j <
h; j++)
174 s->rdft_hdata[plane][j *
s->rdft_hlen[plane] +
i] =
175 s->rdft_vdata[plane][
i *
s->rdft_vlen[plane] + j];
183 for (
i = 0;
i <
h;
i++)
184 av_rdft_calc(
s->ihrdft[plane],
s->rdft_hdata[plane] +
i *
s->rdft_hlen[plane]);
186 for (
i = 0;
i <
h;
i++)
187 for (j = 0; j <
w; j++)
188 *(
out->data[plane] +
out->linesize[plane] *
i + j) =
av_clip(
s->rdft_hdata[plane][
i
189 *
s->rdft_hlen[plane] + j] * 4 /
190 (
s->rdft_hlen[plane] *
191 s->rdft_vlen[plane]), 0, 255);
196 uint16_t *dst = (uint16_t *)
out->data[plane];
197 int linesize =
out->linesize[plane] / 2;
198 int max = (1 <<
s->depth) - 1;
201 for (
i = 0;
i <
h;
i++)
202 av_rdft_calc(
s->ihrdft[plane],
s->rdft_hdata[plane] +
i *
s->rdft_hlen[plane]);
204 for (
i = 0;
i <
h;
i++)
205 for (j = 0; j <
w; j++)
206 *(dst + linesize *
i + j) =
av_clip(
s->rdft_hdata[plane][
i
207 *
s->rdft_hlen[plane] + j] * 4 /
208 (
s->rdft_hlen[plane] *
209 s->rdft_vlen[plane]), 0,
max);
217 if (!
s->dc[
U] && !
s->dc[
V]) {
221 if (!
s->dc[
U])
s->dc[
U] =
s->dc[
V];
222 if (!
s->dc[
V])
s->dc[
V] =
s->dc[
U];
225 if (!
s->weight_str[
U] && !
s->weight_str[
V]) {
233 for (plane = 0; plane < 3; plane++) {
235 const char *
const func2_names[] = {
"weight_Y",
"weight_U",
"weight_V",
NULL };
252 values[
VAR_W] =
s->planewidth[plane];
253 values[
VAR_H] =
s->planeheight[plane];
255 for (
i = 0;
i <
s->rdft_hlen[plane];
i++) {
257 for (j = 0; j <
s->rdft_vlen[plane]; j++) {
259 s->weight[plane][
i *
s->rdft_vlen[plane] + j] =
272 s->depth =
desc->comp[0].depth;
274 s->planewidth[0] =
s->planewidth[3] = inlink->
w;
276 s->planeheight[0] =
s->planeheight[3] = inlink->
h;
280 for (
i = 0;
i <
desc->nb_components;
i++) {
281 int w =
s->planewidth[
i];
282 int h =
s->planeheight[
i];
310 for (plane = 0; plane < 3; plane++) {
311 if(!(
s->weight[plane] =
av_malloc_array(
s->rdft_hlen[plane],
s->rdft_vlen[plane] *
sizeof(
double))))
321 }
else if (
s->depth > 8) {
346 for (plane = 0; plane <
s->nb_planes; plane++) {
347 int w =
s->planewidth[plane];
348 int h =
s->planeheight[plane];
353 s->rdft_horizontal(
s,
in,
w,
h, plane);
357 for (
i = 0;
i <
s->rdft_hlen[plane];
i++)
358 for (j = 0; j <
s->rdft_vlen[plane]; j++)
359 s->rdft_vdata[plane][
i *
s->rdft_vlen[plane] + j] *=
360 s->weight[plane][
i *
s->rdft_vlen[plane] + j];
362 s->rdft_vdata[plane][0] +=
s->rdft_hlen[plane] *
s->rdft_vlen[plane] *
s->dc[plane];
365 s->irdft_horizontal(
s,
out,
w,
h, plane);
433 .description =
NULL_IF_CONFIG_SMALL(
"Apply arbitrary expressions to pixels in frequency domain."),
435 .priv_class = &fftfilt_class,
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
static double(*const func2[])(void *, double, double)
static const char *const func2_names[]
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-> dc
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static av_cold int init(AVCodecContext *avctx)
#define flags(name, subs,...)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
simple arithmetic expression evaluator
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
void av_rdft_calc(RDFTContext *s, FFTSample *data)
void av_rdft_end(RDFTContext *s)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
char * av_strdup(const char *s)
Duplicate a string.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
typedef void(RENAME(mix_any_func_type))
Describe the class of an AVClass context structure.
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * dst
dest filter
int format
agreed upon media format
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int planewidth[MAX_PLANES]
RDFTContext * vrdft[MAX_PLANES]
int planeheight[MAX_PLANES]
int rdft_vbits[MAX_PLANES]
void(* irdft_horizontal)(struct FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
char * weight_str[MAX_PLANES]
size_t rdft_hlen[MAX_PLANES]
size_t rdft_vlen[MAX_PLANES]
FFTSample * rdft_hdata[MAX_PLANES]
RDFTContext * ihrdft[MAX_PLANES]
double * weight[MAX_PLANES]
RDFTContext * ivrdft[MAX_PLANES]
RDFTContext * hrdft[MAX_PLANES]
AVExpr * weight_expr[MAX_PLANES]
FFTSample * rdft_vdata[MAX_PLANES]
int rdft_hbits[MAX_PLANES]
void(* rdft_horizontal)(struct FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
#define av_malloc_array(a, b)
static const AVFilterPad fftfilt_outputs[]
static void copy_rev(FFTSample *dest, int w, int w2)
static void do_eval(FFTFILTContext *s, AVFilterLink *inlink, int plane)
static void rdft_horizontal16(FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
static av_cold int initialize(AVFilterContext *ctx)
static double weight_Y(void *priv, double x, double y)
static void rdft_horizontal8(FFTFILTContext *s, AVFrame *in, int w, int h, int plane)
static void irdft_horizontal8(FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
static const AVFilterPad fftfilt_inputs[]
static int query_formats(AVFilterContext *ctx)
static double weight_U(void *priv, double x, double y)
static double weight_V(void *priv, double x, double y)
static void irdft_vertical(FFTFILTContext *s, int h, int plane)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
AVFILTER_DEFINE_CLASS(fftfilt)
static void rdft_vertical(FFTFILTContext *s, int h, int plane)
static int config_props(AVFilterLink *inlink)
static const char *const var_names[]
static const AVOption fftfilt_options[]
static av_cold void uninit(AVFilterContext *ctx)
static void irdft_horizontal16(FFTFILTContext *s, AVFrame *out, int w, int h, int plane)
static double lum(void *priv, double x, double y, int plane)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.