FFmpeg
Loading...
Searching...
No Matches
af_asetrate.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Nicolas George
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "libavutil/opt.h"
22#include "avfilter.h"
23#include "filters.h"
24#include "formats.h"
25
26typedef struct ASetRateContext {
27 const AVClass *class;
31
32#define CONTEXT ASetRateContext
33#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
34
35#define OPT_GENERIC(name, field, def, min, max, descr, type, deffield, ...) \
36 { name, descr, offsetof(CONTEXT, field), AV_OPT_TYPE_ ## type, \
37 { .deffield = def }, min, max, FLAGS, __VA_ARGS__ }
38
39#define OPT_INT(name, field, def, min, max, descr, ...) \
40 OPT_GENERIC(name, field, def, min, max, descr, INT, i64, __VA_ARGS__)
41
42static const AVOption asetrate_options[] = {
43 OPT_INT("sample_rate", sample_rate, 44100, 1, INT_MAX, "set the sample rate",),
44 OPT_INT("r", sample_rate, 44100, 1, INT_MAX, "set the sample rate",),
45 {NULL},
46};
47
49
51 AVFilterFormatsConfig **cfg_in,
52 AVFilterFormatsConfig **cfg_out)
53{
54 const ASetRateContext *sr = ctx->priv;
55 int ret, sample_rates[] = { sr->sample_rate, -1 };
56
58 &cfg_in[0]->samplerates)) < 0)
59 return ret;
60
62 &cfg_out[0]->samplerates);
63}
64
65static av_cold int config_props(AVFilterLink *outlink)
66{
67 AVFilterContext *ctx = outlink->src;
68 ASetRateContext *sr = ctx->priv;
69 AVFilterLink *inlink = ctx->inputs[0];
70 AVRational intb = ctx->inputs[0]->time_base;
71 int inrate = inlink->sample_rate;
72
73 if (intb.num == 1 && intb.den == inrate) {
74 outlink->time_base.num = 1;
75 outlink->time_base.den = outlink->sample_rate;
76 } else {
77 outlink->time_base = intb;
78 sr->rescale_pts = 1;
79 if (av_q2d(intb) > 1.0 / FFMAX(inrate, outlink->sample_rate))
80 av_log(ctx, AV_LOG_WARNING, "Time base is inaccurate\n");
81 }
82 return 0;
83}
84
86{
87 AVFilterContext *ctx = inlink->dst;
88 ASetRateContext *sr = ctx->priv;
89 AVFilterLink *outlink = ctx->outputs[0];
90
91 frame->sample_rate = outlink->sample_rate;
92 if (sr->rescale_pts)
93 frame->pts = av_rescale(frame->pts, inlink->sample_rate,
94 outlink->sample_rate);
95 return ff_filter_frame(outlink, frame);
96}
97
98static const AVFilterPad asetrate_inputs[] = {
99 {
100 .name = "default",
101 .type = AVMEDIA_TYPE_AUDIO,
102 .filter_frame = filter_frame,
103 },
104};
105
107 {
108 .name = "default",
109 .type = AVMEDIA_TYPE_AUDIO,
110 .config_props = config_props,
111 },
112};
113
115 .p.name = "asetrate",
116 .p.description = NULL_IF_CONFIG_SMALL("Change the sample rate without "
117 "altering the data."),
118 .p.priv_class = &asetrate_class,
120 .priv_size = sizeof(ASetRateContext),
124};
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
static const AVFilterPad asetrate_inputs[]
Definition af_asetrate.c:98
static const AVOption asetrate_options[]
Definition af_asetrate.c:42
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition af_asetrate.c:85
const FFFilter ff_af_asetrate
static av_cold int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition af_asetrate.c:50
#define OPT_INT(name, field, def, min, max, descr,...)
Definition af_asetrate.c:39
static const AVFilterPad asetrate_outputs[]
static av_cold int config_props(AVFilterLink *outlink)
Definition af_asetrate.c:65
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
Main libavfilter public API header.
#define NULL
Definition coverity.c:32
static const int sample_rates[]
Definition dcaenc.h:34
static AVFrame * frame
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add ref as a new reference to formats.
Definition formats.c:756
AVFilterFormats * ff_all_samplerates(void)
Definition formats.c:673
av_warn_unused_result AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition avfilter.h:182
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define FFMAX(a, b)
Definition macros.h:47
AVOptions.
static int config_props(AVBitStreamFilterLink *link)
Definition source.c:181
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:273
Lists of formats / etc.
Definition avfilter.h:120
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
AVOption.
Definition opt.h:428
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
#define av_log(a,...)