Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2015 Arwa Arif <[email protected]>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 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 General Public License for more details.
- *
- * You should have received a copy of the GNU 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
- * FFT domain filtering.
- */
- #include "libavfilter/internal.h"
- #include "libavutil/common.h"
- #include "libavutil/imgutils.h"
- #include "libavutil/opt.h"
- #include "libavutil/pixdesc.h"
- #include "libavcodec/avfft.h"
- typedef struct {
- const AVClass *class;
- RDFTContext *rdft;
- int rdft_bits;
- FFTSample *rdft_data;
- } FFTFILTContext;
- static int filter_frame(AVFilterLink *inlink, AVFrame *in)
- {
- AVFilterContext *ctx = inlink->dst;
- AVFilterLink *outlink = inlink->dst->outputs[0];
- FFTFILTContext *fftfilt = ctx->priv;
- AVFrame *out;
- int i, rdft_bits;
- size_t rdft_len, w, h;
- w = inlink->w;
- h = inlink->h;
- /* RDFT window size (precision) according to the requested output frame height */
- for (rdft_bits = 1; 1 << rdft_bits < 2 * w; rdft_bits++);
- rdft_len = 1 << rdft_bits;
- fftfilt->rdft_data = av_malloc_array(h, rdft_len);
- for (i = 0; i < h; i++)
- memset(fftfilt->rdft_data, 0, rdft_len * h);
- out = ff_get_video_buffer(outlink, inlink->w, inlink->h);
- if (!out)
- return AVERROR(ENOMEM);
- av_frame_copy_props(out, in);
- /*Horizontal pass - RDFT*/
- for (i = 0; i < h; i++)
- fftfilt->rdft_data[i] = *(in->data[0] + in->linesize[0] * i);
- for (i = 0; i < h; i++)
- av_rdft_calc(fftfilt->rdft, fftfilt->rdft_data + i * rdft_len);
- av_rdft_end(fftfilt->rdft);
- /*Horizontal pass - IRDFT*/
- fftfilt->rdft = av_rdft_init(rdft_bits, IDFT_C2R);
- for (i = 0; i < h; i++)
- av_rdft_calc(fftfilt->rdft, fftfilt->rdft_data + i*rdft_len);
- for (i = 0; i < h; i++)
- *(out->data[0] + out->linesize[0] * i) = fftfilt->rdft_data[i];
- av_rdft_end(fftfilt->rdft);
- av_free(fftfilt->rdft_data);
- av_frame_free(&in);
- return ff_filter_frame(outlink, out);
- }
- static int query_formats(AVFilterContext *ctx)
- {
- static const enum AVPixelFormat pixel_fmts_fftfilt[] = {
- AV_PIX_FMT_GRAY8,
- AV_PIX_FMT_NONE
- };
- ff_set_common_formats(ctx, ff_make_format_list(pixel_fmts_fftfilt));
- return 0;
- }
- static const AVFilterPad fftfilt_inputs[] = {
- {
- .name = "default",
- .type = AVMEDIA_TYPE_VIDEO,
- .filter_frame = filter_frame,
- },
- { NULL }
- };
- static const AVFilterPad fftfilt_outputs[] = {
- {
- .name = "default",
- .type = AVMEDIA_TYPE_VIDEO,
- },
- { NULL }
- };
- AVFilter ff_vf_fftfilt = {
- .name = "fftfilt",
- .description = NULL_IF_CONFIG_SMALL("Adjust gain."),
- .priv_size = sizeof(FFTFILTContext),
- // .priv_class = &fftfilt_class,
- .inputs = fftfilt_inputs,
- .outputs = fftfilt_outputs,
- .query_formats = query_formats,
- };
Advertisement
Add Comment
Please, Sign In to add comment